Commit | Line | Data |
4fd5e347 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
c13900f1 |
4 | use Test::More; |
5 | BEGIN { |
6 | if (eval "require Class::Method::Modifiers; 1") { |
7 | plan tests => 4; |
8 | } |
9 | else { |
10 | plan skip_all => "Class::Method::Modifiers required for this test"; |
11 | } |
12 | } |
eab81545 |
13 | use Test::Exception; |
4fd5e347 |
14 | |
15 | my @calls; |
16 | my ($before, $after, $around); |
17 | |
18 | do { |
19 | package Role; |
20 | use Mouse::Role; |
21 | |
22 | $before = sub { |
23 | push @calls, 'Role::foo:before'; |
24 | }; |
25 | before foo => $before; |
26 | |
27 | $after = sub { |
28 | push @calls, 'Role::foo:after'; |
29 | }; |
30 | after foo => $after; |
31 | |
32 | $around = sub { |
33 | my $orig = shift; |
34 | push @calls, 'Role::foo:around_before'; |
35 | $orig->(@_); |
36 | push @calls, 'Role::foo:around_after'; |
37 | }; |
38 | around foo => $around; |
39 | |
40 | no Mouse::Role; |
41 | }; |
42 | |
43 | is_deeply([Role->meta->get_before_method_modifiers('foo')], [$before]); |
44 | is_deeply([Role->meta->get_after_method_modifiers('foo')], [$after]); |
45 | is_deeply([Role->meta->get_around_method_modifiers('foo')], [$around]); |
46 | |
47 | do { |
48 | package Class; |
49 | use Mouse; |
50 | with 'Role'; |
51 | |
52 | sub foo { |
53 | push @calls, 'Class::foo'; |
54 | } |
55 | |
56 | no Mouse; |
57 | }; |
58 | |
59 | Class->foo; |
60 | is_deeply([splice @calls], [ |
61 | 'Role::foo:before', |
62 | 'Role::foo:around_before', |
63 | 'Class::foo', |
64 | 'Role::foo:around_after', |
65 | 'Role::foo:after', |
66 | ]); |
67 | |