[tpm] private method call nuances

John Macdonald john at perlwolf.com
Tue Jul 21 07:58:29 PDT 2009


On Mon, Jul 20, 2009 at 11:17:24PM -0400, Michael Graham wrote:
> 
> > Can you explain, or point me somewhere to better understand, how 
> > inheritance breaks using the '&' method? Also, I was a little
> > unclear... if you pass in '$self', does that restore the inheritance?
> > I just want to be clear so that I can best explain it in my paper.
> 
> If you call: 
>     
>     foo($thingy);
> 
> you're calling the "foo" sub in the current package.
> 
> If you call:
> 
>     $thingy->foo;
> 
> you're saying:  
> 
>     - Find the package that $thingy is blessed into.
>     - If there's a "foo" sub in that package, run it.  
>       Otherwise, walk the inheritance tree of that package, and run the
>       first "foo" sub found.

So, what breaks when you use the sub call is not the inheritance
relation to classes above the current class in which you make the
call.

Instead you lose the ability to create sub-classes that have their
own version of the "method" that you are calling as a sub unless
they also have their own version of the methof that invokes the
sub.  So, it is inheritance by other classes *from* your current
class that is being compromised.


More information about the toronto-pm mailing list