X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole%2FComposite.pm;h=d7e004a0f5b8461b7bb56ed4fab068a5aa9f6d7e;hb=823419c540f9e77090f31f11e04b14477c0372c4;hp=7b205b8e8dd89313881f0aaa2b7f7dbbdaa5869a;hpb=267711f78bd79835875f805447d3ab802a18f0c4;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index 7b205b8..d7e004a 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -1,9 +1,10 @@ package Mouse::Meta::Role::Composite; -use Mouse::Util qw(english_list); # enables strict and warnings +use Mouse::Util; # enables strict and warnings use Mouse::Meta::Role; +use Mouse::Meta::Role::Application; our @ISA = qw(Mouse::Meta::Role); -sub get_method_list{ +sub get_method_list { my($self) = @_; return keys %{ $self->{methods} }; } @@ -16,16 +17,18 @@ sub add_method { return; } - if($method_name ne 'meta'){ + if($method_name eq 'meta'){ + $self->SUPER::add_method($method_name => $code); + } + else{ + # no need to add a subroutine to the stash my $roles = $self->{composed_roles_by_method}{$method_name} ||= []; push @{$roles}, $role; if(@{$roles} > 1){ $self->{conflicting_methods}{$method_name}++; } + $self->{methods}{$method_name} = $code; } - - $self->{methods}{$method_name} = $code; - # no need to add a subroutine to the stash return; } @@ -36,21 +39,23 @@ sub get_method_body { sub has_method { # my($self, $method_name) = @_; - return 0; # to fool _apply_methods() in combine() + return 0; # to fool apply_methods() in combine() } -sub has_attribute{ +sub has_attribute { # my($self, $method_name) = @_; - return 0; # to fool _appply_attributes() in combine() + return 0; # to fool appply_attributes() in combine() } -sub has_override_method_modifier{ +sub has_override_method_modifier { # my($self, $method_name) = @_; - return 0; # to fool _apply_modifiers() in combine() + return 0; # to fool apply_modifiers() in combine() } -sub add_attribute{ - my($self, $attr_name, $spec) = @_; +sub add_attribute { + my $self = shift; + my $attr_name = shift; + my $spec = (@_ == 1 ? $_[0] : {@_}); my $existing = $self->{attributes}{$attr_name}; if($existing && $existing != $spec){ @@ -61,7 +66,7 @@ sub add_attribute{ return; } -sub add_override_method_modifier{ +sub add_override_method_modifier { my($self, $method_name, $code) = @_; my $existing = $self->{override_method_modifiers}{$method_name}; @@ -74,43 +79,57 @@ sub add_override_method_modifier{ return; } -# components of apply() +sub apply { + my $self = shift; + my $consumer = shift; + + Mouse::Meta::Role::Application::RoleSummation->new(@_)->apply($self, $consumer); + return; +} -sub _apply_methods{ - my($self, $applicant, $args) = @_; +package Mouse::Meta::Role::Application::RoleSummation; +our @ISA = qw(Mouse::Meta::Role::Application); - if(exists $self->{conflicting_methods}){ - my $applicant_class_name = $applicant->name; +sub apply_methods { + my($self, $role, $consumer, @extra) = @_; - my @conflicting = sort grep{ !$applicant_class_name->can($_) } keys %{ $self->{conflicting_methods} }; + if(exists $role->{conflicting_methods}){ + my $consumer_class_name = $consumer->name; + + my @conflicting = grep{ !$consumer_class_name->can($_) } + keys %{ $role->{conflicting_methods} }; if(@conflicting == 1){ my $method_name = $conflicting[0]; - my @roles = sort @{ $self->{composed_roles_by_method}{$method_name} }; + my $roles = Mouse::Util::quoted_english_list( map{ $_->name } + @{ $role->{composed_roles_by_method}{$method_name} }); $self->throw_error( sprintf q{Due to a method name conflict in roles %s, the method '%s' must be implemented or excluded by '%s'}, - english_list(map{ sprintf q{'%s'}, $_->name } @roles), $method_name, $applicant->name + $roles, $method_name, $consumer_class_name ); } elsif(@conflicting > 1){ - my $methods = english_list(map{ sprintf q{'%s'}, $_ } @conflicting); - my %seen; - my $roles = english_list( - sort map{ my $name = $_->name; $seen{$name}++ ? () : sprintf q{'%s'}, $name } - map{ @{$_} } @{ $self->{composed_roles_by_method} }{@conflicting} + my $roles = Mouse::Util::quoted_english_list( + grep{ !$seen{$_}++ } # uniq + map { $_->name } + map { @{$_} } @{ $role->{composed_roles_by_method} }{@conflicting} ); $self->throw_error( sprintf q{Due to method name conflicts in roles %s, the methods %s must be implemented or excluded by '%s'}, - $roles, $methods, $applicant->name + $roles, + Mouse::Util::quoted_english_list(@conflicting), + $consumer_class_name ); } } - $self->SUPER::_apply_methods($applicant, $args); + $self->SUPER::apply_methods($role, $consumer, @extra); return; } + +package Mouse::Meta::Role::Composite; 1; __END__ @@ -120,7 +139,7 @@ Mouse::Meta::Role::Composite - An object to represent the set of roles =head1 VERSION -This document describes Mouse version 0.4501 +This document describes Mouse version 0.70 =head1 SEE ALSO