Have you tried printing ^mro of $best_friend? You would be surprised! Instead, 
try compiling the following:

     role R1 {
         method !priv { say "R1::priv" }
     }
     role R2 {
         method !priv { say "R2::priv" }
     }
     class Foo does R1 does R2 {
     }

Oops.... And this I consider a major problem. I as a developer must not care 
about private methods of third-party modules. But I would have to! That's why I 
want roles to be something more than mere collection of entitites mixed into a 
class.

> On Jan 30, 2019, at 1:47 AM, yary <not....@gmail.com> wrote:
> 
> > Yet, have a look at my example with private methods
> 
> All of the bug reports, code excerts use regular (public) methods. Do you 
> have code to share with !private_methods and/or submethods? I just made an 
> example, will be at the end of this email
> 
> > If accidentally two roles declare same private method – I either must 
> > reject using one of them or resolve the conflict manually ...
> 
> The docs say what to do if two roles declare the same regular method. I would 
> expect the same to hold for private methods, and submethods- the consuming 
> class would need to define its own same-named submethod or private method, 
> calling the whichever role routine(s) it needs.
> 
> it sounds like you'd like to have a role be able to declare some routines 
> which only other methods in the role can use- not the consuming class, or any 
> other role. Turns out that private methods in roles do the trick!
> 
> use v6;
> 
> # Turn anything into a public entertainer
> role Diva {
>   method captivate (&talent) {
>     say "tais toi!";
>       self.&talent;
>       self!bow;
>   }
> 
>   method !bow {
>     say "<takes a bow>"
>   }
> }
> 
> 
> # Learn to play
> role Violinist {
>   method fiddle {
>     say "got sheet music, got rosin...";
>       self!bow;
>   }
> 
>   method !bow {
>     say "<world's most beautiful melodies>"
>   }
> }
> 
> 
> # cute and playful
> class Puppy {
>   method greet {
>    say "<sniff>";
>    self!bow;
>   }
> 
>   method !bow {
>     say "Bow wow wow!"
>   }
> }
> 
> my $best_friend=(Puppy.new but Violinist) but Diva;
> $best_friend.greet;
> $best_friend.captivate($best_friend.^lookup('fiddle'));
> 
> says
> <sniff>
> Bow wow wow!
> tais toi!
> got sheet music, got rosin...
> <world's most beautiful melodies>
> <takes a bow>
> 
> I'm very happy with that behavior. Would like it to be documented.
> 
> (And, I'll add comments to your bug tickets now)
> -y

Best regards,
Vadim Belman

Reply via email to