Commit | Line | Data |
89e9bce8 |
1 | use strictures 1; |
2 | use Test::More; |
3 | |
89e9bce8 |
4 | { |
cb35d359 |
5 | package ModifyFoo; |
89e9bce8 |
6 | use Moo::Role; |
7 | |
8 | our $before_ran = 0; |
9 | our $around_ran = 0; |
10 | our $after_ran = 0; |
11 | |
12 | before foo => sub { $before_ran = 1 }; |
13 | after foo => sub { $after_ran = 1 }; |
14 | around foo => sub { |
15 | my ($orig, $self, @rest) = @_; |
16 | $self->$orig(@rest); |
146fb407 |
17 | $around_ran = 1; |
89e9bce8 |
18 | }; |
19 | |
20 | package Bar; |
21 | use Moose; |
cb35d359 |
22 | with 'ModifyFoo'; |
89e9bce8 |
23 | |
24 | sub foo { } |
25 | } |
26 | |
27 | my $bar = Bar->new; |
28 | |
29 | ok(!$ModifyFoo::before_ran, 'before has not run yet'); |
30 | ok(!$ModifyFoo::after_ran, 'after has not run yet'); |
31 | ok(!$ModifyFoo::around_ran, 'around has not run yet'); |
32 | $bar->foo; |
33 | ok($ModifyFoo::before_ran, 'before ran'); |
34 | ok($ModifyFoo::after_ran, 'after ran'); |
35 | ok($ModifyFoo::around_ran, 'around ran'); |
36 | |
25ceb5de |
37 | { |
38 | package ModifyMultiple; |
39 | use Moo::Role; |
40 | our $before = 0; |
41 | |
42 | before 'foo', 'bar' => sub { |
43 | $before++; |
44 | }; |
45 | |
46 | package Baz; |
47 | use Moose; |
48 | with 'ModifyMultiple'; |
49 | |
50 | sub foo {} |
51 | sub bar {} |
52 | } |
53 | |
54 | my $baz = Baz->new; |
55 | my $pre = $ModifyMultiple::before; |
56 | $baz->foo; |
57 | is $ModifyMultiple::before, $pre+1, "before applies to first of multiple subs"; |
58 | $baz->bar; |
59 | is $ModifyMultiple::before, $pre+2, "before applies to second of multiple subs"; |
60 | |
89e9bce8 |
61 | done_testing; |