fix typo in documentation
[p5sagit/Class-C3-Componentised.git] / t / 04-on-apply-use-base.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use Test::More;
6 use Test::Exception;
7
8 use lib "$FindBin::Bin/lib";
9
10 BEGIN {
11   package A::First;
12
13   use Class::C3::Componentised::ApplyHooks;
14
15   AFTER_APPLY { $_[0]->after("a $_[1]") };
16   AFTER_APPLY { $_[0]->after("b $_[1]") };
17   BEFORE_APPLY { $_[0]->before("a $_[1]") };
18   BEFORE_APPLY { $_[0]->before("b $_[1]") };
19
20   1;
21 }
22
23 BEGIN {
24   package A::Second;
25
26   use base 'A::First';
27
28   use Class::C3::Componentised::ApplyHooks
29     -after_apply => sub { $_[0]->after("a $_[1]") },
30     -before_apply => sub { $_[0]->before("a $_[1]") },
31     qw(BEFORE_APPLY AFTER_APPLY);
32
33   AFTER_APPLY { $_[0]->after("b $_[1]") };
34   BEFORE_APPLY { $_[0]->before("b $_[1]") };
35   1;
36 }
37
38
39 BEGIN {
40   package A::Third;
41
42   use base 'A::Second';
43
44   1;
45 }
46
47 BEGIN {
48   package A::Class::Second;
49
50   use base 'Class::C3::Componentised';
51   use Test::More;
52
53   our @before;
54   our @after;
55
56   sub component_base_class { 'A' }
57   __PACKAGE__->load_components('Second');
58
59   sub before { push @before, $_[1] }
60   sub after { push @after, $_[1] }
61
62   is_deeply(\@before, [
63     'b A::Second',
64     'a A::Second',
65     'b A::First',
66     'a A::First',
67   ], 'before runs in the correct order');
68   is_deeply(\@after, [
69     'a A::First',
70     'b A::First',
71     'a A::Second',
72     'b A::Second',
73   ], 'after runs in the correct order');
74 }
75
76 BEGIN {
77   package A::Class::Third;
78
79   use base 'Class::C3::Componentised';
80   use Test::More;
81
82   our @before;
83   our @after;
84
85   sub component_base_class { 'A' }
86   __PACKAGE__->load_components('Third');
87
88   sub before { push @before, $_[1] }
89   sub after { push @after, $_[1] }
90
91   is_deeply(\@before, [
92     'b A::Second',
93     'a A::Second',
94     'b A::First',
95     'a A::First',
96   ], 'before runs in the correct order');
97   is_deeply(\@after, [
98     'a A::First',
99     'b A::First',
100     'a A::Second',
101     'b A::Second',
102   ], 'after runs in the correct order');
103 }
104
105 done_testing;