Perl-Sensitive Sunglasses | |
PerlMonks |
Using SUPER in dynamically generated subsby clinton (Priest) |
on Nov 13, 2006 at 17:16 UTC ( [id://583762]=perlmeditation: print w/replies, xml ) | Need Help?? |
I was trying to generate a sub which relied on the deep binding of a lexical variable, and tried to call $self->SUPER::method() as well:
The problem with this, is that SUPER refers to the @ISA of the class it is COMPILED into, not the class of $self at runtime. (See Overridden Methods) So my other option was doing this:
...but this wouldn't work either, because then $alias for wouldn't be defined, and I'm relying on the deep binding of lexical variables to have $alias_for defined. UPDATE See Re^4: Using SUPER in dynamically generated subs for correct usage of SUPER with an anonymous sub
The can() method, called against that object or class, reports back whether its string argument is a callable method name in that class. In fact, it gives you back a function reference to that method So this is my final code, which works:
It works for me. Is there a better way? Anything I'm missing? CAVEAT This will not take notice of any changes to @ISA after this sub has been defined. UPDATE See Re^6: Using SUPER in dynamically generated subs for benchmarks comparing the three methods mentioned in this thread.
Back to
Meditations
|
|