This works great, and no compliants here.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 );
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:
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.my $newdata = $data->processA( @opts ); #scalar $data->processA( @opts ); #void
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Style question - Modify passed arged if void context?
by dragonchild (Archbishop) on Dec 11, 2001 at 22:07 UTC | |
|
Re: Style question - Modify passed arged if void context?
by dws (Chancellor) on Dec 11, 2001 at 23:14 UTC | |
|
Re: Style question - Modify passed arged if void context?
by blakem (Monsignor) on Dec 12, 2001 at 00:49 UTC | |
|
Re: Style question - Modify passed arged if void context?
by japhy (Canon) on Dec 11, 2001 at 22:47 UTC | |
|
Re: Style question - Modify passed arged if void context?
by herveus (Prior) on Dec 12, 2001 at 20:12 UTC |