| 1 | package Long::Jump; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.000005'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Importer Importer => 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our @EXPORT_OK = qw/setjump longjump havejump/; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my (%STACK, $SEEK, $OUT); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 15 | ▶ | sub havejump { $STACK{$_[-1]} ? 1 : 0 } | ||||||||||||||||||||||||||
|
Subroutine
havejump: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 20 | ▶ | sub setjump { | ||||||||||||||||||||||||||
|
Subroutine
setjump: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 20 | my ($name, $code, @args) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 20 | ▶ | croak "You must name your jump point" unless defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 19 | ▶ | croak "You must provide a subroutine as a second argument" unless $code && ref($code) eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$code and ref $code eq "CODE"
MC/DC100%2/2
$code and ref $code eq "CODE"
$code
ref $code eq "CODE"
Truth table100%3/3
A and B
A= $codeB= ref $code eq "CODE"
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 17 | ▶ | croak "There is already a jump point named '$name'" if exists $STACK{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 16 | local $STACK{$name} = 1; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | LONG_JUMP_SET: { | ||||||||||||||||||||||||||||
| 27 | 16 | $code->(@args); | |||||||||||||||||||||||||||
| 28 | 6 | return undef; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 9 | ▶ | longjump($SEEK, @$OUT) if $name ne $SEEK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | my $out = $OUT; | |||||||||||||||||||||||||||
| 34 | 6 | $OUT = undef; | |||||||||||||||||||||||||||
| 35 | 6 | return $out; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 11 | ▶ | sub longjump { | ||||||||||||||||||||||||||
|
Subroutine
longjump: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 11 | $SEEK = shift; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 11 | ▶ | croak "No such jump point: '$SEEK'" unless $STACK{$SEEK}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 10 | $OUT = [@_]; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $ok = eval { no warnings 'exiting'; last LONG_JUMP_SET; 1 }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 1 | my $err = $@; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | my $msg = "longjump('$SEEK') failed"; | |||||||||||||||||||||||||||
| 49 | 1 | ▶ | $msg .= ", error: $err" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | croak $msg; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||