return::thence - return values from up above
return has a seemed inconsistency when used within functions that take a code block, such as try below.
return
try
use Try::Tiny; # will return 1 sub foo { try { return(2) }; return 1; }
This module introduces a return::thence keyword which returns from where you really mean:
return::thence
# will return 2 sub bar { try { return::thence(2) }; return 1; }
This module needs to perform a bit of guesswork to figure out where you want to return from. Looking at the call stack, it returns from the first named function (see Sub::Name, Sub::Identify) that was defined in the same file and same package as its immediate caller.
return::thence doesn't especially differentiate between list and scalar context.
sub baz { return::thence('a' .. 'z') }; my @baz = baz() # 'a' .. 'z' my $baz = baz(); # 'z'
If you need more power, use Scope::Upper which is what this module uses under the hood.
Skipping over XS stack frames can cause segfaults.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=return-thence.
Scope::Upper.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install return::thence, copy and paste the appropriate command in to your terminal.
cpanm
cpanm return::thence
CPAN shell
perl -MCPAN -e shell install return::thence
For more information on module installation, please visit the detailed CPAN module installation guide.