6 use Test::More tests => 6;
9 use lib 'opt', '../opt', '..';
11 # uncomment this line, and re-run the
12 # test to see the normal p5 dispatch order
13 #$Class::C3::TURN_OFF_C3 = 1;
18 This tests the classic diamond inheritence pattern.
31 sub hello { 'Diamond_A::hello' }
32 sub foo { 'Diamond_A::foo' }
38 sub foo { 'Diamond_B::foo => ' . (shift)->next::method() }
45 sub hello { 'Diamond_C::hello => ' . (shift)->next::method() }
46 sub foo { 'Diamond_C::foo => ' . (shift)->next::method() }
50 use base ('Diamond_B', 'Diamond_C');
53 sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
56 Class::C3::initialize();
59 [ Class::C3::calculateMRO('Diamond_D') ],
60 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
61 '... got the right MRO for Diamond_D');
63 is(Diamond_D->hello, 'Diamond_C::hello => Diamond_A::hello', '... method resolved itself as expected');
65 is(Diamond_D->can('hello')->('Diamond_D'),
66 'Diamond_C::hello => Diamond_A::hello',
67 '... can(method) resolved itself as expected');
69 is(UNIVERSAL::can("Diamond_D", 'hello')->('Diamond_D'),
70 'Diamond_C::hello => Diamond_A::hello',
71 '... can(method) resolved itself as expected');
74 'Diamond_D::foo => Diamond_B::foo => Diamond_C::foo => Diamond_A::foo',
75 '... method foo resolved itself as expected');