Re: module w/ object-oriented and functional interfaces: best practices?by BrowserUk (Pope)
|on Sep 21, 2012 at 17:41 UTC||Need Help??|
Kinda hard to advise seeing as you don't want to re-write your procedural (functional has other connotations), stuff, but haven't shown us what it looks like.
At the simplest level, a method is just a function that has a hashref (or other ref) pointing to the data it is to operate on, as its first argument.
If your procedural functions were written (or could be easily modified) to take a hashref containing the data they operate on, then making the module "OO" could be as simple as adding a constructor sub that builds a hash from its inputs, blesses a reference to it and returns it.
That way, all your existing subs become methods also, if the reference to the data is blessed,o with no further work required.
It probably wouldn't be "good OO"; but it would satisfy the requirement of having both styles of interface.
But then the question becomes; why do you want two styles of interface?
Individual problems/libraries generally lend themselves best to one or the other. Having both is often no more than paying lip service to peoples wont to have things work in one particular way.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.