in reply to tracing SUPER

How about (untested):

sub validate { my $self = shift; # do validation print STDERR "it is going to call $ISA[0] :: validate\n"; return $self->SUPER::validate(@_); }

You should be able to see the Class name in the error log.

Replies are listed 'Best First'.
Re^2: tracing SUPER
by gaal (Parson) on Jul 28, 2004 at 18:08 UTC
    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 :-)

      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
Re^2: tracing SUPER
by Ranger Rick (Novice) on Jul 28, 2004 at 18:43 UTC
    I may be confused about how delegation works, now that I think about it more. When something has @ISA = qw(Foo::Bar), the only thing it checks other than itself is Foo::Bar? Or does it look for anything else that isa(Foo::Bar) and call the method there as well? If that's the case, then I think it's failing altogether; We have a bunch of code that @ISA = qw(Foo::Bar) but there is no Foo/Bar.pm; it's just a convenience. If that is the case (you use SUPER, but one of your @ISA's doesn't exist), does it return a false value?
      Inheritance goes one way: up. If B and C are both As, and C->meth is called but C doesn't define a meth, B will certainly not be called! Why should it; after all, C is not a B.

      But you say you have "a bunch of code that @ISA = qw(Foo::Bar) but there is no Foo/Bar.pm; it's just a convenience". Convenience for what? It's wrong semantically to inherit from something that doesn't exist.

      Note that not having a file Foo/Bar.pm is perfectl all right: Foo::Bar may be defined in another file, or created on the fly at run time. So long that it is compiled before you call any of its methods, you are syntactically safe. You'd better make sure it finishes compiling before its subclasses are defined too, unless you know what you're doing (== funky dynamic stuff)