develooper Front page | perl.perl6.language | Postings from January 2004

Re: Roles and Mix-ins?

Thread Previous
Jonathan Lang
January 6, 2004 20:44
Re: Roles and Mix-ins?
Message ID:
Joe Gottman wrote:
> Luke Palmer wrote:
> > Your renaming can be done easily enough, and more clearly (IMO) with:
> >
> >   class Trog
> >     does Dog does Tree {
> >       method bark() { ... }   # Explicitly remove the provided method
> >       method dogBark()  { .Dog::bark() }
> >       method treeBark() { .Tree::bark() }
> >   }
>    But won't explicitly removing bark() from the class also disable
> Dog::bark() and Tree::bark() for the class?  

No.  method bark isn't technically being removed; rather, method
Trog::bark is being defined as "postpone the definition" while
simultaneously taking precedence over both Dog::bark and Tree::bark, since
it is a class method native to Trog while the others are role methods
provided to Trog - and class methods take precedence over role methods. 
So if "my Trog $spot; $spot.bark;" is executed, perl will unambiguously
call $spot.Trog::bark, and then complain that it hasn't been defined. 
(This assumes that it doesn't complain during compile-time.)

This works, but seems counterintuitive to me.  

Jonathan "Dataweaver" Lang

Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About