From: Shawn M Moore Date: Sun, 3 May 2009 19:04:59 +0000 (-0400) Subject: Make role_applications return a list not an arrayref X-Git-Tag: 0.78~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=639f9a1a9d7162d6af6fe3843d19e046114008d8;p=gitmo%2FMoose.git Make role_applications return a list not an arrayref --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index de9da90..09a0d33 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -30,11 +30,10 @@ __PACKAGE__->meta->add_attribute('roles' => ( )); __PACKAGE__->meta->add_attribute('role_applications' => ( - reader => 'role_applications', + reader => '_get_role_applications', default => sub { [] } )); - __PACKAGE__->meta->add_attribute( Class::MOP::Attribute->new('immutable_trait' => ( accessor => "immutable_trait", @@ -141,11 +140,17 @@ sub add_role { push @{$self->roles} => $role; } +sub role_applications { + my ($self) = @_; + + return @{$self->_get_role_applications}; +} + 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; + push @{$self->_get_role_applications} => $application; } sub calculate_all_roles { @@ -709,7 +714,7 @@ list of roles. This I actually apply the role to the class. =item B<< $metaclass->role_applications >> -Returns an array reference of L +Returns a list of L objects, which contain the arguments to role application. =item B<< $metaclass->add_role_application($application) >> diff --git a/t/030_roles/039_application_toclass.t b/t/030_roles/039_application_toclass.t index 930d9a3..67c7d4e 100644 --- a/t/030_roles/039_application_toclass.t +++ b/t/030_roles/039_application_toclass.t @@ -33,10 +33,10 @@ do { sub foo { } }; -my @basic = @{ Consumer::Basic->meta->role_applications }; -my @excludes = @{ Consumer::Excludes->meta->role_applications }; -my @aliases = @{ Consumer::Aliases->meta->role_applications }; -my @overrides = @{ Consumer::Overrides->meta->role_applications }; +my @basic = Consumer::Basic->meta->role_applications; +my @excludes = Consumer::Excludes->meta->role_applications; +my @aliases = Consumer::Aliases->meta->role_applications; +my @overrides = Consumer::Overrides->meta->role_applications; is(@basic, 1); is(@excludes, 1);