6 use Test::More no_plan => 18;
11 use_ok('Class::MOP::Method');
14 # test before and afters
18 my $method = Class::MOP::Method->new(sub { $trace .= 'primary' });
19 isa_ok($method, 'Class::MOP::Method');
22 is($trace, 'primary', '... got the right return value from method');
25 my $wrapped = $method->wrap();
26 isa_ok($wrapped, 'Class::MOP::Method');
29 is($trace, 'primary', '... got the right return value from the wrapped method');
33 $wrapped->add_before_modifier(sub { $trace .= 'before -> ' });
34 } '... added the before modifier okay';
37 is($trace, 'before -> primary', '... got the right return value from the wrapped method (w/ before)');
41 $wrapped->add_after_modifier(sub { $trace .= ' -> after' });
42 } '... added the after modifier okay';
45 is($trace, 'before -> primary -> after', '... got the right return value from the wrapped method (w/ before)');
51 my $method = Class::MOP::Method->new(sub { 4 });
52 isa_ok($method, 'Class::MOP::Method');
54 is($method->(), 4, '... got the right value from the wrapped method');
56 my $wrapped = $method->wrap;
57 isa_ok($wrapped, 'Class::MOP::Method');
59 is($wrapped->(), 4, '... got the right value from the wrapped method');
62 $wrapped->add_around_modifier(sub { (3, $_[0]->()) });
63 $wrapped->add_around_modifier(sub { (2, $_[0]->()) });
64 $wrapped->add_around_modifier(sub { (1, $_[0]->()) });
65 $wrapped->add_around_modifier(sub { (0, $_[0]->()) });
66 } '... added the around modifier okay';
71 '... got the right results back from the around methods (in list context)');
73 is(scalar $wrapped->(), 4, '... got the right results back from the around methods (in scalar context)');