From: Shawn M Moore Date: Sun, 3 May 2009 18:37:34 +0000 (-0400) Subject: Add role application objects to each class X-Git-Tag: 0.78~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a9b63d79245f3150f8925c7f2c2cbaee36423533;p=gitmo%2FMoose.git Add role application objects to each class --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index f05486b..11b75ab 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -29,6 +29,11 @@ __PACKAGE__->meta->add_attribute('roles' => ( default => sub { [] } )); +__PACKAGE__->meta->add_attribute('role_applications' => ( + reader => 'role_applications', + default => sub { [] } +)); + __PACKAGE__->meta->add_attribute( Class::MOP::Attribute->new('immutable_trait' => ( @@ -136,6 +141,13 @@ sub add_role { push @{$self->roles} => $role; } +sub add_role_application { + my ($self, $application) = @_; + (blessed($application) && $application->isa('Moose::Meta::Role::Application::ToClass')) + || $self->throw_error("Role applications must be instances of Moose::Meta::Role::Application::ToClass", data => $application); + push @{$self->role_applications} => $application; +} + sub calculate_all_roles { my $self = shift; my %seen; diff --git a/lib/Moose/Meta/Role/Application/ToClass.pm b/lib/Moose/Meta/Role/Application/ToClass.pm index 28d1ef4..c8c443c 100644 --- a/lib/Moose/Meta/Role/Application/ToClass.pm +++ b/lib/Moose/Meta/Role/Application/ToClass.pm @@ -30,7 +30,9 @@ sub apply { $self->set_class($class); $self->SUPER::apply($role, $class); + $class->add_role($role); + $class->add_role_application($self); } sub check_role_exclusions {