return a hashref with output names as keys, and file contents as data values (caller can write them out himself)

The only thing this would do is force most of your users to use the same boilerplate every time they used your module:

for (my($file,$data) = each %returnedhash) { open my $f, ">", $file or die "$!"; print $f $data; }

And we all know that boilerplate is generally bad. Modules are written to avoid boilerplate, not create more of it.

If you're afraid that your module might occasionally generate invalid data, and you don't want to clobber their files with it, I can sort of understand your reluctance. But believe me, if you provide them with data and a filename, they will clobber their own files happily, and still blame you for any problems that may occur. The only difference is that they will be cursing you for an inconvenient interface as well. :-)

If, on the other hand, you're confident in your module, then I don't see a problem. As long as the module is clearly documented to clobber files, you should have no reason to be concerned. To that end, your test suite should be heavily loaded towards pounding on the file IO code. This can at least provide a minimum of reassurance.

Update: of course, I agree with all the other fine Monks who recommend having both methods available.


In reply to Re: Should Modules Do I/O? by Mugatu
in thread Should Modules Do I/O? by pboin

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.