Commit | Line | Data |
d0e2efe5 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 5; |
7 | |
8 | BEGIN { |
9 | use_ok('Class::C3'); |
10 | # uncomment this line, and re-run the |
11 | # test to see the normal p5 dispatch order |
12 | #$Class::C3::TURN_OFF_C3 = 1; |
13 | } |
14 | |
15 | =pod |
16 | |
17 | Start with this: |
18 | |
19 | <A> |
20 | / \ |
21 | <B> <C> |
22 | \ / |
23 | <D> |
24 | |
25 | =cut |
26 | |
27 | { |
28 | package Diamond_A; |
29 | use Class::C3; |
30 | sub hello { 'Diamond_A::hello' } |
31 | } |
32 | { |
33 | package Diamond_B; |
34 | use base 'Diamond_A'; |
35 | use Class::C3; |
36 | } |
37 | { |
38 | package Diamond_C; |
39 | use Class::C3; |
40 | use base 'Diamond_A'; |
41 | sub hello { 'Diamond_C::hello' } |
42 | } |
43 | { |
44 | package Diamond_D; |
45 | use base ('Diamond_B', 'Diamond_C'); |
46 | use Class::C3; |
47 | } |
48 | |
2ffffc6d |
49 | Class::C3::initialize(); |
50 | |
d0e2efe5 |
51 | is_deeply( |
52 | [ Class::C3::calculateMRO('Diamond_D') ], |
53 | [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ], |
54 | '... got the right MRO for Diamond_D'); |
55 | |
56 | =pod |
57 | |
58 | Then change it to this: |
59 | |
60 | <E> <A> |
61 | \ / \ |
62 | <B> <C> |
63 | \ / |
64 | <D> |
65 | |
66 | =cut |
67 | |
68 | { |
69 | package Diamond_E; |
70 | use Class::C3; |
71 | sub hello { 'Diamond_E::hello' } |
72 | } |
73 | |
74 | { |
75 | no strict 'refs'; |
76 | unshift @{"Diamond_B::ISA"} => 'Diamond_E'; |
77 | } |
78 | |
79 | is_deeply( |
80 | [ Class::C3::calculateMRO('Diamond_D') ], |
81 | [ qw(Diamond_D Diamond_B Diamond_E Diamond_C Diamond_A) ], |
82 | '... got the new MRO for Diamond_D'); |
83 | |
27195a45 |
84 | SKIP: { |
85 | skip "This test makes no sense with this perl", 1 if $Class::C3::C3_IN_CORE; |
86 | is(Diamond_D->hello, 'Diamond_C::hello', '... method still resolves with old MRO'); |
87 | } |
d0e2efe5 |
88 | |
89 | Class::C3::reinitialize(); |
90 | |
91 | is(Diamond_D->hello, 'Diamond_E::hello', '... method resolves with reinitialized MRO'); |