in reply to Using SUPER in dynamically generated subs

You are wrong. The SUPER module on CPAN does not depend on what package was used at compile time. That is the point to the module. The SUPER module is not the same thing as SUPER:: that is listed in your perl documentation. You can't read perlobj (and related) and know what SUPER does.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

  • Comment on Re: Using SUPER in dynamically generated subs

Replies are listed 'Best First'.
Re^2: Using SUPER in dynamically generated subs
by clinton (Priest) on Nov 13, 2006 at 17:24 UTC
    According to the docs for SUPER:

    Note: you must have the appropriate package declaration in place for this to work. That is, you must have compiled the method in which you use this function in the package from which you want to use it. Them's the breaks with Perl 5.

    And when i tried it, it didn't work.

      There is more than one way to use SUPER than the super() function. super() happens to be nice to look at but does suffer from that drawback. Use the $self->SUPER and $self->super methods instead. Those *don't* suffer from that problem.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        You're absolutely right - I misread the error message. The problem was not that it didn't look at the right @ISA but that I was using an anonymous sub.

        When I called it like this:

        my ($class,$alias_for) = @_; install_sub( $class, 'find_ids', sub { my ($class,$params) = @_; do_something_with($alias_for); # Pass the subname to super, because # this is an anonymous sub my $super = $class->super('find_ids'); return $super->($class,$params); }); ....

        ... then it works perfectly. And when I benchmarked the overhead of using SUPER, there was only a 1% slowdown.

        . Thanks Diotalevi

        UPDATE My benchmark was wrong. See Re^6: Using SUPER in dynamically generated subs for correct benchmarks