6 use Test::More tests => 9;
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 bar { 'Diamond_A::bar' }
32 sub baz { 'Diamond_A::baz' }
38 sub baz { 'Diamond_B::baz => ' . (shift)->next::method() }
44 sub foo { 'Diamond_C::foo' }
45 sub buz { 'Diamond_C::buz' }
46 sub woz { 'Diamond_C::woz' }
50 use base ('Diamond_B', 'Diamond_C');
52 sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
53 sub bar { 'Diamond_D::bar => ' . (shift)->next::method() }
54 sub buz { 'Diamond_D::buz => ' . (shift)->baz() }
55 sub fuz { 'Diamond_D::fuz => ' . (shift)->next::method() }
56 sub woz { 'Diamond_D::woz can => ' . (shift)->next::can() }
57 sub noz { 'Diamond_D::noz can => ' . (shift)->next::can() }
61 Class::C3::initialize();
64 [ Class::C3::calculateMRO('Diamond_D') ],
65 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
66 '... got the right MRO for Diamond_D');
68 is(Diamond_D->foo, 'Diamond_D::foo => Diamond_C::foo', '... skipped B and went to C correctly');
69 is(Diamond_D->bar, 'Diamond_D::bar => Diamond_A::bar', '... skipped B & C and went to A correctly');
70 is(Diamond_D->baz, 'Diamond_B::baz => Diamond_A::baz', '... called B method, skipped C and went to A correctly');
71 is(Diamond_D->buz, 'Diamond_D::buz => Diamond_B::baz => Diamond_A::baz', '... called D method dispatched to , different method correctly');
72 eval { Diamond_D->fuz };
73 like($@, qr/^No next::method 'fuz' found for Diamond_D/, '... cannot re-dispatch to a method which is not there');
75 is(Diamond_D->woz, 'Diamond_D::woz can => 1', '... can re-dispatch figured out correctly');
76 is(Diamond_D->noz, 'Diamond_D::noz can => 0', '... cannot re-dispatch figured out correctly');