Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Creating modules with OO and functional interfaces.by broquaint (Abbot) |
on May 14, 2002 at 11:58 UTC ( [id://166420]=note: print w/replies, xml ) | Need Help?? |
This sort of thing is generally discouraged in the world of OO where a consistent interface to the class is fairly key[1]. The mixing of a procedural[2] interface with class/object methods is rather counter-intuitive (where's my object state kept?!?). If you look at the source of CGI you can see it implements this mixing of styles by using a 'magical' method called self_or_default() which basically gets around the fact that a method is being called as a function. However if you're deadset on implementing both styles, then perl's certainly the language to do it in ;-) Check out the code for the self_or_default() method in CGI for some pointers on how to do this (it basically checks whether it's first argument is a reference to a CGI object or not and does the right thing).
HTH
_________
[1] there's an interesting debate on this topic here between TheDamian and tilly
In Section
Seekers of Perl Wisdom
|
|