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   439397 use strict;
  2         4  
  2         80  
3 2     2   19 use warnings;
  2         7  
  2         150  
4              
5             our $VERSION = '0.000005';
6              
7 2     2   15 use Carp qw/croak/;
  2         8  
  2         152  
8 2     2   1653 use Importer Importer => 'import';
  2         13009  
  2         19  
9              
10             our @EXPORT_OK = qw/setjump longjump havejump/;
11              
12             my (%STACK, $SEEK, $OUT);
13              
14 15 100   15 1 152489 sub havejump { $STACK{$_[-1]} ? 1 : 0 }
15              
16             sub setjump {
17 20     20 1 208295 my ($name, $code, @args) = @_;
18              
19 20 100       197 croak "You must name your jump point" unless defined $name;
20 19 100 100     357 croak "You must provide a subroutine as a second argument" unless $code && ref($code) eq 'CODE';
21              
22 17 100       163 croak "There is already a jump point named '$name'" if exists $STACK{$name};
23              
24 16         37 local $STACK{$name} = 1;
25              
26             LONG_JUMP_SET: {
27 16         25 $code->(@args);
  16         32  
28 6         1416 return undef;
29             }
30              
31 9 100       29 longjump($SEEK, @$OUT) if $name ne $SEEK;
32              
33 6         8 my $out = $OUT;
34 6         9 $OUT = undef;
35 6         18 return $out;
36             }
37              
38             sub longjump {
39 11     11 1 868 $SEEK = shift;
40              
41 11 100       189 croak "No such jump point: '$SEEK'" unless $STACK{$SEEK};
42              
43 10         25 $OUT = [@_];
44              
45 2     2   550 my $ok = eval { no warnings 'exiting'; last LONG_JUMP_SET; 1 };
  2         4  
  2         270  
  10         15  
  10         49  
  0         0  
46 1         4 my $err = $@;
47              
48 1         3 my $msg = "longjump('$SEEK') failed";
49 1 50       5 $msg .= ", error: $err" unless $ok;
50              
51 1         10 croak $msg;
52             }
53              
54             1;
55              
56             __END__