Giving a talk about roles at YAPC::EU in Lisbon and I'm a bit stuck on how to 
translate a Perl 5 example into Perl 6.  Basically, Imagine a "PracticalJoke" 
class which has fuse() and explode methods().  It needs the timed fuse() from a 
Bomb role and a non-lethal explode() from a Spouse role, though each role 
provides both methods.  In Moose, it's easy:

  package PracticalJoke;
  use Moose;
  with 'Bomb'   => { excludes => 'explode' };
       'Spouse' => { excludes => 'fuse' };

Try as I might, I can't figure out how to translate that into Perl 6.  I have 
the following:

  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 {

Nothing I see in S14 ( seems to cover this 
case. I can't declare them as multis as they have the same signature.  There's 
a note that one can "simply to write a class method that overrides the 
conflicting role methods, perhaps figuring out which role method to call", but 
I don't understand how a particular role's methods would be called here.

Buy the book         -
Tech blog            -
Twitter              -
Official Perl 6 Wiki -

Reply via email to