This works but we loose the CONTENT of $AUTOLOAD coming in Parent::AUTOLOAD.

Then why not just set it?

$Parent::AUTOLOAD = $AUTOLOAD; $self->Parent::AUTOLOAD(@_);
I do something similar to this when i make proxy classes in IOC::Proxy. The proxy class catches the AUTOLOAD and allows you to log it (or whatever you want your proxy to do) and then passes it to the actual object it is proxying.

Of course this way requires you to know what superclass you want to dispatch too. A more generic solution would involve going through the @ISA array and calling AUTOLOAD on each superclass (if they have an AUTOLOAD that is). The code might look something like this (note: this is highly untested)

if (we can do something) { ... } else { no strict 'refs'; foreach my $super (@{'${class}::ISA"}) { my $method; if ($method = $super->can('AUTOLOAD')) { ${"${super}::AUTOLOAD"} = $AUTOLOAD; return $class->$method(@_); } } }
Of course this would only go down one level of the tree, unless this code was included in the AUTOLOAD on each level of your object hierarchy. A recursive solution would start getting really hairy (as if this wasn't hairy enough).

But now I ask you, is all this really worth it to save a little bit of repetitive typing by hand-making getters and setters?

-stvn

In reply to Re: More then one AUTOLOAD in a class hierarchy. by stvn
in thread More then one AUTOLOAD in a class hierarchy. by ced

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.