X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FModule.pm;h=bccd7a635a98cde69d6dbabf0dbeb5af36f3d8d3;hb=6a7756cc831fa21bc28b924a8edbaeeb28a4a66b;hp=8276d5d052ea26c4f5d7ba87bd527102080f71cb;hpb=01d4f728d7f3689267bdfbc997e1fbe02f19fabd;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 8276d5d..bccd7a6 100644 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -1,5 +1,5 @@ package Mouse::Meta::Module; -use Mouse::Util qw/:meta get_code_package get_code_ref not_supported/; # enables strict and warnings +use Mouse::Util qw/:meta/; # enables strict and warnings use Carp (); use Scalar::Util (); @@ -79,44 +79,40 @@ sub remove_attribute { delete $_[0]->{attributes}->{$_[1]} } sub get_attribute_list{ keys %{$_[0]->{attributes}} } -# XXX: for backward compatibility +# XXX: not completely compatible with Moose 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{ 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 = 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 = 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)){ @@ -232,7 +228,7 @@ sub create { my $meta = $self->initialize( $package_name, %options); - Scalar::Util::weaken $METAS{$package_name} + Scalar::Util::weaken($METAS{$package_name}) if $mortal; $meta->add_method(meta => sub { @@ -319,7 +315,7 @@ Mouse::Meta::Module - The common base class of Mouse::Meta::Class and Mouse::Met =head1 VERSION -This document describes Mouse version 0.72 +This document describes Mouse version 0.78 =head1 DESCRIPTION