Commit | Line | Data |
e1a479c5 |
1 | #!./perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | BEGIN { |
6 | unless (-d 'blib') { |
7 | chdir 't' if -d 't'; |
8 | @INC = '../lib'; |
9 | } |
10 | } |
11 | |
12 | use Test::More tests => 12; |
13 | |
14 | =pod |
15 | |
16 | This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879 |
17 | |
18 | --- --- --- |
19 | Level 5 8 | A | 9 | B | A | C | (More General) |
20 | --- --- --- V |
21 | \ | / | |
22 | \ | / | |
23 | \ | / | |
24 | \ | / | |
25 | --- | |
26 | Level 4 7 | D | | |
27 | --- | |
28 | / \ | |
29 | / \ | |
30 | --- --- | |
31 | Level 3 4 | G | 6 | E | | |
32 | --- --- | |
33 | | | | |
34 | | | | |
35 | --- --- | |
36 | Level 2 3 | H | 5 | F | | |
37 | --- --- | |
38 | \ / | | |
39 | \ / | | |
40 | \ | | |
41 | / \ | | |
42 | / \ | | |
43 | --- --- | |
44 | Level 1 1 | J | 2 | I | | |
45 | --- --- | |
46 | \ / | |
47 | \ / | |
48 | --- v |
49 | Level 0 0 | K | (More Specialized) |
50 | --- |
51 | |
52 | |
53 | 0123456789A |
54 | KJIHGFEDABC |
55 | |
56 | =cut |
57 | |
58 | { |
59 | package Test::A; use mro 'c3'; |
60 | |
61 | package Test::B; use mro 'c3'; |
62 | |
63 | package Test::C; use mro 'c3'; |
64 | |
65 | package Test::D; use mro 'c3'; |
66 | use base qw/Test::A Test::B Test::C/; |
67 | |
68 | package Test::E; use mro 'c3'; |
69 | use base qw/Test::D/; |
70 | |
71 | package Test::F; use mro 'c3'; |
72 | use base qw/Test::E/; |
73 | sub testmeth { "wrong" } |
74 | |
75 | package Test::G; use mro 'c3'; |
76 | use base qw/Test::D/; |
77 | |
78 | package Test::H; use mro 'c3'; |
79 | use base qw/Test::G/; |
80 | |
81 | package Test::I; use mro 'c3'; |
82 | use base qw/Test::H Test::F/; |
83 | sub testmeth { "right" } |
84 | |
85 | package Test::J; use mro 'c3'; |
86 | use base qw/Test::F/; |
87 | |
88 | package Test::K; use mro 'c3'; |
89 | use base qw/Test::J Test::I/; |
90 | sub testmeth { shift->next::method } |
91 | } |
92 | |
93 | is_deeply( |
94 | mro::get_linear_isa('Test::A'), |
95 | [ qw(Test::A) ], |
96 | '... got the right C3 merge order for Test::A'); |
97 | |
98 | is_deeply( |
99 | mro::get_linear_isa('Test::B'), |
100 | [ qw(Test::B) ], |
101 | '... got the right C3 merge order for Test::B'); |
102 | |
103 | is_deeply( |
104 | mro::get_linear_isa('Test::C'), |
105 | [ qw(Test::C) ], |
106 | '... got the right C3 merge order for Test::C'); |
107 | |
108 | is_deeply( |
109 | mro::get_linear_isa('Test::D'), |
110 | [ qw(Test::D Test::A Test::B Test::C) ], |
111 | '... got the right C3 merge order for Test::D'); |
112 | |
113 | is_deeply( |
114 | mro::get_linear_isa('Test::E'), |
115 | [ qw(Test::E Test::D Test::A Test::B Test::C) ], |
116 | '... got the right C3 merge order for Test::E'); |
117 | |
118 | is_deeply( |
119 | mro::get_linear_isa('Test::F'), |
120 | [ qw(Test::F Test::E Test::D Test::A Test::B Test::C) ], |
121 | '... got the right C3 merge order for Test::F'); |
122 | |
123 | is_deeply( |
124 | mro::get_linear_isa('Test::G'), |
125 | [ qw(Test::G Test::D Test::A Test::B Test::C) ], |
126 | '... got the right C3 merge order for Test::G'); |
127 | |
128 | is_deeply( |
129 | mro::get_linear_isa('Test::H'), |
130 | [ qw(Test::H Test::G Test::D Test::A Test::B Test::C) ], |
131 | '... got the right C3 merge order for Test::H'); |
132 | |
133 | is_deeply( |
134 | mro::get_linear_isa('Test::I'), |
135 | [ qw(Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ], |
136 | '... got the right C3 merge order for Test::I'); |
137 | |
138 | is_deeply( |
139 | mro::get_linear_isa('Test::J'), |
140 | [ qw(Test::J Test::F Test::E Test::D Test::A Test::B Test::C) ], |
141 | '... got the right C3 merge order for Test::J'); |
142 | |
143 | is_deeply( |
144 | mro::get_linear_isa('Test::K'), |
145 | [ qw(Test::K Test::J Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ], |
146 | '... got the right C3 merge order for Test::K'); |
147 | |
148 | is(Test::K->testmeth(), "right", 'next::method working ok'); |