saintmike has asked for the wisdom of the Perl Monks concerning the following question:
This will print "Before" every time somefunc will be called. Now, what I'd like to do is create a Module, say MyAttrMaker that would accomplish the above like this:use Attribute::Handlers; sub myattr :ATTR { my($func, $symbol, $code) = @_; no warnings 'redefine'; *{$symbol} = sub { print "Before\n"; $code->(); } } sub somefunc :myattr { print "somefunc!\n"; } somefunc();
For this to work, MyAttrMaker would have an import() function, which would use Attribute::Handlers and define sub myattr :ATTR {.use MyAttrMaker qw(myattr); sub somefunc :myattr { print "somefunc!\n"; } somefunc();
However, due to Attribute::Handler creating these hooks in the CHECK phase (other phases can be selected, too), this doesn't seem to be possible. Or is it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Attribute::Handlers usage at runtime
by liz (Monsignor) on Jun 13, 2004 at 09:22 UTC | |
|
Re: Attribute::Handlers usage at runtime
by Anonymous Monk on Jun 13, 2004 at 14:33 UTC |