Commit | Line | Data |
---|---|---|
204e6232 BF |
1 | #!./perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use utf8; | |
6 | use open qw( :utf8 :std ); | |
7 | ||
8 | require q(./test.pl); plan(tests => 10); | |
9 | ||
10 | =pod | |
11 | ||
12 | This example is take from: http://www.python.org/2.3/mro.html | |
13 | ||
14 | "My first example" | |
15 | class O: pass | |
16 | class F(O): pass | |
17 | class E(O): pass | |
18 | class D(O): pass | |
19 | class C(D,F): pass | |
20 | class B(D,E): pass | |
21 | class A(B,C): pass | |
22 | ||
23 | ||
24 | 6 | |
25 | --- | |
26 | Level 3 | O | (more general) | |
27 | / --- \ | |
28 | / | \ | | |
29 | / | \ | | |
30 | / | \ | | |
31 | --- --- --- | | |
32 | Level 2 3 | D | 4| E | | F | 5 | | |
33 | --- --- --- | | |
34 | \ \ _ / | | | |
35 | \ / \ _ | | | |
36 | \ / \ | | | |
37 | --- --- | | |
38 | Level 1 1 | B | | C | 2 | | |
39 | --- --- | | |
40 | \ / | | |
41 | \ / \ / | |
42 | --- | |
43 | Level 0 0 | A | (more specialized) | |
44 | --- | |
45 | ||
46 | =cut | |
47 | ||
48 | { | |
49 | package 텟ţ::ᴼ; | |
50 | use mro 'c3'; | |
51 | ||
52 | package 텟ţ::Ḟ; | |
53 | use mro 'c3'; | |
54 | use base '텟ţ::ᴼ'; | |
55 | ||
56 | package 텟ţ::ऍ; | |
57 | use base '텟ţ::ᴼ'; | |
58 | use mro 'c3'; | |
59 | ||
60 | sub ƈ_or_ऍ { '텟ţ::ऍ' } | |
61 | ||
62 | package 텟ţ::Ḋ; | |
63 | use mro 'c3'; | |
64 | use base '텟ţ::ᴼ'; | |
65 | ||
66 | sub ƈ_or_Ḋ { '텟ţ::Ḋ' } | |
67 | ||
68 | package 텟ţ::ƈ; | |
69 | use base ('텟ţ::Ḋ', '텟ţ::Ḟ'); | |
70 | use mro 'c3'; | |
71 | ||
72 | sub ƈ_or_Ḋ { '텟ţ::ƈ' } | |
73 | sub ƈ_or_ऍ { '텟ţ::ƈ' } | |
74 | ||
75 | package 텟ţ::ᛒ; | |
76 | use mro 'c3'; | |
77 | use base ('텟ţ::Ḋ', '텟ţ::ऍ'); | |
78 | ||
79 | package 텟ţ::ଅ; | |
80 | use base ('텟ţ::ᛒ', '텟ţ::ƈ'); | |
81 | use mro 'c3'; | |
82 | } | |
83 | ||
84 | ok(eq_array( | |
85 | mro::get_linear_isa('텟ţ::Ḟ'), | |
86 | [ qw(텟ţ::Ḟ 텟ţ::ᴼ) ] | |
87 | ), '... got the right MRO for 텟ţ::Ḟ'); | |
88 | ||
89 | ok(eq_array( | |
90 | mro::get_linear_isa('텟ţ::ऍ'), | |
91 | [ qw(텟ţ::ऍ 텟ţ::ᴼ) ] | |
92 | ), '... got the right MRO for 텟ţ::ऍ'); | |
93 | ||
94 | ok(eq_array( | |
95 | mro::get_linear_isa('텟ţ::Ḋ'), | |
96 | [ qw(텟ţ::Ḋ 텟ţ::ᴼ) ] | |
97 | ), '... got the right MRO for 텟ţ::Ḋ'); | |
98 | ||
99 | ok(eq_array( | |
100 | mro::get_linear_isa('텟ţ::ƈ'), | |
101 | [ qw(텟ţ::ƈ 텟ţ::Ḋ 텟ţ::Ḟ 텟ţ::ᴼ) ] | |
102 | ), '... got the right MRO for 텟ţ::ƈ'); | |
103 | ||
104 | ok(eq_array( | |
105 | mro::get_linear_isa('텟ţ::ᛒ'), | |
106 | [ qw(텟ţ::ᛒ 텟ţ::Ḋ 텟ţ::ऍ 텟ţ::ᴼ) ] | |
107 | ), '... got the right MRO for 텟ţ::ᛒ'); | |
108 | ||
109 | ok(eq_array( | |
110 | mro::get_linear_isa('텟ţ::ଅ'), | |
111 | [ qw(텟ţ::ଅ 텟ţ::ᛒ 텟ţ::ƈ 텟ţ::Ḋ 텟ţ::ऍ 텟ţ::Ḟ 텟ţ::ᴼ) ] | |
112 | ), '... got the right MRO for 텟ţ::ଅ'); | |
113 | ||
114 | is(텟ţ::ଅ->ƈ_or_Ḋ, '텟ţ::ƈ', '... got the expected method output'); | |
115 | is(텟ţ::ଅ->can('ƈ_or_Ḋ')->(), '텟ţ::ƈ', '... can got the expected method output'); | |
116 | is(텟ţ::ଅ->ƈ_or_ऍ, '텟ţ::ƈ', '... got the expected method output'); | |
117 | is(텟ţ::ଅ->can('ƈ_or_ऍ')->(), '텟ţ::ƈ', '... can got the expected method output'); |