6 use Test::More tests => 8;
10 # uncomment this line, and re-run the
11 # test to see the normal p5 dispatch order
12 #$Class::C3::TURN_OFF_C3 = 1;
18 This example is take from: http://www.python.org/2.3/mro.html
37 Level 2 2 | E | 4 | D | | F | 5
43 Level 1 1 | B | | C | 3
52 (<class '__main__.A'>, <class '__main__.B'>, <class '__main__.E'>,
53 <class '__main__.C'>, <class '__main__.D'>, <class '__main__.F'>,
62 sub O_or_D { 'Test::O' }
63 sub O_or_F { 'Test::O' }
69 sub O_or_F { 'Test::F' }
79 sub O_or_D { 'Test::D' }
80 sub C_or_D { 'Test::D' }
83 use base ('Test::D', 'Test::F');
86 sub C_or_D { 'Test::C' }
89 use base ('Test::E', 'Test::D');
93 use base ('Test::B', 'Test::C');
97 Class::C3::initialize();
100 [ Class::C3::calculateMRO('Test::A') ],
101 [ qw(Test::A Test::B Test::E Test::C Test::D Test::F Test::O) ],
102 '... got the right MRO for Test::A');
104 is(Test::A->O_or_D, 'Test::D', '... got the right method dispatch');
105 is(Test::A->O_or_F, 'Test::F', '... got the right method dispatch');
108 # this test is particularly interesting because the p5 dispatch
109 # would actually call Test::D before Test::C and Test::D is a
110 # subclass of Test::C
111 is(Test::A->C_or_D, 'Test::C', '... got the right method dispatch');
113 Class::C3::uninitialize();
115 is(Test::A->O_or_D, 'Test::O', '... old dispatch order is restored');
116 is(Test::A->O_or_F, 'Test::O', '... old dispatch order is restored');
117 is(Test::A->C_or_D, 'Test::D', '... old dispatch order is restored');