I don't want to get too much into theory or start any holy wars, so I'm going to stay on the "safe side" with this.

Just what should a perl module do?

In generaly, any set of functionality that is likely to be used by more than one other script or module can and should be put into a module package. You can further use namespaces to logicially organize functionality. What comprises a 'set' of functionality is a matter of diverse opinion, but the important thing is to decide on a definition and stick with it for a given project.

An example of how I do things may be helpful. I have a particular project where several diverse CGI components are querying the same SQL database, with the same credentials, &c. I placed the connection info into a module called Connection.pm. All I need to do to connect from any of my scripts (or modules) is:

require Connection; die Connection::error() unless (Connection::is_up()); my $dbh = Connection::handle();

am i being retarded or bad manared separating my code into modules this way? should I only sepparate code into modules if they can be used alone ?

Modules needn't be entirely stand-alone -- many, many CPAN modules have complex dependencies, and that doesn't make them bad. If these are modules specificially useful to your project and unlikely to have broader appeal, that's ok: just release your project as one distribution rather than having a separate distribution for each module.

Modules that offer more generalized functionality are more desirable -- the point of modules is code re-use, after all. Try to think about that when you decide what you're putting into a module, but don't become over-concerned with it.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: how far should i split my code into modules by radiantmatrix
in thread how far should i split my code into modules by leocharre

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.