X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole.pm;h=6f9c7a839a0ba3da9d36b442953e883ad1802bd7;hp=ea4b1fa9fdb698c0b03f9041f6d65ce979512532;hb=2b68f76d78d96325821e9a6360c3639f8c5637df;hpb=06a970ab9fb60a4cac5e3f1774cf9a2914c94cc1 diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index ea4b1fa..6f9c7a8 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -29,11 +29,16 @@ sub create_anon_role{ return $self->create(undef, @_); } -sub is_anon_role{ - return exists $_[0]->{anon_serial_id}; -} +sub is_anon_role; -sub get_roles { $_[0]->{roles} } +sub get_roles; + +sub calculate_all_roles { + my $self = shift; + my %seen; + return grep { !$seen{ $_->name }++ } + ($self, map { $_->calculate_all_roles } @{ $self->get_roles }); +} sub get_required_method_list{ return @{ $_[0]->{required_methods} }; @@ -181,10 +186,10 @@ sub apply { my $instance; - if($applicant->isa('Mouse::Meta::Class')){ # Application::ToClass + if(Mouse::Util::TypeConstraints::_is_a_metaclass($applicant)){ # Application::ToClass $args{_to} = 'class'; } - elsif($applicant->isa('Mouse::Meta::Role')){ # Application::ToRole + elsif(Mouse::Util::TypeConstraints::_is_a_metarole($applicant)){ # Application::ToRole $args{_to} = 'role'; } else{ # Appplication::ToInstance @@ -250,27 +255,36 @@ sub combine { return $composite; } -for my $modifier_type (qw/before after around/) { - - my $modifier = "${modifier_type}_method_modifiers"; +sub add_before_method_modifier { + my ($self, $method_name, $method) = @_; - my $add_method_modifier = sub { - my ($self, $method_name, $method) = @_; - - push @{ $self->{$modifier}->{$method_name} ||= [] }, $method; - return; - }; + push @{ $self->{before_method_modifiers}{$method_name} ||= [] }, $method; + return; +} +sub add_around_method_modifier { + my ($self, $method_name, $method) = @_; - my $get_method_modifiers = sub { - my ($self, $method_name) = @_; - return @{ $self->{$modifier}->{$method_name} ||= [] } - }; + push @{ $self->{around_method_modifiers}{$method_name} ||= [] }, $method; + return; +} +sub add_after_method_modifier { + my ($self, $method_name, $method) = @_; - no strict 'refs'; - *{ 'add_' . $modifier_type . '_method_modifier' } = $add_method_modifier; - *{ 'get_' . $modifier_type . '_method_modifiers' } = $get_method_modifiers; + push @{ $self->{after_method_modifiers}{$method_name} ||= [] }, $method; + return; +} - # has_${modifier_type}_method_modifiers is moved into t::lib::Test::Mouse +sub get_before_method_modifiers { + my ($self, $method_name) = @_; + return @{ $self->{before_method_modifiers}{$method_name} ||= [] } +} +sub get_around_method_modifiers { + my ($self, $method_name) = @_; + return @{ $self->{around_method_modifiers}{$method_name} ||= [] } +} +sub get_after_method_modifiers { + my ($self, $method_name) = @_; + return @{ $self->{after_method_modifiers}{$method_name} ||= [] } } sub add_override_method_modifier{ @@ -316,7 +330,7 @@ Mouse::Meta::Role - The Mouse Role metaclass =head1 VERSION -This document describes Mouse version 0.38 +This document describes Mouse version 0.40_03 =head1 SEE ALSO