One aspect worth considering is how the coder would work around lack of the convenience function, and how irritated she is likely to be about needing to. If, for example, you have a file_parse but not a filehandle_parse, that's likely to be very irritating when you have a filehandle but don't know the filename; when it's the other way round it isn't too bad, since you can just open the file to get the filehandle.

Similarly, if you have a string rather than a filehandle it may not be too difficult to work around (open(my $fh, "<", \$string) is newly available in 5.8.0), but if the code is only going to do:

sub filehandle_parse { my $fh = shift; my $string = do { local $/; <$fh> }; ... work on $string }
then it may seem like an unreasonable inefficiency, particularly since the string_parse functionality could be exposed directly (as below) for almost no extra cost.

It can also be worth putting in some placeholders for future optimisation: if string_parse is your primary entry point, but you anticipate that some users of the module may need to parse large files, putting in a

sub filehandle_parse { my $fh = shift; string_parse(do { local $/; <$fh> }); }
leaves room to implement that in a more memory-gentle manner in the future, without your users needing to change their code. Of course the functionality itself determines how likely that is ever to be useful.

No hard and fast rules, though; the main danger is that the "surface" of your module may become too complex. I'm a great believer in polymorphic methods to reduce that complexity ("EXPR may be a filehandle or a string"), but that approach isn't for everyone.

Hugo

In reply to Re: When is a feature bloat? by hv
in thread When is a feature bloat? by ajt

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.