update repo to point to github
[gitmo/Moo.git] / xt / moose-method-modifiers.t
CommitLineData
89e9bce8 1use strictures 1;
2use 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
27my $bar = Bar->new;
28
29ok(!$ModifyFoo::before_ran, 'before has not run yet');
30ok(!$ModifyFoo::after_ran, 'after has not run yet');
31ok(!$ModifyFoo::around_ran, 'around has not run yet');
32$bar->foo;
33ok($ModifyFoo::before_ran, 'before ran');
34ok($ModifyFoo::after_ran, 'after ran');
35ok($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
54my $baz = Baz->new;
55my $pre = $ModifyMultiple::before;
56$baz->foo;
57is $ModifyMultiple::before, $pre+1, "before applies to first of multiple subs";
58$baz->bar;
59is $ModifyMultiple::before, $pre+2, "before applies to second of multiple subs";
60
89e9bce8 61done_testing;