|There's more than one way to do things|
Re: Difference between Function-oriented and object-oriented in Perlby erroneousBollock (Curate)
|on Nov 23, 2007 at 05:37 UTC||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" 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.