Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

When I write modules for Perl they typically follow a functional style of programming. I learned Perl from a functional point of view and I feel like Perl best lends itself to this paradigm. Certainly not saying that Perl can't do OO (I have written some OO code in Perl before, enough to know the basics), but just saying this now so that you know where I'm coming from.

That said, I have been running into situations where I want to access some modules in a more OO style. Or extend them so that I can leverage some of the benefits of OO. I'd like to keep all their functional components in place but add on this OO interface as well.

Dug up this post: Module provides both of functional interface and object-oriented one, which was a good read but didn't seem to come to any real conclusions. I know there are some great modules on CPAN that implement this sort of dual interface. The ones that I've code dived look like they go ahead and write separate functional routines which can be exported should the user want a functional interface.

Since this is primarily retrofitting some already written modules I'd rather not have to rewrite all of my functions. So least effort would be a nice plus but it doesn't outweigh keeping things 'best practice'.

My initial thought was to add in OO and then my already written functions can determine intent based on their arguments. My second thought was to just spend a bit more time on this and make everything primarily OO and fake the functional side by having them create self-objects every time they are called functionally. Probably a significant performance hit there for functional implementers.

One final note: I am aware of Moose et al. Seem very handy, but I have not taken the time to learn them. I want to avoid using these until I have a solid grasp of how to implement OO in Perl by hand. So in a way I am approaching this as a bit of a learning experience as well. Besides, I am already fluent in other OO languages that look and feel like what Moose-ish modules do to Perl.

Bit long-winded but I hope that I got my situation and questions across. Any ideas/recommendations/links/rants on best practices for implementing OO + functional interfaces for modules?

In reply to module w/ object-oriented and functional interfaces: best practices? by temporal

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (2)
    As of 2018-02-19 06:40 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (258 votes). Check out past polls.