On Tue, Jul 7, 2009 at 2:48 AM,
Ovid<publiustemp-perl6langua...@yahoo.com> wrote:
>
> 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 (http://perlcabal.org/syn/S14.html) 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.
>

I believe that the official word is to say:

  class PracticalJoke does Bomb does Spouse {
    method fuse () { Bomb::fuse }
    method explode () { Spouse::explode }
  }

Personally, I agree that some sort of ability to exclude individual
methods from Roles, such as what Moose does, would be beneficial; but
this is an old argument that has been hashed out many times before.

-- 
Jonathan "Dataweaver" Lang

Reply via email to