class A {}
class A_ is A {}
class B {
multi method f(A $) {
say 'B: hi A';
}
multi method f(A_ $) {
say 'B: hi A_';
nextsame;
}
}
# using redispatching
class C is B {
multi method f(A $) {
say 'C: hi A';
nextsame;
}
multi method f(A_ $) {
say 'C: hi A_';
nextsame;
}
}
C.f(A_);
say();
# using super
class SuperDelegator {
has $!object is built;
has %!super-methods = $!object.^mro[1].^method_table;
method FALLBACK($name, |c) {
%!super-methods{$name}($!object, |c);
}
}
sub super($o) {
SuperDelegator.new(object => $o);
}
class D is B {
multi method f(A $a) {
say 'D: hi A';
super(self).f($a);
}
multi method f(A_ $a) {
say 'D: hi A_';
super(self).f($a);
}
}
D.f(A_);