/
lastcall.t
54 lines (45 loc) 路 1.48 KB
/
lastcall.t
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
use v6;
use Test;
plan 6;
# L<S12/"Calling sets of methods"/"It is also possible to trim the candidate list so that the current call is considered the final candidate.">
class Foo {
# $.tracker is used to determine the order of calls.
has $.tracker is rw;
method doit($foo) { $.tracker ~= 'foo,' }
method show {$.tracker}
method clear {$.tracker = ''}
}
class BazLastCallNext is Foo {
multi method doit($foo) { $.tracker ~= 'baz,'; nextsame; }
multi method doit(Int $foo) {
$.tracker ~= 'bazint,';
if 1 { lastcall }
nextsame;
$.tracker ~= 'ret3,';
}
}
{
my $o = BazLastCallNext.new;
$o.clear;
$o.doit("");
is($o.show, 'baz,foo,', 'no lastcall, so we defer up the inheritance tree');
$o.clear;
is($o.show, '', 'sanity test for clearing');
$o.doit(5);
is($o.show, 'bazint,ret3,', 'lastcall meant nextsame failed, no deferal happened');
}
class BarLastCallSame is Foo {
multi method doit($foo) {$.tracker ~= 'bar,'; lastcall; callsame; $.tracker ~= 'ret1,'}
multi method doit(Int $num) {$.tracker ~= 'barint,'; callsame; $.tracker ~= 'ret2,'}
}
{
my $o = BarLastCallSame.new;
$o.clear;
$o.doit("");
is($o.show, 'bar,ret1,', 'lastcall trims candidate list, so no call up inheritance tree');
$o.clear;
is($o.show, '', 'sanity test for clearing');
$o.doit(5);
is($o.show, 'barint,bar,ret1,ret2,', 'lastcall trimming does not affect stuff earlier in chain');
}
# vim: ft=perl6