Perl: the Markov chain saw | |
PerlMonks |
AUTOLOAD cascadeby shemp (Deacon) |
on Oct 13, 2004 at 16:15 UTC ( [id://398906]=perlquestion: print w/replies, xml ) | Need Help?? |
shemp has asked for the wisdom of the Perl Monks concerning the following question:
2 Updates (at the bottom) I have 2 classes, one inherits from the other, call them Parent and Child (Child inherits from Parent), and Parent has an AUTOLOAD method, and so does Child. The problem is that an instance of Child will never call Parent::AUTOLOAD, because of the call heirarchy. For instance: So, when i have an instance of Child, and call parent_method() on it, there is no parent_method() found in Child, then its not found in Parent, then its not found in UNIVERSAL. But then, Child::AUTOLOAD() is found, and is invoked. But that AUTOLOAD doesnt know about parent_method(), so does nothing, and Parent::AUTOLOAD() is not invoked. To get around this, im thinking i should add a line to the end of Child::AUTOLOAD() like this: Is this the proper way to do this, or am i missing something obvious? Thanks much, as always. Update: I found that i need to modify Parent::AUTOLOAD() too, so im thinking there is a better way than this, but heres the parent modification: This had to be done because $Parent::AUTOLOAD is not set like for a normal call to AUTOLOAD, so i had to do something to get Parent::AUTOLOAD() to know what method to use.
Update 2: The only thing about this one is that Perl will search through Parent and its parents, before calling Parent::AUTOLOAD(), which is a little more time consuming, but i am going to have the AUTOLOADS screw with the symbol tables and install AUTOLOAD'ed methods after their first invocation, which will speed things up.
Back to
Seekers of Perl Wisdom
|
|