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