From: Stevan Little Date: Thu, 13 Apr 2006 04:56:40 +0000 (+0000) Subject: method_modifiers_are_arrays X-Git-Tag: 0_05~39 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=598340d5d8380c0fa45fe2018e2f29d0e9c5aa73;p=gitmo%2FMoose.git method_modifiers_are_arrays --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 9c99bfc..0bd30d7 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -11,7 +11,7 @@ our $VERSION = '0.04'; use base 'Class::MOP::Class'; -__PACKAGE__->meta->add_attribute('@:roles' => ( +__PACKAGE__->meta->add_attribute('roles' => ( reader => 'roles', default => sub { [] } )); diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 1eb76bb..fca8c81 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -70,30 +70,30 @@ sub apply { # add it, although it could be overriden $other->add_override_method_modifier( $method_name, - $self->get_method_modifier('override' => $method_name), + $_, $self->name - ); + ) foreach $self->get_method_modifiers('override' => $method_name); } foreach my $method_name ($self->get_method_modifier_list('before')) { $other->add_before_method_modifier( $method_name, - $self->get_method_modifier('before' => $method_name) - ); + $_ + ) foreach $self->get_method_modifiers('before' => $method_name); } foreach my $method_name ($self->get_method_modifier_list('after')) { $other->add_after_method_modifier( $method_name, - $self->get_method_modifier('after' => $method_name) - ); + $_ + ) foreach $self->get_method_modifiers('after' => $method_name); } foreach my $method_name ($self->get_method_modifier_list('around')) { $other->add_around_method_modifier( $method_name, - $self->get_method_modifier('around' => $method_name) - ); + $_ + ) foreach $self->get_method_modifiers('around' => $method_name); } ## add the roles and set does() @@ -175,20 +175,22 @@ sub get_attribute_list { sub add_method_modifier { my ($self, $modifier_type, $method_name, $method) = @_; - $self->get_method_modifier_map->{$modifier_type}->{$method_name} = $method; + $self->get_method_modifier_map->{$modifier_type}->{$method_name} = [] + unless exists $self->get_method_modifier_map->{$modifier_type}->{$method_name}; + push @{$self->get_method_modifier_map->{$modifier_type}->{$method_name}} => $method; } -sub has_method_modifier { +sub has_method_modifiers { my ($self, $modifier_type, $method_name) = @_; exists $self->get_method_modifier_map->{$modifier_type}->{$method_name} ? 1 : 0 } -sub get_method_modifier { +sub get_method_modifiers { my ($self, $modifier_type, $method_name) = @_; - $self->get_method_modifier_map->{$modifier_type}->{$method_name}; + @{$self->get_method_modifier_map->{$modifier_type}->{$method_name}}; } -sub remove_method_modifier { +sub remove_method_modifiers { my ($self, $modifier_type, $method_name) = @_; delete $self->get_method_modifier_map->{$modifier_type}->{$method_name}; } @@ -274,15 +276,15 @@ for more information. =item B -=item B +=item B -=item B +=item B =item B =item B -=item B +=item B =back diff --git a/t/040_meta_role.t b/t/040_meta_role.t index b3b8328..89403a7 100644 --- a/t/040_meta_role.t +++ b/t/040_meta_role.t @@ -95,7 +95,7 @@ ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribu # method modifiers -ok(!$foo_role->has_method_modifier('before' => 'boo'), '... no boo:before modifier'); +ok(!$foo_role->has_method_modifiers('before' => 'boo'), '... no boo:before modifier'); my $method = sub { "FooRole::boo:before" }; lives_ok { @@ -104,8 +104,8 @@ lives_ok { )); } '... added a method modifier okay'; -ok($foo_role->has_method_modifier('before' => 'boo'), '... now we have a boo:before modifier'); -is($foo_role->get_method_modifier('before' => 'boo'), $method, '... got the right method back'); +ok($foo_role->has_method_modifiers('before' => 'boo'), '... now we have a boo:before modifier'); +is(($foo_role->get_method_modifiers('before' => 'boo'))[0], $method, '... got the right method back'); is_deeply( [ $foo_role->get_method_modifier_list('before') ], diff --git a/t/041_role.t b/t/041_role.t index d5080ba..76d0263 100644 --- a/t/041_role.t +++ b/t/041_role.t @@ -70,8 +70,8 @@ is_deeply( # method modifiers -ok($foo_role->has_method_modifier('before' => 'boo'), '... now we have a boo:before modifier'); -is($foo_role->get_method_modifier('before' => 'boo')->(), +ok($foo_role->has_method_modifiers('before' => 'boo'), '... now we have a boo:before modifier'); +is(($foo_role->get_method_modifiers('before' => 'boo'))[0]->(), "FooRole::boo:before", '... got the right method back');