1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#!./perl
use strict;
use warnings;
use utf8;
use open qw( :utf8 :std );
require q(./test.pl); plan(tests => 4);
=pod
This example is take from: http://www.python.org/2.3/mro.html
"My second example"
class O: pass
class F(O): pass
class E(O): pass
class D(O): pass
class C(D,F): pass
class B(E,D): pass
class A(B,C): pass
6
---
Level 3 | O |
/ --- \
/ | \
/ | \
/ | \
--- --- ---
Level 2 2 | E | 4 | D | | F | 5
--- --- ---
\ / \ /
\ / \ /
\ / \ /
--- ---
Level 1 1 | B | | C | 3
--- ---
\ /
\ /
---
Level 0 0 | A |
---
>>> A.mro()
(<class '__main__.A'>, <class '__main__.B'>, <class '__main__.E'>,
<class '__main__.C'>, <class '__main__.D'>, <class '__main__.F'>,
<type 'object'>)
=cut
{
package 텟ţ::ᴼ;
use mro 'dfs';
sub ᴼ_or_Ḋ { '텟ţ::ᴼ' }
sub ᴼ_or_Ḟ { '텟ţ::ᴼ' }
package 텟ţ::Ḟ;
use base '텟ţ::ᴼ';
use mro 'dfs';
sub ᴼ_or_Ḟ { '텟ţ::Ḟ' }
package 텟ţ::ऍ;
use base '텟ţ::ᴼ';
use mro 'dfs';
package 텟ţ::Ḋ;
use base '텟ţ::ᴼ';
use mro 'dfs';
sub ᴼ_or_Ḋ { '텟ţ::Ḋ' }
sub ƈ_or_Ḋ { '텟ţ::Ḋ' }
package 텟ţ::ƈ;
use base ('텟ţ::Ḋ', '텟ţ::Ḟ');
use mro 'dfs';
sub ƈ_or_Ḋ { '텟ţ::ƈ' }
package 텟ţ::ᛒ;
use base ('텟ţ::ऍ', '텟ţ::Ḋ');
use mro 'dfs';
package 텟ţ::ଅ;
use base ('텟ţ::ᛒ', '텟ţ::ƈ');
use mro 'dfs';
}
ok(eq_array(
mro::get_linear_isa('텟ţ::ଅ'),
[ qw(텟ţ::ଅ 텟ţ::ᛒ 텟ţ::ऍ 텟ţ::ᴼ 텟ţ::Ḋ 텟ţ::ƈ 텟ţ::Ḟ) ]
), '... got the right MRO for 텟ţ::ଅ');
is(텟ţ::ଅ->ᴼ_or_Ḋ, '텟ţ::ᴼ', '... got the right method dispatch');
is(텟ţ::ଅ->ᴼ_or_Ḟ, '텟ţ::ᴼ', '... got the right method dispatch');
# NOTE:
# this test is particularly interesting because the p5 dispatch
# would actually call 텟ţ::Ḋ before 텟ţ::ƈ and 텟ţ::Ḋ is a
# subclass of 텟ţ::ƈ
is(텟ţ::ଅ->ƈ_or_Ḋ, '텟ţ::Ḋ', '... got the right method dispatch');
|