Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: module w/ object-oriented and functional interfaces: best practices?

by BrowserUk (Pope)
on Sep 21, 2012 at 17:41 UTC ( #994957=note: print w/replies, xml ) Need Help??

in reply to module w/ object-oriented and functional interfaces: best practices?

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.

RIP Neil Armstrong

  • Comment on Re: module w/ object-oriented and functional interfaces: best practices?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994957]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-06-23 12:42 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.