in reply to Re^2: Trying to figure out subroutine attributes
in thread Trying to figure out subroutine attributes
This says "for the attribute xmlrpc, do nothing". The code attached to the ATTR(CODE) is to be run at the time the code with that attribute is compiled. You have an empty block, so Perl does that: nothing at all.sub xmlrpc :ATTR(CODE) {}
The toughest part about using Attribute::Handlers is remembering that the attribute code gets control at compile time, and that the only way to influence execution later is to record information at that point.
Note that friedo's code is recording information in a hash in the sub xmlrpc: ATTR(CODE) subroutine, and the xmlrpc_methods sub then just reads it off. If you look at Class::AutoPlug::Plugin, you can see an example of using a similar mechanism to "advertise" methods and method hooks.
[I just noticed a documentation bug I have to fix there - the hooks actually get and send back a Class::AutoPlug::ResultState, instead of magical numeric values, wich allows the hooks to manipulate @_ and to replace the real return value for a method. However, this is unrelated to the attribute-based "advertising"; check out the source for the details on how that works. I'll be pushing another version with the doc corrections this evening.]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Trying to figure out subroutine attributes
by Anonymous Monk on Dec 11, 2006 at 15:37 UTC | |
by pemungkah (Priest) on Dec 11, 2006 at 19:54 UTC |