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

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.