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

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.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

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

Replies are listed 'Best First'.
Re^4: Using SUPER in dynamically generated subs
by clinton (Priest) on Nov 13, 2006 at 18:46 UTC
    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;