File Coverage

blib/lib/Error/Return.pm
Criterion Covered Total %
statement 19 19 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1 1     1   3470 use 5.008;
  1         3  
  1         39  
2 1     1   6 use strict;
  1         2  
  1         29  
3 1     1   5 use warnings;
  1         2  
  1         49  
4              
5             package Error::Return;
6             BEGIN {
7 1     1   19 $Error::Return::VERSION = '1.110510';
8             }
9             # ABSTRACT: Really return() from a try/catch-block
10 1     1   931 use Scope::Upper qw(unwind want_at :words);
  1         1190  
  1         228  
11 1     1   7 use Exporter qw(import);
  1         2  
  1         151  
12             our @EXPORT = qw(RETURN);
13              
14             sub RETURN {
15 1     1 1 88 my $context = SUB UP SUB UP SUB UP SUB;
16             # read the context definition from right to left.
17             # SUB == this sub: RETURN()
18             # SUB UP SUB == the try() or catch() sub in which we're expected to run
19             # SUB UP SUB UP SUB == the sub containing the try/catch block
20             # SUB UP SUB UP SUB UP SUB == where we really want to return to
21              
22             # Do the cleanup that try() would normally do if the try-block had ended
23             # without an exception; this is only necessary if using Error.pm, but
24             # doesn't hurt if using Try::Tiny.
25              
26 1         3 shift @Error::STACK;
27 1 50       17 unwind +(want_at($context) ? @_ : $_[0]) => $context;
28             }
29             1;
30              
31              
32             __END__