Interesting question!
I'd say that unless all of your return statements take some form of return $one, $two, $three;, that's something you could only do at runtime instead of by looking at the source, as it gets less clear how many values will actually be returned in situations like return @foo; or return bar();.
How about something like Hook::LexWrap (see also http://www.perladvent.org/2003/3rd/)? I haven't really used it before but it seems like it should be possible to implement a check like you want:
use Hook::LexWrap 'wrap';
sub my_func { return ("foo") x shift }
wrap my_func =>
post => sub {
my $cnt = @{$_[-1]}; # assumes list context!
print "Returning $cnt values\n";
};
print my_func(1), "\n";
print my_func(2), "\n";
print my_func(3), "\n";
__END__
Returning 1 values
foo
Returning 2 values
foofoo
Returning 3 values
foofoofoo
It may also be worth taking a step back: How many returns do you have per sub? What's the largest number of values per return you have? If you've got a lot of returns per sub, then perhaps your logic is getting a little too complex? And if you have a large number of values per return, then perhaps you could look into returning complex data structures instead, like arrayrefs, hashrefs, or objects?
-
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.
|