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