X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FModule.pm;h=5588f29276ac137757ab326ad4bb9b30ba9e563e;hb=83fd4df5c46993d68fc0c2d84a1faffaef2b3cdd;hp=1c18447fcb5d8d61b41a1c6273651cf427ddd850;hpb=7eb3a8d52207d71fe91dad750a74c9f04bea568d;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 1c18447..5588f29 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -1,13 +1,9 @@ package Mouse::Meta::Module; -use strict; -use warnings; +use Mouse::Util qw/:meta get_code_package load_class not_supported/; # enables strict and warnings use Carp (); use Scalar::Util qw/blessed weaken/; -use Mouse::Util qw/:meta get_code_package not_supported load_class/; - - my %METAS; sub _metaclass_cache { # DEPRECATED @@ -88,10 +84,10 @@ sub add_method { } if(ref($code) ne 'CODE'){ - not_supported 'add_method for a method object'; + $code = \&{$code}; # coerce } - $self->{methods}->{$name}++; # Moose stores meta object here. + $self->{methods}->{$name} = $code; # Moose stores meta object here. my $pkg = $self->name; no strict 'refs'; @@ -115,13 +111,32 @@ sub _code_is_mine{ sub has_method { my($self, $method_name) = @_; - return 1 if $self->{methods}->{$method_name}; + defined($method_name) + or $self->throw_error('You must define a method name'); - my $code = do{ no strict 'refs'; *{$self->{package} . '::' . $method_name}{CODE} }; + return 1 if $self->{methods}{$method_name}; + + my $code = do{ + no strict 'refs'; + *{ $self->{package} . '::' . $method_name }{CODE}; + }; 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 = do{ no strict 'refs'; *{$self->{package} . '::' . $method_name}{CODE} }; + + ($code && $self->_code_is_mine($code)) ? $code : undef; + }; +} + sub get_method{ my($self, $method_name) = @_;