I was thinking about this a little over the weekend, and I realized why SUPER needs to check the current package's @ISA, instead of the package into which the object is blessed. It's to handle the case where the super-method also uses SUPER. If it just used the @ISA of the package the object was blessed into, SUPER in a super-method would start over at the bottom (top?) of the inheritance tree. So it has to use the current package, which is also the current position in the inheritance tree, except for the one case that you happened to run into. Anyway, that's the "why" of it.

I also realised that it's probably a bit more efficient to do the eval once, when creating the anonymous sub, instead of every time it's called (although it may be a case of premature optimization... I'm not entirely certain). Like so:

$methods{$_} = eval qq( package $caller; sub { my \$self = shift; # #print "installing $method_name() in $caller...\n"; # # Without \$caller and eval, the following line causes this error: # # Can't locate auto/CustomMethodMaker/SUPER/[METHOD].al in \@INC # my \@parent_slots; if ( \$self->can( SUPER::$method_name ) ) { \@parent_slots = \$self->SUPER::$method_name( \@_ ); } return ( \@parent_slots, \@slots ); } ); die $@ if $@;

Just thought I'd share those, for completeness.

bbfu
Black flowers blossom
Fearless on my breath


In reply to Re9: Calling SUPER in MethodMaker-generated methods by bbfu
in thread Calling SUPER in MethodMaker-generated methods by danb

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.