X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FApplication%2FToRole.pm;h=6c7dfeafc8e612d0fa4466087e0612198d9a22f3;hb=bb09ad9144e7ee7b2cad8a90725267f591346406;hp=47593ddd7dcc7c007a346e263c00aa92b00b1a2e;hpb=a538895dd79e9a74cd1ba763f77fa7d63cbab935;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 47593dd..6c7dfea 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -6,7 +6,7 @@ use metaclass; use Scalar::Util 'blessed'; -our $VERSION = '1.02'; +our $VERSION = '1.17'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -57,9 +57,15 @@ sub apply_attributes { # make sure we haven't seen this one already too $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) { + my $role2_name = $role2->name; + require Moose; - Moose->throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " . - "during composition. This is fatal error and cannot be disambiguated."); + Moose->throw_error( "Role '" + . $role1->name + . "' has encountered an attribute conflict" + . " while being composed into '$role2_name'." + . " This is a fatal error and cannot be disambiguated." + . " The conflicting attribute is named '$attribute_name'." ); } else { $role2->add_attribute( @@ -70,14 +76,18 @@ sub apply_attributes { } sub apply_methods { - my ($self, $role1, $role2) = @_; - foreach my $method_name ($role1->get_method_list) { - next if $method_name eq 'meta'; + my ( $self, $role1, $role2 ) = @_; + foreach my $method ( $role1->_get_local_methods ) { + + my $method_name = $method->name; + + next if $method->isa('Class::MOP::Method::Meta'); unless ( $self->is_method_excluded($method_name) ) { - if ( $role2->has_method($method_name) - && $role2->get_method($method_name)->body - != $role1->get_method($method_name)->body ) { + + my $role2_method = $role2->get_method($method_name); + if ( $role2_method + && $role2_method->body != $method->body ) { # method conflicts between roles result in the method becoming # a requirement @@ -89,30 +99,34 @@ sub apply_methods { else { $role2->add_method( $method_name, - $role1->get_method($method_name) + $method, ); } } - if ($self->is_method_aliased($method_name)) { - my $aliased_method_name = $self->get_method_aliases->{$method_name}; + next unless $self->is_method_aliased($method_name); - if ($role2->has_method($aliased_method_name) && - $role2->get_method($aliased_method_name)->body != $role1->get_method($method_name)->body) { + my $aliased_method_name = $self->get_method_aliases->{$method_name}; - require Moose; - Moose->throw_error("Cannot create a method alias if a local method of the same name exists"); - } + my $role2_method = $role2->get_method($aliased_method_name); + + if ( $role2_method + && $role2_method->body != $method->body ) { - $role2->add_method( - $aliased_method_name, - $role1->get_method($method_name) + require Moose; + Moose->throw_error( + "Cannot create a method alias if a local method of the same name exists" ); + } - if (!$role2->has_method($method_name)) { - $role2->add_required_methods($method_name) - unless $self->is_method_excluded($method_name); - } + $role2->add_method( + $aliased_method_name, + $role1->get_method($method_name) + ); + + if ( !$role2->has_method($method_name) ) { + $role2->add_required_methods($method_name) + unless $self->is_method_excluded($method_name); } } }