File: moose-method-modifiers.t

package info (click to toggle)
libmoo-perl 0.091011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 476 kB
  • sloc: perl: 1,688; makefile: 4; sh: 1
file content (39 lines) | stat: -rw-r--r-- 776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use strictures 1;
use Test::More;

use Moo::HandleMoose;

{
   package ModifyFoo;
   use Moo::Role;

   our $before_ran = 0;
   our $around_ran = 0;
   our $after_ran = 0;

   before foo => sub { $before_ran = 1 };
   after foo => sub { $after_ran = 1 };
   around foo => sub {
      my ($orig, $self, @rest) = @_;
      $self->$orig(@rest);
      $around_ran = 1;
   };

   package Bar;
   use Moose;
   with 'ModifyFoo';

   sub foo { }
}

my $bar = Bar->new;

ok(!$ModifyFoo::before_ran, 'before has not run yet');
ok(!$ModifyFoo::after_ran, 'after has not run yet');
ok(!$ModifyFoo::around_ran, 'around has not run yet');
$bar->foo;
ok($ModifyFoo::before_ran, 'before ran');
ok($ModifyFoo::after_ran, 'after ran');
ok($ModifyFoo::around_ran, 'around ran');

done_testing;