X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole%2FComposite.pm;h=7c29969b70416fbc3074adfb09e866eebcf92975;hb=86eb0b5e6f0c2d89a6c86516e7bccbf9c7daba1f;hp=58496c369ffcba50b1ff9c0f4759c90827faa6b3;hpb=45f22b92d1140ad101f7c3112bc565890ea5a1ad;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index 58496c3..7c29969 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -1,5 +1,5 @@ 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; our @ISA = qw(Mouse::Meta::Role); @@ -16,16 +16,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; } @@ -84,28 +86,29 @@ sub _apply_methods{ if(exists $self->{conflicting_methods}){ my $consumer_class_name = $consumer->name; - my @conflicting = sort grep{ !$consumer_class_name->can($_) } keys %{ $self->{conflicting_methods} }; + my @conflicting = grep{ !$consumer_class_name->can($_) } keys %{ $self->{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 } @{ $self->{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, $consumer->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 { @{$_} } @{ $self->{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, $consumer->name + $roles, + Mouse::Util::quoted_english_list(@conflicting), + $consumer_class_name ); } } @@ -122,7 +125,7 @@ Mouse::Meta::Role::Composite - An object to represent the set of roles =head1 VERSION -This document describes Mouse version 0.49 +This document describes Mouse version 0.70 =head1 SEE ALSO