From: Dave Rolsky Date: Sun, 8 Aug 2010 09:02:08 +0000 (+0200) Subject: Get the package name once as a small optimization X-Git-Tag: 1.05~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef8d6eaee0d3a8a57f7e42c5cf3eab266fe25476;p=gitmo%2FClass-MOP.git Get the package name once as a small optimization --- diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 34a66b4..cd11a8f 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 ); }