Commit | Line | Data |
de19f115 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 18; |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Class::MOP'); |
11 | use_ok('Class::MOP::Method'); |
12 | } |
13 | |
14 | my $trace = ''; |
15 | |
16 | my $method = Class::MOP::Method->new(sub { $trace .= 'primary' }); |
17 | isa_ok($method, 'Class::MOP::Method'); |
18 | |
19 | $method->(); |
20 | is($trace, 'primary', '... got the right return value from method'); |
21 | $trace = ''; |
22 | |
23 | my $wrapped = $method->wrap(); |
24 | isa_ok($wrapped, 'Class::MOP::Method'); |
25 | |
26 | $wrapped->(); |
27 | is($trace, 'primary', '... got the right return value from the wrapped method'); |
28 | $trace = ''; |
29 | |
30 | lives_ok { |
31 | $wrapped->add_before_modifier(sub { $trace .= 'before -> ' }); |
32 | } '... added the before modifier okay'; |
33 | |
34 | $wrapped->(); |
35 | is($trace, 'before -> primary', '... got the right return value from the wrapped method (w/ before)'); |
36 | $trace = ''; |
37 | |
38 | lives_ok { |
39 | $wrapped->add_after_modifier(sub { $trace .= ' -> after' }); |
40 | } '... added the after modifier okay'; |
41 | |
42 | $wrapped->(); |
43 | is($trace, 'before -> primary -> after', '... got the right return value from the wrapped method (w/ before)'); |
44 | $trace = ''; |