6 use Test::More tests => 15;
10 # uncomment this line, and re-run the
11 # test to see the normal p5 dispatch order
12 #$Class::C3::TURN_OFF_C3 = 1;
17 This example is take from: http://www.python.org/2.3/mro.html
31 Level 3 | O | (more general)
37 Level 2 3 | D | 4| E | | F | 5 |
43 Level 1 1 | B | | C | 2 |
48 Level 0 0 | A | (more specialized)
65 sub C_or_E { 'Test::E' }
71 sub C_or_D { 'Test::D' }
74 use base ('Test::D', 'Test::F');
77 sub C_or_D { 'Test::C' }
78 sub C_or_E { 'Test::C' }
82 use base ('Test::D', 'Test::E');
85 use base ('Test::B', 'Test::C');
90 [ Class::C3::calculateMRO('Test::F') ],
91 [ qw(Test::F Test::O) ],
92 '... got the right MRO for Test::F');
95 [ Class::C3::calculateMRO('Test::E') ],
96 [ qw(Test::E Test::O) ],
97 '... got the right MRO for Test::E');
100 [ Class::C3::calculateMRO('Test::D') ],
101 [ qw(Test::D Test::O) ],
102 '... got the right MRO for Test::D');
105 [ Class::C3::calculateMRO('Test::C') ],
106 [ qw(Test::C Test::D Test::F Test::O) ],
107 '... got the right MRO for Test::C');
110 [ Class::C3::calculateMRO('Test::B') ],
111 [ qw(Test::B Test::D Test::E Test::O) ],
112 '... got the right MRO for Test::B');
115 [ Class::C3::calculateMRO('Test::A') ],
116 [ qw(Test::A Test::B Test::C Test::D Test::E Test::F Test::O) ],
117 '... got the right MRO for Test::A');
119 is(Test::A->C_or_D, 'Test::C', '... got the expected method output');
120 is(Test::A->can('C_or_D')->(), 'Test::C', '... can got the expected method output');
122 is(Test::A->C_or_E, 'Test::C', '... got the expected method output');
123 is(Test::A->can('C_or_E')->(), 'Test::C', '... can got the expected method output');
126 Class::C3::uninitialize();
128 is(Test::A->C_or_D, 'Test::D', '... old method resolution has been restored');
129 is(Test::A->can('C_or_D')->(), 'Test::D', '... old can(method) resolution has been restored');
131 is(Test::A->C_or_E, 'Test::E', '... old method resolution has been restored');
132 is(Test::A->can('C_or_E')->(), 'Test::E', '... old can(method) resolution has been restored');