Imagine a PracticalJoke class. It needs a non-lethal explode() from a Spouse role and a timed fuse() from a Bomb role. Unfortunately, each role provides the both methods. With Moose, this is trivial to resolve:
package PracticalJoke;
use Moose;
with 'Bomb' => { excludes => 'explode' };
'Spouse' => { excludes => 'fuse' };
How the heck do I do that with Perl 6? No matter how many times I read Synopsis 14, I can't figure out how that would work.
role Bomb {
method fuse () { say '3 .. 2 .. 1 ..' }
method explode () { say 'Rock falls. Everybody dies!' }
}
role Spouse {
method fuse () { sleep rand(20); say "Now!" }
method explode () { say 'You worthless piece of junk! Why I should ...' }
}
class PracticalJoke does Bomb does Spouse {
???
}
What have I missed?
Reading the Synopsis and the role conflict spectest doesn't suggest anything other than resolving it yourself:
class PracticalJoke does Bomb does Spouse {
method fuse() {
return self.Bomb::fuse();
}
method explode() {
return self.Spouse::explode();
}
}
Re:This type of divergence is worrying to me
moritz on 2009-07-07T16:16:25
Perl 5 is pluggable, and Moose is a great "external" improvement.
Perl 6 is (in the realm of object orientation without question) even better and more pluggable than Perl 5, and you wonder that the default isn't is as good isn't as good as Perl 5 with a bunch of the best modules available?
I think thats an understandable position, but don't forget that Perl 6 leaves room for improvement. It shouldn't be all that hard to write a module that allows additional syntax like
class Foo does SomeRole:except<methods you want ignored> { ... }
We know that we're not perfect, which is why we leave much room for modifications later on.