Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
One advantage of having direct access to the data from the API (i.e. not forcing users to use the filesystem) is that it's easier to write tests.

Also, in my experience writing tests for your module generally gives you a good indication about the quality of the API: if your tests look straight-forward, the API is probably good. update: or rather, if your tests look clumsy, the API is probably bad.

For your specific instance, I would probably write a test like so (method and class-names made up):

# using Test::More... my $input_string = "some input data"; my $proc = Data::Processor->new( string => $input_string ); my @out_filenames = $proc->names; is_deeply(\@out_filenames,[qw(some list of filenames)]); is($proc->data($some_filename),"data for filename"); $proc->close();
then you can expand to direct to disk methods:
my $proc = Data::Processor->( file => "some filename"); # or handle => \*DATA for my $name ($proc->names) { $proc->write( $some_filename, file => $name ); # or handle => \*STDOUT }

I wouldn't return a hashref with all the filenames and data in it - chances are, that users who want to access the data directly aren't interested in all files, plus, if your archive is big, it would consume a lot of memory.


In reply to Re: Should Modules Do I/O? by Joost
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-20 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found