From: Dave Rolsky Date: Fri, 7 Nov 2008 19:59:57 +0000 (+0000) Subject: Added introspection methods for method modifiers, along with tests. X-Git-Tag: 0.69~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b88aa2e8d394623bfccf6eb8052dba12acf1e69a;p=gitmo%2FClass-MOP.git Added introspection methods for method modifiers, along with tests. --- diff --git a/Changes b/Changes index 5907234..b2770b0 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Perl extension Class-MOP. +0.69 + * Class::MOP::Method::Wrapped + - Added introspection methods for method modifiers (Dave Rolsky) + + 0.68 Fri October 24, 2008 * Class::MOP - Make load_class require by file name instead of module name. diff --git a/lib/Class/MOP/Method/Wrapped.pm b/lib/Class/MOP/Method/Wrapped.pm index c3a355d..883fbcd 100644 --- a/lib/Class/MOP/Method/Wrapped.pm +++ b/lib/Class/MOP/Method/Wrapped.pm @@ -108,6 +108,11 @@ sub add_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; @@ -115,6 +120,11 @@ sub add_after_modifier { $_build_wrapped_method->($code->{'modifier_table'}); } +sub after_modifiers { + my $code = shift; + return @{$code->{'modifier_table'}->{after}}; +} + { # NOTE: # this is another possible candidate for @@ -142,6 +152,11 @@ sub add_after_modifier { } } +sub around_modifiers { + my $code = shift; + return @{$code->{'modifier_table'}->{around}->{methods}}; +} + 1; __END__ @@ -191,6 +206,19 @@ see the section in L. =back +These three methods each returna list of method modifiers I. + +=over 4 + +=item B + +=item B + +=item B + +=back + =head1 AUTHORS Stevan Little Estevan@iinteractive.comE diff --git a/t/031_method_modifiers.t b/t/031_method_modifiers.t index 200b045..00f564a 100644 --- a/t/031_method_modifiers.t +++ b/t/031_method_modifiers.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 24; +use Test::More tests => 28; use Test::Exception; use Class::MOP; @@ -143,3 +143,68 @@ use Class::MOP::Method; ); } +# test introspection +{ + sub before1 { + } + + sub before2 { + } + + sub before3 { + } + + sub after1 { + } + + sub after2 { + } + + sub after3 { + } + + sub around1 { + } + + sub around2 { + } + + sub around3 { + } + + sub orig { + } + + my $method = Class::MOP::Method->wrap( + body => \&orig, + package_name => 'main', + name => '__ANON__', + ); + + my $wrapped = Class::MOP::Method::Wrapped->wrap($method); + + $wrapped->add_before_modifier($_) + for \&before1, \&before2, \&before3; + + $wrapped->add_after_modifier($_) + for \&after1, \&after2, \&after3; + + $wrapped->add_around_modifier($_) + for \&around1, \&around2, \&around3; + + is( $wrapped->get_original_method, $method, + 'check get_original_method' ); + + is_deeply( [ $wrapped->before_modifiers ], + [ \&before3, \&before2, \&before1 ], + 'check before_modifiers' ); + + is_deeply( [ $wrapped->after_modifiers ], + [ \&after1, \&after2, \&after3 ], + 'check after_modifiers' ); + + is_deeply( [ $wrapped->around_modifiers ], + [ \&around3, \&around2, \&around1 ], + 'check around_modifiers' ); +} +