I see two problems. The small problem is that $AUTOLOAD contains the name of the class, so you have to strip that off first.

The big problem is that it appears the inheritance is working before AUTOLOAD gets a chance to run. One way around this, which is pretty ugly, is to avoid setting up the inheritence until AUTOLOAD is run. I'm not sure how workable this solution is, but at least it's something to chew on.

You can see this by changing AA.pm to:

package AA; require BB; sub AUTOLOAD { my ($self,$extrainfo,@args) = @_; local @ISA = 'BB'; my ($method) = (split /::/, $AUTOLOAD)[-1]; $superfunk = "SUPER::$method"; $self->$superfunk(@args); } 1;

Update: an alternative way to accomplish a similar goal, without using AUTOLOAD, would go something like this:

package AA; use base 'BB'; for my $meth (qw(print flop frizzle)) { *{ $meth } = sub { my ($self, $extra, @args) = @_; my $meth = "SUPER::$meth"; $self->$meth(@args); }; } 1;

Which just goes to show that AUTOLOAD is not the only way to dynamically create methods.


In reply to Re: AUTOLOAD and inheritance by revdiablo
in thread AUTOLOAD and inheritance by eXile

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.