I guess my explaination left something to be desired, so here it is in slightly expanded pseudo-code.

The basic idea is that rather than each operation on an instance of Foo returning an instance of some State class, it returns a new instance of itself. To perform any further processing on that state of the data, he invokes the operation directly on returned object.

That way there are no seperate objects to be passed back to you wrongly.

package Foo; sub new{ my ($class, filespec) = @_; # check for existance, other init stuff return bless {file=>$filespec }, $class; } sub sort{ $self = shift; system( 'sort', $self->$filespec, '>', "$self->filespec.sorted" ); return $self->new( "$self->$filespec.sorted" ); } sub munge{ $self = shift; system( 'munge', $self->$filespec, '>', "$self->filespec.munged" ) +; return $self->new( "$self->$filespec.munged" ); } 1; package main; # Start with a object created by the user. my $data = Foo->new( 'datafile' );; # Munge it two different ways and get two seperate objects back repres +enting the two new states my $sorted = $data->sort(); my $munged = $data->munged(); # Further processing on the new state is invoked directly on the new o +bject my $sorted'n'munged = $sorted->munge(); my $munged'n'sorted = $munged->sort(); # Or even pipeline them my $sorted'n'munged'n'sorted_again = $data->sort()->munge()->sort();

Anyways, if I understood your question correctly, that's how I would do it.

HTH. Sorry, if it doesn't.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

In reply to Re: Re: Re: Tracking processing by returning objects? by BrowserUk
in thread 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.