It seems like what you're trying to do violates modularity in a way that'll cause problems. That is, somebody who wants to extend this to a new format should ideally be able to just whip up a DBI::Pretty::Foo and start using it in scripts. But with this design, any such developer also has to muck with the DBI::Pretty.pm as well, adding an elsif to that bit of (pseudo-)code. This is really undesirable, potentially making it difficult to maintain and use your module.

As an alternative, how about this:

If you do want the module to be flexible enough to handle a few alternative situations by default without requiring subclasses, just place that if/elsif you've got inside the default parse_input(), but rather than calling alternative use statements, each condition should just invoke different parse_foo_input() methods. Doing it like this -- in parse_input(), not in new() -- shouldn't interfere with the ability for other people to roll their own subclasses.

But the simplest/best thing is probably to just require that anyone using the module must themselves pick the subclass(es) that they want. You can then provide a few basic alternative subclasses along with the main module.

-- Frag.


In reply to Re: Scope of a Module? by frag
in thread Scope of a Module? by Masem

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.