I am pretty sure (but not positive) the answer is:
No, this cant be done.
Calling AUTOLOAD before your parent functions sort of
defeats the purpose of inheritance. If this were the case, a parent
function would never get called because the AUTOLOAD would get
called first. AUTOLOAD is a last
ditch effort when *all* else fails, so if perl cannot find
the function in the class or anywhere in chain of parents it
will call the first AUTOLOAD it finds.
I would recommend just moving the AUTOLOAD to the parent. Or not give the class a parent if you think
the class needs to have an AUTOLOAD function.
Another idea is instead of total inheritance
you can do cheesy selective pseudo-inheritance, ie only grab the functions you
want like:
package B;
*new = \&A::new;
sub AUTOLOAD {
print "autoload in B, called as $AUTOLOAD\n";
}
So now your main will do what you want. I have just
made &A::new synonomous with &B::new in the symbol table so you only
have to maintain one new function. I dont this this would be
too much work to just alias the symbols for each function that
you want.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.