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.
$_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;
$_build_wrapped_method->($code->{'modifier_table'});
}
+sub after_modifiers {
+ my $code = shift;
+ return @{$code->{'modifier_table'}->{after}};
+}
+
{
# NOTE:
# this is another possible candidate for
}
}
+sub around_modifiers {
+ my $code = shift;
+ return @{$code->{'modifier_table'}->{around}->{methods}};
+}
+
1;
__END__
=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>
use strict;
use warnings;
-use Test::More tests => 24;
+use Test::More tests => 28;
use Test::Exception;
use Class::MOP;
);
}
+# 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' );
+}
+