This is yet a continuation of the microlanguage that I'm working on; right now, I've been able to implement tye's solution on reverse inheritence as offered in (tye)Re2: Possible Stupid Perl Trick - Importing method into object class?. That is, I can now do:
package Data; sub new { ... } sub other { ... } #no "process" package package My::ProcessA; BEGIN { #reverse inheritence code into Data } sub processA { my ( $data, @opts ) = @_; #$data is a Data instance\ ... return new Data( $stuff ); } package My::ProcessB; BEGIN { #reverse inheritence code into Data } sub processB { my ( $data, @opts ) = @_; #$data is a Data instance ... return new Data( $stuff ); } # In code: use Data; use My::ProcessA; (Data::processA appears, magically!) use My::ProcessB; (Data::processB appears, magically!) my $data = new Data ( $data_from_file ); # Now possible, woohoo! my $processed = $data ->processA( @Aopts ) ->processB( @Bopts );
This works great, and no compliants here.

However, in browsing thru OOPerl recently, I noticed that the wantarray function, which can determine what context the function is called in, actually can have 3 states; true if an array is wanted, defined but false if a scalar is wanted, or undefined if in void context. Now, thinking about my functions above, I wonder if there should be a difference in terms of functionality between the following calls:

my $newdata = $data->processA( @opts ); #scalar $data->processA( @opts ); #void
That is, in the void context, it would seem to be apparent that I want to do process A on the data and set the data to those new values. In the scalar context, the function returns a new Data object which is stored in the new variable; $data may or may not be set with the new data as well. I'm more interested in the case where, in scalar context, it is NOT set with the new data while void context it is; I know this feels like bad coding style, but for some reason, this seems to rather natural in the way this data is processed.

Should I avoid this 'mixed metaphore' and have the processing be consistent regardless of context, or is there nothing wrong with the alternate behaviors?

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important


In reply to Style question - Modify passed arged if void context? by Masem

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.