File Coverage

blib/lib/Long/Jump.pm
Criterion Covered Total %
statement 37 38 97.3
branch 13 14 92.8
condition 3 3 100.0
subroutine 8 8 100.0
pod 3 3 100.0
total 64 66 96.9


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