I'd second CountZeros suggestion to check out Moose, if only for getting a different perspective on OO programming styles.
Apart from that, this really is a matter of style and also of the interface you want to your class. For example, you might have a class DataAnalyzer that does some calculations on data from a database. One interface to this could look like this:
my $da = DataAnalyzer->new(); $da->connect_to_db->($dsn); my $result_set = $da->run_analysis( %parameters_for_analysis );
But this probably connects to the same database every time, so it might make more sense to initiate the object with the database parameters straight away, i.e. set up the connection in the 'new' method so that the API becomes:
my $da = DataAnalyzer->new( $dsn ); my $result_set = $da->run_analysis( %parameters_for_analysis );
Now the 'new' method does a bit moe work (set up the actual connection) but it seems to make more sense from the user's perspective.
Or, if you find that the new method should return results straight away because it is unlikely that this will ever be run twice with different parameters on the same database anyway. Now your new method will run the analysis and return some sort of result immediately (this may not be the best example but nevertheless...):
my $result_set = DataAnalyzer->new( $dsn, \%parameters_for_analysis ) +;
Whether or not you use an '_init' method is really just matter of style: it certainly helps to de-clutter the 'new' method itself and keep it short in cases where a lot of setting-up has to be done.

In reply to Re: Philosophy of a "new" method by tospo
in thread Philosophy of a "new" method by rastoboy

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.