X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FModule.pm;h=546bb2e21f726d2040a2844810bc2ea7591fd3ef;hb=cf267e676ef8c258c71348c3becd5da2d7f9f36c;hp=2a3563abe22644651a41ce456cc081013423b63c;hpb=a7e3b78eb9097adb42355eaa27a6c5846a1ad9cc;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 2a3563a..546bb2e 100644 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -84,39 +84,35 @@ my %foreign = map{ $_ => undef } qw( Mouse Mouse::Role Mouse::Util Mouse::Util::TypeConstraints Carp Scalar::Util List::Util ); -sub _code_is_mine{ -# my($self, $code) = @_; - - return !exists $foreign{ Mouse::Util::get_code_package($_[1]) }; +sub _get_method_body { + my($self, $method_name) = @_; + my $code = Mouse::Util::get_code_ref($self->{package}, $method_name); + return $code && !exists $foreign{ Mouse::Util::get_code_package($code) } + ? $code + : undef; } sub add_method; sub has_method { my($self, $method_name) = @_; - defined($method_name) or $self->throw_error('You must define a method name'); - return defined($self->{methods}{$method_name}) || do{ - my $code = Mouse::Util::get_code_ref($self->{package}, $method_name); - $code && $self->_code_is_mine($code); - }; + return defined( $self->{methods}{$method_name} ) + || defined( $self->_get_method_body($method_name) ); } sub get_method_body { my($self, $method_name) = @_; - defined($method_name) or $self->throw_error('You must define a method name'); - return $self->{methods}{$method_name} ||= do{ - my $code = Mouse::Util::get_code_ref($self->{package}, $method_name); - $code && $self->_code_is_mine($code) ? $code : undef; - }; + return $self->{methods}{$method_name} + ||= $self->_get_method_body($method_name); } -sub get_method{ +sub get_method { my($self, $method_name) = @_; if(my $code = $self->get_method_body($method_name)){