Howdy, Monks.

I'm in the process of putting together a couple of OO-based modules that wrap binaries and perform various sorts, subsets and munging operations on files.

The main problem I have is tracking all the files produced by each operation, and using that information to cut back on the amount of the information required by each method call.

In my quest to simplify (at least to the caller) the amount of parameters required I've tried the following:

This breaks very quickly - the user might do things in a valid but wierd order, or the code will pick the wrong file.

Also not great - then we have to repeatedly recalculate supplimentary data about each file, and it could get really messy if we have lots of files produced for some reason.

Both ideas above don't handle the case where the underlying data is held in a number of files, because the code decided to split them up for parallel processing for example.
The user only needs to believe they have one logical file, not all the details underneath.

Anyway, after that rather lengthy introduction, how should I deal with this?

I though of returning some sort of Foo::IO object that contains all of the filenames that had been processed by a method, and all the information we might need. If the user wants to process the output from an early stage of the code, he just uses the old Foo::IO object.

General example:

my $munger=Munger->new( input => "data" ); # assume the original "data" # since there's no Foo::IO argument my $sort_result = $munger->sort(by => "date"); # Again, just use the input filename stored in # the main object - "data" my $mangle_result = $munger->mangle(); # Use sorted file, and know that it's sorted by date # Give it the sort result Foo::IO state object my $subset_result = $munger->subset( by => date, $sort_result ); # etc.

When I mentioned my problem in the CB, jwest suggested using a object that contained several file objects that could be used for this sort of problem.

So, my questions are:

jwest's idea seems to make a lot of sense, but I've not yet been able to think out how the main class that does all the munging would use these state objects, and how it would all fit together.

Hopefully I've explained my problem with sufficient detail.
Thanks in advance.

BazB


If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.


In reply to Tracking processing by returning objects? by BazB

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.