Commit | Line | Data |
5f71050b |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
e606ae5f |
6 | use Test::More tests => 9; |
401cb5a6 |
7 | use Test::Exception; |
5f71050b |
8 | |
e606ae5f |
9 | |
5f71050b |
10 | |
11 | { |
12 | |
13 | package Dog; |
14 | use Moose; |
15 | |
16 | sub bark_once { |
17 | my $self = shift; |
18 | return 'bark'; |
19 | } |
20 | |
21 | sub bark_twice { |
22 | return 'barkbark'; |
23 | } |
24 | |
25 | around qr/bark.*/ => sub { |
401cb5a6 |
26 | 'Dog::around(' . $_[0]->() . ')'; |
5f71050b |
27 | }; |
28 | |
29 | } |
30 | |
31 | my $dog = Dog->new; |
401cb5a6 |
32 | is( $dog->bark_once, 'Dog::around(bark)', 'around modifier is called' ); |
33 | is( $dog->bark_twice, 'Dog::around(barkbark)', 'around modifier is called' ); |
5f71050b |
34 | |
35 | { |
36 | |
37 | package Cat; |
38 | use Moose; |
39 | our $BEFORE_BARK_COUNTER = 0; |
40 | our $AFTER_BARK_COUNTER = 0; |
41 | |
42 | sub bark_once { |
43 | my $self = shift; |
44 | return 'bark'; |
45 | } |
46 | |
47 | sub bark_twice { |
48 | return 'barkbark'; |
49 | } |
50 | |
51 | before qr/bark.*/ => sub { |
52 | $BEFORE_BARK_COUNTER++; |
53 | }; |
54 | |
55 | after qr/bark.*/ => sub { |
56 | $AFTER_BARK_COUNTER++; |
57 | }; |
58 | |
59 | } |
60 | |
61 | my $cat = Cat->new; |
62 | $cat->bark_once; |
63 | is( $Cat::BEFORE_BARK_COUNTER, 1, 'before modifier is called once' ); |
64 | is( $Cat::AFTER_BARK_COUNTER, 1, 'after modifier is called once' ); |
65 | $cat->bark_twice; |
66 | is( $Cat::BEFORE_BARK_COUNTER, 2, 'before modifier is called twice' ); |
67 | is( $Cat::AFTER_BARK_COUNTER, 2, 'after modifier is called twice' ); |
68 | |
69 | { |
401cb5a6 |
70 | package Dog::Role; |
71 | use Moose::Role; |
5f71050b |
72 | |
401cb5a6 |
73 | ::dies_ok { |
74 | before qr/bark.*/ => sub {}; |
75 | } '... this is not currently supported'; |
5f71050b |
76 | |
401cb5a6 |
77 | ::dies_ok { |
78 | around qr/bark.*/ => sub {}; |
79 | } '... this is not currently supported'; |
5f71050b |
80 | |
401cb5a6 |
81 | ::dies_ok { |
82 | after qr/bark.*/ => sub {}; |
83 | } '... this is not currently supported'; |
5f71050b |
84 | |
85 | } |
86 | |