blib/lib/Exception/Delayed.pm

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