in reply to Re: tracing SUPER
in thread tracing SUPER

Hmmm, that probably won't help much, because presumably the class knows who its direct ancestor is. It gets tricky with multiple inheritance and/or deep inheritance hierarchies, where it's just plain hard to tell from a casual glance who the next method is. Note how in this case there's no guarantee $ISA[0] ."::validate" exists.

If you want to do that kind of analysis, though, the code in NEXT.pm might provide inspiration. Or deterrence :-)

Replies are listed 'Best First'.
Re^3: tracing SUPER
by fglock (Vicar) on Jul 28, 2004 at 18:19 UTC

    It's not that complicated. The "Perl Cookbook" says:

    Note that SUPER only works on the first overridden method. If your @ISA array has several classes, it only gets the first one.

      This sounds fishy to me! Could it be that the Cookbook means that SUPER stops at the first match?

      I had to test, and it appears to be the case:

      #!/usr/bin/perl -w package A; sub new { bless {}, shift } package B; sub new { bless {}, shift } sub blarf { print "B::blarf\n" } package C; @ISA = qw/A B/; sub blarf { my($self) = @_; print "C::blarf\n"; $self->SUPER::blarf; } package main; C->new->blarf; __END__ % perl ~/super.pl C::blarf B::blarf