bump version to 0.77
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Wrapped.pm
index 0055265..7cb8b3f 100644 (file)
@@ -5,10 +5,10 @@ use strict;
 use warnings;
 
 use Carp         'confess';
-use Scalar::Util 'reftype', 'blessed';
-use Sub::Name    'subname';
+use Scalar::Util 'blessed';
 
-our $VERSION   = '0.02';
+our $VERSION   = '0.77';
+$VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Class::MOP::Method';
@@ -69,10 +69,11 @@ my $_build_wrapped_method = sub {
 };
 
 sub wrap {
-    my $class = shift;
-    my $code  = shift;
+    my ( $class, $code, %params ) = @_;
+    
     (blessed($code) && $code->isa('Class::MOP::Method'))
         || confess "Can only wrap blessed CODE";
+        
     my $modifier_table = {
         cache  => undef,
         orig   => $code,
@@ -84,28 +85,44 @@ sub wrap {
         },
     };
     $_build_wrapped_method->($modifier_table);
-    my $method = $class->SUPER::wrap(sub { $modifier_table->{cache}->(@_) });
-    $method->{'%!modifier_table'} = $modifier_table;
+    my $method = $class->SUPER::wrap(
+        sub { $modifier_table->{cache}->(@_) },
+        # get these from the original 
+        # unless explicitly overriden
+        package_name => $params{package_name} || $code->package_name,
+        name         => $params{name}         || $code->name,
+    );
+    $method->{'modifier_table'} = $modifier_table;
     $method;
 }
 
 sub get_original_method {
     my $code = shift;
-    $code->{'%!modifier_table'}->{orig};
+    $code->{'modifier_table'}->{orig};
 }
 
 sub add_before_modifier {
     my $code     = shift;
     my $modifier = shift;
-    unshift @{$code->{'%!modifier_table'}->{before}} => $modifier;
-    $_build_wrapped_method->($code->{'%!modifier_table'});
+    unshift @{$code->{'modifier_table'}->{before}} => $modifier;
+    $_build_wrapped_method->($code->{'modifier_table'});
+}
+
+sub before_modifiers {
+    my $code = shift;
+    return @{$code->{'modifier_table'}->{before}};
 }
 
 sub add_after_modifier {
     my $code     = shift;
     my $modifier = shift;
-    push @{$code->{'%!modifier_table'}->{after}} => $modifier;
-    $_build_wrapped_method->($code->{'%!modifier_table'});
+    push @{$code->{'modifier_table'}->{after}} => $modifier;
+    $_build_wrapped_method->($code->{'modifier_table'});
+}
+
+sub after_modifiers {
+    my $code = shift;
+    return @{$code->{'modifier_table'}->{after}};
 }
 
 {
@@ -126,15 +143,20 @@ sub add_after_modifier {
     sub add_around_modifier {
         my $code     = shift;
         my $modifier = shift;
-        unshift @{$code->{'%!modifier_table'}->{around}->{methods}} => $modifier;
-        $code->{'%!modifier_table'}->{around}->{cache} = $compile_around_method->(
-            @{$code->{'%!modifier_table'}->{around}->{methods}},
-            $code->{'%!modifier_table'}->{orig}->body
+        unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier;
+        $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->(
+            @{$code->{'modifier_table'}->{around}->{methods}},
+            $code->{'modifier_table'}->{orig}->body
         );
-        $_build_wrapped_method->($code->{'%!modifier_table'});
+        $_build_wrapped_method->($code->{'modifier_table'});
     }
 }
 
+sub around_modifiers {
+    my $code = shift;
+    return @{$code->{'modifier_table'}->{around}->{methods}};
+}
+
 1;
 
 __END__
@@ -145,26 +167,35 @@ __END__
 
 Class::MOP::Method::Wrapped - Method Meta Object to handle before/around/after modifiers
 
-=head1 SYNOPSIS
-
-  # ... more to come later maybe
-
 =head1 DESCRIPTION
 
+This is a L<Class::MOP::Method> subclass which provides the funtionality 
+to wrap a given CODE reference with before, after and around method modifiers.
+
 =head1 METHODS
 
 =head2 Construction
 
 =over 4
 
-=item B<wrap (&code)>
+=item B<wrap ($code)>
+
+This is the constructor, it will return a B<Class::MOP::Method::Wrapped>
+instance that can be used to add before, after and around modifiers to.
 
 =item B<get_original_method>
 
+This returns the original CODE reference that was provided to the 
+constructor.
+
 =back
 
 =head2 Modifiers
 
+These three methods will add the method modifiers to the wrapped 
+CODE reference. For more information on how method modifiers work, 
+see the section in L<Class::MOP::Class>.
+
 =over 4
 
 =item B<add_before_modifier ($code)>
@@ -175,6 +206,19 @@ Class::MOP::Method::Wrapped - Method Meta Object to handle before/around/after m
 
 =back
 
+These three methods each returna list of method modifiers I<in the
+order in which they are run>.
+
+=over 4
+
+=item B<before_modifiers>
+
+=item B<after_modifiers>
+
+=item B<around_modifiers>
+
+=back
+
 =head1 AUTHORS
 
 Stevan Little E<lt>stevan@iinteractive.comE<gt>