Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
But I coult not find any document which explains about the function oriented and object oriented way of using Perl modules.
I haven't really seen 'function-oriented' used as a term.

Usually it's just called 'imperative' (as opposed to 'functional' which is something else altogether).

Not everyone is going to agree with the classifications I provide below (different language backgrounds, etc), so I welcome improvements/clarifications to nomenclature.

Not all Perl modules expose both kinds of interface, and where they do it's typically (not always) because the imperative interface is there for legacy users of the module.

For imperative interfaces to modules, you get two main types:

  • "singleton": state/data held in module globals
  • "state-passing": you have to pass state/context to each call to a function.

"singleton" imperative interfaces to modules offer the least level of composability with other APIs, and must generally have access to their functions serialised to avoid confusion or corruption. In your example above, CGI is first used via a "singleton" CGI interface; all information related to the request and the response are stored in module globals inside the CGI module.

"state-passing" imperative interfaces are generally used by modules that don't have a lot of state. An example is Date::Calc; it exposes large number of functions that take simple scalars or lists and has no state data to speak of.

OO interfaces for modules seem more popular these days, mostly I guess because they're a little more composable than imperative interfaces.

Functional (lower-order FP) interfaces to modules are even less common, but can have even greater composability. File::Find and List::Util are probably good examples.


In reply to Re: Difference between Function-oriented and object-oriented in Perl by erroneousBollock
in thread Difference between Function-oriented and object-oriented in Perl by jesuashok

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2015-12-02 04:19 GMT
    Find Nodes?
      Voting Booth?

      My keyboard shows this many letters:

      Results (34 votes), past polls