X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FModule.pm;h=9dbe85dd197806cba8742b825687f25903c862ee;hp=a4ddb380a18027a4c988211b0bcad25b1d3430a7;hb=745220df2da2256a9bd2692ac585f39b35ed19df;hpb=8d59c7239b90bb75b0187decbed09c6952e2b4a5 diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index a4ddb38..9dbe85d 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -1,5 +1,7 @@ package Mouse::Meta::Module; -use Mouse::Util qw/:meta get_code_package load_class not_supported/; # enables strict and warnings +use Mouse::Util qw/:meta get_code_package get_code_ref load_class not_supported/; # enables strict and warnings + +use Mouse::Util::TypeConstraints (); use Carp (); use Scalar::Util qw/blessed weaken/; @@ -38,9 +40,9 @@ sub get_metaclass_by_name { $METAS{$_[0]} } #sub does_metaclass_exist { defined $METAS{$_[0]} } #sub remove_metaclass_by_name { delete $METAS{$_[0]} } +sub name; - -sub name { $_[0]->{package} } +sub namespace; # The followings are Class::MOP specific methods @@ -67,12 +69,6 @@ sub get_attribute { $_[0]->{attributes}->{$_[1]} } sub get_attribute_list{ keys %{$_[0]->{attributes}} } sub remove_attribute { delete $_[0]->{attributes}->{$_[1]} } -sub namespace{ - my $name = $_[0]->{package}; - no strict 'refs'; - return \%{ $name . '::' }; -} - sub add_method { my($self, $name, $code) = @_; @@ -91,7 +87,7 @@ sub add_method { my $pkg = $self->name; no strict 'refs'; - no warnings 'redefine'; + no warnings 'redefine', 'once'; *{ $pkg . '::' . $name } = $code; } @@ -114,13 +110,25 @@ sub has_method { defined($method_name) or $self->throw_error('You must define a method name'); - return 1 if $self->{methods}->{$method_name}; + return 1 if $self->{methods}{$method_name}; - my $code = do{ no strict 'refs'; *{$self->{package} . '::' . $method_name}{CODE} }; + my $code = get_code_ref($self->{package}, $method_name); return $code && $self->_code_is_mine($code); } +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; + }; +} + sub get_method{ my($self, $method_name) = @_; @@ -128,11 +136,11 @@ sub get_method{ my $method_metaclass = $self->method_metaclass; load_class($method_metaclass); - my $package = $self->name; - return $method_metaclass->new( - body => $package->can($method_name), - name => $method_name, - package => $package, + return $method_metaclass->wrap( + body => $self->get_method_body($method_name), + name => $method_name, + package => $self->name, + associated_metaclass => $self, ); } @@ -158,7 +166,7 @@ sub get_method_list { my $superclasses; if(exists $options{superclasses}){ - if($self->isa('Mouse::Meta::Role')){ + if(Mouse::Util::TypeConstraints::_is_a_metarole($self)){ delete $options{superclasses}; } else{ @@ -303,6 +311,10 @@ __END__ Mouse::Meta::Module - The base class for Mouse::Meta::Class and Mouse::Meta::Role +=head1 VERSION + +This document describes Mouse version 0.40_01 + =head1 SEE ALSO L