| 1 | package Try::Chain; ## no critic (TidyCode) | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Try::Tiny qw(try catch finally); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | our $VERSION = '0.005'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 11 | try catch finally | ||||||||||||||||||||||||||||
| 12 | try_chain | ||||||||||||||||||||||||||||
| 13 | $call_m $call_em | ||||||||||||||||||||||||||||
| 14 | $fetch_i $fetch_ei | ||||||||||||||||||||||||||||
| 15 | $fetch_k $fetch_ek | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 22 | ▶ | sub try_chain (&;@) { ## no critic (SubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
try_chain: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 22 | my ( $chain_code, @more ) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 12 | ▶ | my $check_code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 22 | ## no critic (ComplexRegexes) | ||||||||||||||||||||||||||||
| 23 | 12 | ▶ | m{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | \A \QCan't call method "\E .*? \Q" on an undefined value\E \b | ||||||||||||||||||||||||||||
| 25 | | \A \QCan't locate object method "\E .*? \Q" via package\E \b | ||||||||||||||||||||||||||||
| 26 | | \A \QCan't use an undefined value as a HASH reference\E \b | ||||||||||||||||||||||||||||
| 27 | | \A \QCan't use an undefined value as an ARRAY reference\E \b | ||||||||||||||||||||||||||||
| 28 | }xms | ||||||||||||||||||||||||||||
| 29 | or die $_; ## no critic (RequireCarping) | ||||||||||||||||||||||||||||
| 30 | ## use critic (ComplexRegexes) | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 10 | return (); | |||||||||||||||||||||||||||
| 33 | 22 | }; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | return @more | ||||||||||||||||||||||||||||
| 36 | 6 | ▶ | ? try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 6 | ▶ | try { $chain_code->() } catch { $check_code->() }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | } @more | ||||||||||||||||||||||||||||
| 39 | 22 | ▶ | : try { $chain_code->() } catch { $check_code->() }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 6 | ▶ | our $call_m = sub { ## no critic (PackageVars) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 6 | my ( $self, $method, @more ) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 6 | ▶ | return $self ? $self->$method(@more) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 5 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 6 | ▶ | our $call_em = sub { ## no critic (PackageVars) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 49 | 6 | my ( $self, $method, @more ) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 6 | ▶ | return $self && $self->can($method) ? $self->$method(@more) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self and $self->can($method)
MC/DC100%2/2
$self and $self->can($method)
$self
$self->can($method)
Truth table100%3/3
A and B
A= $selfB= $self->can($method)
| |||||||||||||||||||||||||||||
| 52 | 5 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | our $fetch_i = sub { ## no critic (PackageVars) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 4 | my ( $array_ref, $index ) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | return $array_ref->[$index]; | |||||||||||||||||||||||||||
| 58 | 5 | }; | |||||||||||||||||||||||||||
| 59 | 4 | ▶ | our $fetch_ei = sub { ## no critic (PackageVars) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 60 | 4 | my ( $array_ref, $index ) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | ▶ | return exists $array_ref->[$index] ? $array_ref->[$index] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 5 | }; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | ▶ | our $fetch_k = sub { ## no critic (PackageVars) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 4 | my ( $hash_ref, $key ) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | return $hash_ref->{$key}; | |||||||||||||||||||||||||||
| 69 | 5 | }; | |||||||||||||||||||||||||||
| 70 | 4 | ▶ | our $fetch_ek = sub { ## no critic (PackageVars) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 4 | my ( $hash_ref, $key ) = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 4 | ▶ | return exists $hash_ref->{$key} ? $hash_ref->{$key} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 5 | }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # $Id$ | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||