2d49a8bfb201bb7e64e1b0c50abb5d9951f9a472
[gitmo/Moo.git] / xt / moose-method-modifiers.t
1 use strictures 1;
2 use Test::More;
3
4 use Moo::HandleMoose;
5
6 {
7    package ModifyFoo;
8    use Moo::Role;
9
10    our $before_ran = 0;
11    our $around_ran = 0;
12    our $after_ran = 0;
13
14    before foo => sub { $before_ran = 1 };
15    after foo => sub { $after_ran = 1 };
16    around foo => sub {
17       my ($orig, $self, @rest) = @_;
18       $self->$orig(@rest);
19       $around_ran = 1;
20    };
21
22    package Bar;
23    use Moose;
24    with 'ModifyFoo';
25
26    sub foo { }
27 }
28
29 my $bar = Bar->new;
30
31 ok(!$ModifyFoo::before_ran, 'before has not run yet');
32 ok(!$ModifyFoo::after_ran, 'after has not run yet');
33 ok(!$ModifyFoo::around_ran, 'around has not run yet');
34 $bar->foo;
35 ok($ModifyFoo::before_ran, 'before ran');
36 ok($ModifyFoo::after_ran, 'after ran');
37 ok($ModifyFoo::around_ran, 'around ran');
38
39 done_testing;