> Is there any state that needs to be shared among them? If so, use OOP

Actually you can share state in the package variables, but only one set of them.

This pattern is similar to a singleton object in OOP.

(The modular interface of Data::Dumper is a good example for that, with the global config vars, like $Data::Dumper::Indent )

But you are right, a very good reason to use methods instead of functions is if they all start to look like this

package Do_Something my %repeated = init(); foo( X, %repeated); bar( Y, %repeated); ...

then it's obviously better to write

my $obj = Do_Something->new(%init); $obj->foo(X); $obj->bar(Y);

especially if there is a chance that you might need to have different initializations in the same code

my $obj2 = Do_Something->new(%other_init);

( see Data::Dumper again with it's alternative OOP interface, where the configs are encapsulated in the objects like $OBJ->Indent([NEWVAL]) or $OBJ2->Indent([NEWVAL]) )

On a side note: I prefer to think about objects like actors which do things, not containers which have attributes.

So reducing them to shared data is not the whole picture.

Last but not least: PBP lists some criteria when to use what...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^2: Procedural vs OOP modules by LanX
in thread Procedural vs OOP modules by Bod

Title:
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, details, 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, summary, 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.