in reply to Re: Using SUPER in dynamically generated subs
in thread Using SUPER in dynamically generated subs

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.

  • Comment on Re^2: Using SUPER in dynamically generated subs

Replies are listed 'Best First'.
Re^3: Using SUPER in dynamically generated subs
by diotalevi (Canon) on Nov 13, 2006 at 18:24 UTC

    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

        If you named your anonymous sub, you could use the SUPER module again, with something like:

        local *__ANON__ = $alias_for;