af9492d67ea3dfd01ba6ae8caf14eee5d06472be
[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       $after_ran = 1;
20    };
21
22    package Bar;
23    use Moose;
24
25    sub foo { }
26 }
27
28 my $bar = Bar->new;
29
30 ok(!$ModifyFoo::before_ran, 'before has not run yet');
31 ok(!$ModifyFoo::after_ran, 'after has not run yet');
32 ok(!$ModifyFoo::around_ran, 'around has not run yet');
33 $bar->foo;
34 ok($ModifyFoo::before_ran, 'before ran');
35 ok($ModifyFoo::after_ran, 'after ran');
36 ok($ModifyFoo::around_ran, 'around ran');
37
38 done_testing;