Add role application objects to each class
Shawn M Moore [Sun, 3 May 2009 18:37:34 +0000 (14:37 -0400)]
lib/Moose/Meta/Class.pm
lib/Moose/Meta/Role/Application/ToClass.pm

index f05486b..11b75ab 100644 (file)
@@ -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;
index 28d1ef4..c8c443c 100644 (file)
@@ -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 {