My feelings on this subject are that you need to consider what type of parameter(s) are going to be passed to a given sub that you are writing.

  1. Will you be passing in a pre-existing object? If so, this is an object method, and write it as such.
  2. Will you be passing in a class name instead? If so, make it a class method.
  3. Otherwise, if it is a straight utility function which does not take either a class or an object as a mandatory parameter, it is a standalone function. Make it optionally exportable.

Sometimes there is synergy between cases 1 and 2 here, and so the construct

my $pkg = ref($self) || $self;
does the trick.

Having a heteromorphic sub that does the third case as well is hard to achieve and not worth it. But, this is what CGI.pm does - see this node.


In reply to Re: Object functionality? by rinceWind
in thread Object functionality? by BUU

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.