Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Multiple Inheritence, Munging @ISA

by Stevie-O (Friar)
on Jul 07, 2004 at 00:20 UTC ( #372232=note: print w/replies, xml ) Need Help??

in reply to Multiple Inheritence, Munging @ISA

You're missing part of the picture.

You're right -- any call to a method of a MyRxC::quant object will be dispatched to MyRxA::quant.

Since MyRxA::quant does not define the 'visual' method, its @ISA tree will recursively be searched. This is simply Rx::quant, from what I understand. If Rx::quant defines the 'visual' method, then the Rx::quant one is called instead. Otherwise, Rx::quant's @ISA is checked, depth first, for a 'visual' method.

If no 'visual' method is found in MyRxA::quant, then MyRxB::quant (the 2nd entry in @MyRxC::quant::ISA) is checked for 'visual'. Thus, the MyRxB::quant::visual() method will be called.

Now, if Rx::quant defines a 'visual' method (you didn't actually SAY this, but I have a sneaking suspicion that this is why you made your post), you will have to resolve the issue this way:

package MyRxC::quant; use base 'MyRxA::quant'; use base 'MyRxB::quant'; sub raw { my $this = shift; $this->MyRxA::quant::raw(@_); } sub visual { my $this = shift; $this->MyRxB::quant::visual(@_); }
Explicitly qualifying the package name in the method call will override the usual method lookup. The $this->SUPER::foo() syntax is actually a special case that automagically handles @ISA-ness.

Note that, if you are ONLY delegating and not adding any of your own code, *and* you KNOW for a fact that MyRxA and MyRxB respectively define 'raw' and 'visual' themselves (i.e. instead of inheriting them), a slightly faster technique may be used:

package MyRxC; *raw = \&MyRxA::quant::raw; *visual = \&MyRxB::quant::visual;
This would effectively import the 'raw' and 'visual' methods from the corresponding packages into MyRxC, bypassing the extra call induced with the "$this->MyRxA::quant::raw()" code. The tradeoff is that the former technique plays fine with inheritance, while this latter technique only works if MyRxA and MyRxB directly contain the 'raw' and 'visual' subs in their respective namespaces.
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://372232]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-10-19 22:37 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (258 votes). Check out past polls.