lestrrat has asked for the wisdom of the Perl Monks concerning the following question:
I basically want to put a wrapper around a function when it's declared with a particular attribute. This would normally be easy, because when the handler is run, you get a reference to the symbol, so you can do this:
sub myhandler : ATTR(CODE) { my($pkg, $symbol, $referent....) = @_; ... *{$symbol} = sub { # additional code goto &$referent; } }
However, the script(s) that uses the attribute is called from do(). That means that the CHECK and INIT blocks are not run. I tried changing the handler to be invoked at BEGIN time, but the problem there is that the $symbol is a string that says "ANON". So I have no where I can assign the newly generate sub.
Does anybody know a way to workaround this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to redefine subroutines with Attribute::Handlers that run at BEGIN time?
by tilly (Archbishop) on Oct 05, 2003 at 17:52 UTC | |
|
Re: How to redefine subroutines with Attribute::Handlers that run at BEGIN time?
by Juerd (Abbot) on Oct 15, 2003 at 06:52 UTC |