Brandon S. Allbery KF8NH wrote:
On Jul 7, 2009, at 07:34 , Jonathan Worthington wrote:
Jon Lang wrote:
I believe that the official word is to say:
class PracticalJoke does Bomb does Spouse {
method fuse () { Bomb::fuse }
method explode () { Spouse::explode }
}
This way won't work, because:
* It's doing a sub call to something that's a method
* The lookup won't work unless the method has "our" (package) scope *
* Even in that case, the invocant isn't being passed so you'll get a
"wrong number of parameters" error
I was trying to figure out how to do it with nextsame, but that's not
looking very simple.
Interesting thought, but the problem is that:
role R { method a() { }; method b() { } }
class C does R { method b() { } }
In this case, method b from the role never gets composed into the class,
thanks to the method b in the class. (This is the flattening aspect of
role composition at work). In fact, the composed method behaves pretty
much as if it had been defined in the class itself. So the method b in
the role doesn't exist in the candidate list that we walk when doing
deference. From Rakudo:
> role R { method a() { }; method b() { } }
> class C does R { method b() { } }
> say C.WALK(:name<b>).elems
1
On the other hand, if they were multis then they get added to the multi
candidate list and therefore you can nextsame into them. Again from Rakudo:
> role R { multi method b() { say "lol in role" } }
> class C does R { multi method b() { say "oh hai in class"; nextsame } }
> C.new.b
oh hai in class
lol in role
And role ones beat parents in the ordering too...
> role R { multi method b() { say "lol in role"; nextsame } }
> class P { method b() { say "parent ftw" } }
> class C is P does R { multi method b() { say "oh hai in class";
nextsame } }
> C.new.b
oh hai in class
lol in role
parent ftw
(Note to the bored: feel free to beat me to adding something like these
last two to the spectests...I'm away for the afternoon/evening.)
Thanks,
Jonathan