Perl 6 Roles Question

Ovid on 2009-07-07T10:31:45

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?


spectests sugggest manual resolution

fireartist on 2009-07-07T12:26:25

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();
    }
}

This type of divergence is worrying to me

jjn1056 on 2009-07-07T12:59:04

Before Moose, Perl6 was the great hope to fix a lot of the ugliness with Perl's OO. Perl 6 was like Perl 5 but more. However with all the community effort going into Moose and related MooseX stuff, I'm concerned that a lot of the great ideas in Perl6 are going to always remain too fair behind. It's starting to seem like Perl6 is like Perl5 but different. I wonder if there's some way to increase the communication between the Moose group and the people doing OO Perl6 stuff. There's a lot of little things like the one you have described that just might not be something you realize you need until you are actually building production code.

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.