This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Small optimisations, by Brandon Black
[perl5.git] / t / mro / basic_05_c3.t
CommitLineData
e1a479c5
BB
1#!./perl
2
3use strict;
4use warnings;
5BEGIN {
6 unless (-d 'blib') {
7 chdir 't' if -d 't';
8 @INC = '../lib';
9 }
10}
11
12use Test::More tests => 2;
13
14=pod
15
16This tests a strange bug found by Matt S. Trout
17while building DBIx::Class. Thanks Matt!!!!
18
19 <A>
20 / \
21<C> <B>
22 \ /
23 <D>
24
25=cut
26
27{
28 package Diamond_A;
29 use mro 'c3';
30
31 sub foo { 'Diamond_A::foo' }
32}
33{
34 package Diamond_B;
35 use base 'Diamond_A';
36 use mro 'c3';
37
38 sub foo { 'Diamond_B::foo => ' . (shift)->SUPER::foo }
39}
40{
41 package Diamond_C;
42 use mro 'c3';
43 use base 'Diamond_A';
44
45}
46{
47 package Diamond_D;
48 use base ('Diamond_C', 'Diamond_B');
49 use mro 'c3';
50
51 sub foo { 'Diamond_D::foo => ' . (shift)->SUPER::foo }
52}
53
54is_deeply(
55 mro::get_linear_isa('Diamond_D'),
56 [ qw(Diamond_D Diamond_C Diamond_B Diamond_A) ],
57 '... got the right MRO for Diamond_D');
58
59is(Diamond_D->foo,
60 'Diamond_D::foo => Diamond_B::foo => Diamond_A::foo',
61 '... got the right next::method dispatch path');