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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|