japhy has asked for the wisdom of the Perl Monks concerning the following question:
The base class (for these purposes) for a "quant" object is Rx::quant. If you write an add-on, MyRxA, then a MyRxA::quant object's @ISA is (Rx::quant). If you write an add-on, MyRxB, then a MyRxB::quant object's @ISA is (Rx::quant).
MyRxA::quant::raw() changes the output of all quantifiers to '%' characters; this means a+b would render as a%b.
MyRxB::quant::visual() makes the quantifier appear before the thing it quantifies; a+b would render as +ab.package MyRxA::quant; sub raw { my $self = shift; return "%"; }
package MyRxB::quant::visual; sub visual { my $self = shift; return $self->raw . $self->{data}->visual; }
Now we want to write MyRxC, which uses MyRxA and MyRxB as base classes. This means we want a+b to render as %ab. (Confusing? Sorry. Just bear with me.) The problem is that, because of the way @ISA is set up, an object of MyRxC::quant has the following inheritence tree:
I haven't considered the more difficult scenario of two classes overriding the same method.
I'm stuck. I'm not sure how to traverse the @ISA tree properly. I don't think NEXT has the right tools for the job. I kind of want an "OVER::", not a "NEXT::" or "SUPER::". It looks like I want a breadth-first @ISA scan, not a depth-first scan. What I really want is to avoid looking in Rx for the method until the VERY end. Maybe the solution, then, is not to put Rx in the @ISA tree, but rather to look in Rx after all others have failed, via AUTOLOAD?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple Inheritence, Munging @ISA
by Stevie-O (Friar) on Jul 07, 2004 at 00:20 UTC | |
|
Re: Multiple Inheritence, Munging @ISA
by dragonchild (Archbishop) on Jul 07, 2004 at 01:25 UTC | |
|
Re: Multiple Inheritence, Munging @ISA
by perrin (Chancellor) on Jul 07, 2004 at 03:04 UTC | |
|
Re: Multiple Inheritence, Munging @ISA
by cees (Curate) on Jul 07, 2004 at 01:35 UTC |