X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FApplication%2FToRole.pm;h=f45ec159ed39e825737bdf4f22e72fa5ae451f99;hb=aead17e74252e3884f9f8e39912ca98fdf4b4dd5;hp=46ff62961f95134bf61265030df62a43562a8576;hpb=4c0b35998743adde444d886607da524c7094327c;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 46ff629..f45ec15 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 = '0.57'; +our $VERSION = '0.62'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -20,10 +20,10 @@ sub apply { sub check_role_exclusions { my ($self, $role1, $role2) = @_; - Moose::throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'") + Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'") if $role2->excludes_role($role1->name); foreach my $excluded_role_name ($role1->get_excluded_roles_list) { - Moose::throw_error("The class " . $role2->name . " does the excluded role '$excluded_role_name'") + Moose->throw_error("The class " . $role2->name . " does the excluded role '$excluded_role_name'") if $role2->does_role($excluded_role_name); $role2->add_excluded_roles($excluded_role_name); } @@ -51,7 +51,7 @@ sub apply_attributes { if ($role2->has_attribute($attribute_name) && # make sure we haven't seen this one already too $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) { - Moose::throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " . + Moose->throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " . "during composition. This is fatal error and cannot be disambiguated."); } else { @@ -66,8 +66,6 @@ sub apply_attributes { sub apply_methods { my ($self, $role1, $role2) = @_; foreach my $method_name ($role1->get_method_list) { - - next if $self->is_method_excluded($method_name); if ($self->is_method_aliased($method_name)) { my $aliased_method_name = $self->get_method_aliases->{$method_name}; @@ -75,20 +73,23 @@ sub apply_methods { if ($role2->has_method($aliased_method_name) && # and if they are not the same thing ... $role2->get_method($aliased_method_name)->body != $role1->get_method($method_name)->body) { - Moose::throw_error("Cannot create a method alias if a local method of the same name exists"); + Moose->throw_error("Cannot create a method alias if a local method of the same name exists"); } - $role2->alias_method( + $role2->add_method( $aliased_method_name, $role1->get_method($method_name) ); if (!$role2->has_method($method_name)) { - $role2->add_required_methods($method_name); + $role2->add_required_methods($method_name) + unless $self->is_method_excluded($method_name); } next; - } + } + + next if $self->is_method_excluded($method_name); # it if it has one already if ($role2->has_method($method_name) && @@ -100,7 +101,7 @@ sub apply_methods { } else { # add it, although it could be overriden - $role2->alias_method( + $role2->add_method( $method_name, $role1->get_method($method_name) ); @@ -119,7 +120,7 @@ sub apply_override_method_modifiers { # we have a conflict here, because you cannot # combine an overriden method with a locally # defined one - Moose::throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . + Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . "during composition (A local method of the same name as been found). This " . "is fatal error."); } @@ -129,7 +130,7 @@ sub apply_override_method_modifiers { # we are composing into if ($role2->has_override_method_modifier($method_name) && $role2->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) { - Moose::throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . + Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . "during composition (Two 'override' methods of the same name encountered). " . "This is fatal error."); }