6 use Test::More tests => 10;
10 This tests the classic diamond inheritence pattern.
23 sub bar { 'Diamond_A::bar' }
24 sub baz { 'Diamond_A::baz' }
30 sub baz { 'Diamond_B::baz => ' . (shift)->next::method() }
36 sub foo { 'Diamond_C::foo' }
37 sub buz { 'Diamond_C::buz' }
39 sub woz { 'Diamond_C::woz' }
40 sub maybe { 'Diamond_C::maybe' }
44 use base ('Diamond_B', 'Diamond_C');
46 sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
47 sub bar { 'Diamond_D::bar => ' . (shift)->next::method() }
48 sub buz { 'Diamond_D::buz => ' . (shift)->baz() }
49 sub fuz { 'Diamond_D::fuz => ' . (shift)->next::method() }
51 sub woz { 'Diamond_D::woz can => ' . ((shift)->next::can() ? 1 : 0) }
52 sub noz { 'Diamond_D::noz can => ' . ((shift)->next::can() ? 1 : 0) }
54 sub maybe { 'Diamond_D::maybe => ' . ((shift)->maybe::next::method() || 0) }
55 sub moybe { 'Diamond_D::moybe => ' . ((shift)->maybe::next::method() || 0) }
60 mro::get_linear_isa('Diamond_D'),
61 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
62 '... got the right MRO for Diamond_D');
64 is(Diamond_D->foo, 'Diamond_D::foo => Diamond_C::foo', '... skipped B and went to C correctly');
65 is(Diamond_D->bar, 'Diamond_D::bar => Diamond_A::bar', '... skipped B & C and went to A correctly');
66 is(Diamond_D->baz, 'Diamond_B::baz => Diamond_A::baz', '... called B method, skipped C and went to A correctly');
67 is(Diamond_D->buz, 'Diamond_D::buz => Diamond_B::baz => Diamond_A::baz', '... called D method dispatched to , different method correctly');
68 eval { Diamond_D->fuz };
69 like($@, qr/^No next::method 'fuz' found for Diamond_D/, '... cannot re-dispatch to a method which is not there');
71 is(Diamond_D->woz, 'Diamond_D::woz can => 1', '... can re-dispatch figured out correctly');
72 is(Diamond_D->noz, 'Diamond_D::noz can => 0', '... cannot re-dispatch figured out correctly');
74 is(Diamond_D->maybe, 'Diamond_D::maybe => Diamond_C::maybe', '... redispatched D to C when it exists');
75 is(Diamond_D->moybe, 'Diamond_D::moybe => 0', '... quietly failed redispatch from D');