in reply to How do you use/create subroutine attributes?
Well, it all depends on what kind of magic you want to happen.
I am pretty sure that MODIFY_CODE_ATTRIBUTES will run in the BEGIN phase of the perl compiler. And the $code passed to you is usually a stub, and not the true subroutine that you will eventually have (however it's ref address will stay the same, so you can use that). What Catalyst does is to store the code-ref address along with the list of attributes it had for it, then when Catalyst is initialized (sometime during runtime presumably) it matches code-refs to attributes (using attribute::get() which calls FETCH_CODE_ATTRIBUTES) and does magic then. Attribute::Handlers does similar stuff, but it uses the INIT phase of the perl compiler to do it's dirty work.
In general subroutine attributes are an unwieldy beast with a really bad interface. They are especially tricky when it comes to CODE references. But then again, this is my experience, and your mileage may vary.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do you use/create subroutine attributes?
by xdg (Monsignor) on Mar 17, 2006 at 20:22 UTC |