Fix prototype on message {...}
[gitmo/Mouse.git] / t / 027-modifiers.t
CommitLineData
879a325b 1#!perl -T
2use strict;
3use warnings;
c13900f1 4
5use Test::More;
6BEGIN {
7 if (eval "require Class::Method::Modifiers; 1") {
8 plan tests => 1;
9 }
10 else {
11 plan skip_all => "Class::Method::Modifiers required for this test";
12 }
13}
879a325b 14
15my @seen;
16my @expected = ("before 4",
17 "before 3",
18 "around 4 before",
19 "around 3 before",
20 "before 2",
21 "before 1",
22 "around 2 before",
23 "around 1 before",
24 "orig",
25 "around 1 after",
26 "around 2 after",
27 "after 1",
28 "after 2",
29 "around 3 after",
30 "around 4 after",
31 "after 3",
32 "after 4",
33 );
34
35my $child = Grandchild->new; $child->orig;
36
37is_deeply(\@seen, \@expected, "multiple afters called in the right order");
38
39BEGIN {
40 package Parent;
41 use Mouse;
42
43 sub orig {
44 push @seen, "orig";
45 }
46}
47
48BEGIN {
49 package Child;
50 use Mouse;
51 extends 'Parent';
52
53 before orig => sub {
54 push @seen, "before 1";
55 };
56
57 before orig => sub {
58 push @seen, "before 2";
59 };
60
61 around orig => sub {
62 my $orig = shift;
63 push @seen, "around 1 before";
64 $orig->();
65 push @seen, "around 1 after";
66 };
67
68 around orig => sub {
69 my $orig = shift;
70 push @seen, "around 2 before";
71 $orig->();
72 push @seen, "around 2 after";
73 };
74
75 after orig => sub {
76 push @seen, "after 1";
77 };
78
79 after orig => sub {
80 push @seen, "after 2";
81 };
82}
83
84BEGIN {
85 package Grandchild;
86 use Mouse;
87 extends 'Child';
88
89 before orig => sub {
90 push @seen, "before 3";
91 };
92
93 before orig => sub {
94 push @seen, "before 4";
95 };
96
97 around orig => sub {
98 my $orig = shift;
99 push @seen, "around 3 before";
100 $orig->();
101 push @seen, "around 3 after";
102 };
103
104 around orig => sub {
105 my $orig = shift;
106 push @seen, "around 4 before";
107 $orig->();
108 push @seen, "around 4 after";
109 };
110
111 after orig => sub {
112 push @seen, "after 3";
113 };
114
115 after orig => sub {
116 push @seen, "after 4";
117 };
118}
119