Problems? Is your data what you think it is? | |
PerlMonks |
RFC: Perl meta programmingby bennymack (Pilgrim) |
on Oct 19, 2006 at 20:12 UTC ( [id://579458]=perlmeditation: print w/replies, xml ) | Need Help?? |
Dear Monks, Herein lies my latest half-baked Perl extension. This one is for reducing the amount of boiler-plate code necessary for writing Perl subs. As per usual, I will jump right to the code which I always assume will speak for itself ( but rarely does ). Here is an example of a module that uses my "handy" new module.
SomeTestPackage2.pm
The previous code snip shows how the meta programming interface works for the most part. First, you specify a list of instance variables, or whatever, that you would like to pull into subs. This pre-declaration is necessary for syntax reasons. Next, you can specify "custom" attributes as package subs if you desire. The difference between a custom attribute and a canned/common one is that canned attributes begin with a colon and custom do not. Now, in your sub attribute you specify a list of variables you'd like pulled into your sub along with any attributes you'd like called on them. This is the test script running the prior code
test2.pl
Here is the output of running the previous script.
And finally, here is the code that is compiled from the "Method" attribute on the "self_sub".
That's it! Is it crap?
Back to
Meditations
|
|