blib/lib/Exception/Delayed.pm

filter: Statementstmt 94.1% 32 / 34 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 4 / 4 totaltotal 92.8% 52 / 56 CC 7 SCAR 9.3
CC
7
Cov
91%
result
4.0
wantlist
2.0
wantscalar
2.0
CRAP 2.5
↑ Summary
1 package Exception::Delayed;
2  
3 # ABSTRACT: Execute code and throw exceptions later
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.002'; # VERSION
9  
10 3 ▶sub wantscalar {
Subroutine wantscalar: called CC=2 SCAR=6.9
Pod documented
11 3 my ( $class, $code, @args ) = @_;
12 3 my $RV;
13 3 eval { $RV = scalar $code->(@args); };
14 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 1 2 3
15 1 return bless { error => $@ } => $class;
16 }
17 else {
18 2 return bless { result => \$RV } => $class;
19 }
20 }
21  
22 2 ▶sub wantlist {
Subroutine wantlist: called CC=2 SCAR=7.1
Pod documented
23 2 my ( $class, $code, @args ) = @_;
24 2 my @RV;
25 2 eval { @RV = $code->(@args); };
26 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 2 2
27 0 return bless { error => $@ } => $class;
28 }
29 else {
30 2 return bless { result => \@RV } => $class;
31 }
32 }
33  
34 2 ▶sub wantany {
Subroutine wantany: called CC=2 SCAR=6.9
Pod documented
35 2 my ( $class, $wantarray, $code, @args ) = @_;
36 2 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 1 1 2
37 1 return $class->wantlist( $code, @args );
38 }
39 else {
40 1 return $class->wantscalar( $code, @args );
41 }
42 }
43  
44 5 ▶sub result {
Subroutine result: called CC=4 SCAR=14.0
Pod documented
45 5 my ($self) = @_;
46 5 ▶ if ( exists $self->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'error'}) { } 1 4 5
47 1 die $self->{error};
48 }
49 else {
50 4 my $result = delete $self->{result};
51 4 ▶ if ( ref $result eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $result eq 'ARRAY') { } 2 2 4
elsif (ref $result eq 'SCALAR') { } 2 0 2
52 2 return @$result;
53 }
54 elsif ( ref $result eq 'SCALAR' ) {
55 2 return $$result;
56 }
57 else {
58 0 return;
59 }
60 }
61 }
62  
63 4 1;
64  
65 __END__
↑ Summary