Welcome to the Monastery | |
PerlMonks |
Re: Is it legal to create subs in a module?by merlyn (Sage) |
on Oct 11, 2001 at 19:27 UTC ( [id://118233]=note: print w/replies, xml ) | Need Help?? |
First, please don't use string eval for something like:
It's far better instead to compile that code once, plugging in the parts that are variable, using a closure, like: There. No nasty runtime eval, meaning no "firing up the compiler" every time you add a method (s-l-o-o-o-o-o-w), nor worries that if $action contains quote-character messiness, you'll get clobbered. Second, the class package (where the methods are kept) is not per-object, but shared amongst all objects. So if one object added a "blah" method, that would be seen by all objects. Maybe what you want is one of the classless object solutions, like Class::Prototyped by the Monestary's own bikeNomad. That lets you create lightweight classes with methods that are specific to that object. In fact, you can then inherit from that (very Self-like, if you're familiar with Self). -- Randal L. Schwartz, Perl hacker
In Section
Seekers of Perl Wisdom
|
|