more useful options | |
PerlMonks |
Re: Methods supporting both package and OOP style callsby frag (Hermit) |
on Aug 06, 2002 at 04:38 UTC ( [id://187922]=note: print w/replies, xml ) | Need Help?? |
The magic you seek is UNIVERSAL::isa.
I concur with dragonchild though: pick some subset of the 3 possible WTDI (function, class method, object method) and stick to it, and make it clear in the docs which is preferred. If people using the module get used to "Foo::bar(arg)" then what if some subs really must have the object passed in? Will it be easy to remember which form goes with which subroutine? Personally, I think the sensible way is: public subroutines should be all methods or all functions (in which case it isn't an object package), or else mostly methods with a simple exported procedural function wrapping the most central method (see Data::Dumper). Private subs can vary freely, depending on if they manipulate object/class data or not. (And note this all assumes that speed isn't much of a factor - procedural function calls are always faster than methods.) -- Frag.
In Section
Seekers of Perl Wisdom
|
|