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