File Coverage

blib/lib/Long/Jump.pm
Criterion Covered Total %
statement 36 37 97.3
branch 11 12 91.6
condition 3 3 100.0
subroutine 7 7 100.0
pod 2 2 100.0
total 59 61 96.7


line stmt bran cond sub pod time code
1             package Long::Jump;
2 1     1   250552 use strict;
  1         3  
  1         43  
3 1     1   7 use warnings;
  1         3  
  1         116  
4              
5             our $VERSION = '0.000003';
6              
7 1     1   8 use Carp qw/croak/;
  1         2  
  1         81  
8 1     1   1045 use Importer Importer => 'import';
  1         33501  
  1         11  
9              
10             our @EXPORT_OK = qw/setjump longjump/;
11              
12             my (%STACK, $SEEK, $OUT);
13              
14             sub setjump {
15 15     15 1 351161 my ($name, $code, @args) = @_;
16              
17 15 100       217 croak "You must name your jump point" unless defined $name;
18 14 100 100     320 croak "You must provide a subroutine as a second argument" unless $code && ref($code) eq 'CODE';
19              
20 12 100       187 croak "There is already a jump point named '$name'" if exists $STACK{$name};
21              
22 11         55 local $STACK{$name} = 1;
23              
24             LONG_JUMP_SET: {
25 11         16 $code->(@args);
  11         35  
26 2         1142 return undef;
27             }
28              
29 8 100       35 longjump($SEEK, @$OUT) if $name ne $SEEK;
30              
31 5         10 my $out = $OUT;
32 5         9 $OUT = undef;
33 5         17 return $out;
34             }
35              
36             sub longjump {
37 10     10 1 1152 $SEEK = shift;
38              
39 10 100       147 croak "No such jump point: '$SEEK'" unless $STACK{$SEEK};
40              
41 9         29 $OUT = [@_];
42              
43 1     1   347 my $ok = eval { no warnings 'exiting'; last LONG_JUMP_SET; 1 };
  1         2  
  1         164  
  9         18  
  9         54  
  0         0  
44 1         3 my $err = $@;
45              
46 1         3 my $msg = "longjump('$SEEK') failed";
47 1 50       6 $msg .= ", error: $err" unless $ok;
48              
49 1         5 croak $msg;
50             }
51              
52             1;
53              
54             __END__