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.
--Stevie-O
$"=$,,$_=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

In reply to Re: Multiple Inheritence, Munging @ISA by Stevie-O
in thread Multiple Inheritence, Munging @ISA by japhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.