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

Re: Roles and Mix-ins?

Thread Previous
From:
Jonathan Lang
Date:
January 6, 2004 20:44
Subject:
Re: Roles and Mix-ins?
Message ID:
20040107044432.14040.qmail@web40812.mail.yahoo.com
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
http://hotjobs.sweepstakes.yahoo.com/signingbonus

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About