This isn't a definite solution, but I guess it could help sometimes.
package Bloodnok; sub new { bless {}, shift } sub call { my ( $self, $position ) = @_; my $wa = wantarray; if ( $wa ) { print "$position: list\n"; } elsif ( defined $wa ) { print "$position: scalar\n"; } else { print "$position: void\n"; } return $self; } package main; my $yo_sup_b = Bloodnok->new(); $yo_sup_b->call( 'void start' ) ->call( 'void mid' ) ->call( 'void end' ); scalar $yo_sup_b->call( 'scalar start' ) ->call( 'scalar mid' ) ->call( 'scalar end' ); () = $yo_sup_b->call( 'list start' ) ->call( 'list mid' ) ->call( 'list end' ); __END__ void start: scalar void mid: scalar void end: void scalar start: scalar scalar mid: scalar scalar end: scalar list start: scalar list mid: scalar list end: list
Long story short, wantarray will always show a scalar context for calls before the end of a chain, but it shows the original context at the end of the chain. If your chain is in a scalar context anyway, that doesn't help at all, but in the other two contexts you can tell you must be at the end.
In reply to Re: Determination of chained method call context
by kyle
in thread Determination of chained method call context
by Bloodnok
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |