X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FMethod.pm;h=5642d7069cd159f4e06b3f8317d49291232da8ca;hb=4c1053331a179a6d1dd8e71d49ef05852a81387e;hp=b726e7cfd5df46f73a580aa7770f25d362738247;hpb=3c0a80878fdb1cf4f552c9abff0fc50fb51ad77a;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Method.pm b/lib/Class/MOP/Method.pm index b726e7c..5642d70 100644 --- a/lib/Class/MOP/Method.pm +++ b/lib/Class/MOP/Method.pm @@ -7,7 +7,7 @@ use warnings; use Carp 'confess'; use Scalar::Util 'reftype', 'blessed'; -our $VERSION = '0.06'; +our $VERSION = '0.07'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Object'; @@ -20,12 +20,15 @@ use overload '&{}' => sub { $_[0]->body }, fallback => 1; # construction sub wrap { - my $class = shift; - my $code = shift; + my ( $class, $code, %params ) = @_; + ('CODE' eq (reftype($code) || '')) || confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")"; + bless { - '&!body' => $code + '&!body' => $code, + '$!package_name' => $params{package_name}, + '$!name' => $params{name}, } => blessed($class) || $class; } @@ -37,31 +40,27 @@ sub body { (shift)->{'&!body'} } # informational -# NOTE: -# this may not be the same name -# as the class you got it from -# This gets the package stash name -# associated with the actual CODE-ref sub package_name { - my $code = (shift)->body; - (Class::MOP::get_code_info($code))[0]; + my $self = shift; + $self->{'$!package_name'} ||= (Class::MOP::get_code_info($self->body))[0]; } -# NOTE: -# this may not be the same name -# as the method name it is stored -# with. This gets the name associated -# with the actual CODE-ref sub name { - my $code = (shift)->body; - (Class::MOP::get_code_info($code))[1]; + my $self = shift; + $self->{'$!name'} ||= (Class::MOP::get_code_info($self->body))[1]; } sub fully_qualified_name { - my $code = shift; - $code->package_name . '::' . $code->name; + my $code = shift; + $code->package_name . '::' . $code->name; } +# NOTE: +# the Class::MOP bootstrap +# will create this for us +# - SL +# sub clone { ... } + 1; __END__ @@ -95,10 +94,18 @@ to this class. =over 4 -=item B +=item B This is the basic constructor, it returns a B -instance which wraps the given C<$code> reference. +instance which wraps the given C<$code> reference. You can also +set the C and C attributes using the C<%params>. +If these are not set, then thier accessors will attempt to figure +it out using the C function. + +=item B + +This will make a copy of the object, allowing you to override +any values by stuffing them in C<%params>. =back