X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FMixin%2FHasMethods.pm;h=8e38d5ed3923c59f67678e3761ee648b091aa91a;hb=736bf1f0c52b34a9a91374d3f090d04d1c311440;hp=3cf042dfd58a3993366ddcb74d489052b4a2d732;hpb=67f694add1dd6c3c8d78a7aa991e65ff71dd1395;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 3cf042d..8e38d5e 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -39,12 +39,14 @@ sub add_method { ( defined $method_name && length $method_name ) || confess "You must define a method name"; + my $package_name = $self->name; + my $body; if ( blessed($method) ) { $body = $method->body; - if ( $method->package_name ne $self->name ) { + if ( $method->package_name ne $package_name ) { $method = $method->clone( - package_name => $self->name, + package_name => $package_name, name => $method_name, ) if $method->can('clone'); } @@ -62,7 +64,7 @@ sub add_method { my ( $current_package, $current_name ) = Class::MOP::get_code_info($body); if ( !defined $current_name || $current_name =~ /^__ANON__/ ) { - my $full_method_name = ( $self->name . '::' . $method_name ); + my $full_method_name = ( $package_name . '::' . $method_name ); subname( $full_method_name => $body ); } @@ -106,13 +108,12 @@ sub get_method { } ); - # This seems to happen in some weird cases where methods modifiers are - # added via roles or some other such bizareness. Honestly, I don't totally - # understand this, but returning the entry works, and keeps various MX - # modules from blowing up. - DR - return $map_entry if blessed $map_entry && !$code; - - return $map_entry if blessed $map_entry && $map_entry->body == $code; + # The !$code case seems to happen in some weird cases where methods + # modifiers are added via roles or some other such bizareness. Honestly, I + # don't totally understand this, but returning the entry works, and keeps + # various MX modules from blowing up. - DR + return $map_entry + if blessed $map_entry && ( !$code || $map_entry->body == $code ); unless ($map_entry) { return unless $code && $self->_code_is_mine($code);