blib/lib/DBIO/Future/Immediate.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 86.6% 26 / 30 Conditioncond 77.7% 14 / 18 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 100% 12 / 12 Podpod 100% 9 / 9 totaltotal 90.0% 117 / 130 CC 23 SCAR 16.2
CC
23
Cov
91%
then
8.0
catch
7.0
and_then
6.1
CRAP 5.1
« blib/lib/DBIO/Relationship/HasOne.pm ↑ Summary blib/lib/DBIO/Deploy/Base/TempDatabase.pm »
1 package DBIO::Future::Immediate;
2 # ABSTRACT: Dependency-free immediate Future for DBIO's 'immediate' async mode
3  
4 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 39 our $VERSION = '0.900007';
8  
9 39 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 3241 ▶sub done {
Subroutine done: called CC=1 SCAR=0.0
Pod documented
14 3241 my $class = shift;
15 3241 bless { ready => 1, failed => 0, result => [@_] }, $class;
16 }
17  
18  
19 96 ▶sub fail {
Subroutine fail: called CC=1 SCAR=0.0
Pod documented
20 96 my ($class, $error) = @_;
21 96 bless { ready => 1, failed => 1, error => $error, result => [] }, $class;
22 }
23  
24  
25 1758 ▶sub is_ready { 1 }
Subroutine is_ready: called CC=1 SCAR=0.0
Pod documented
26  
27  
28 1381 ▶sub is_failed { $_[0]->{failed} ? 1 : 0 }
Subroutine is_failed: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'failed'} ? : 35 1346 1381
29  
30  
31 232 ▶sub get {
Subroutine get: called CC=3 SCAR=11.0
Pod documented
32 232 my $self = shift;
33 232 ▶ die $self->{error} if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 42 190 232
34 190 ▶ return wantarray ? @{ $self->{result} } : $self->{result}[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 50 140 190
35 }
36  
37  
38 1723 ▶sub then {
Subroutine then: called CC=8 SCAR=20.8
Pod documented
39 1723 my ($self, $on_done, $on_fail) = @_;
40 1723 ▶ my $cb = $self->{failed} ? $on_fail : $on_done;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'failed'} ? : 33 1690 1723
41 1723 ▶ return $self unless $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 14 1709 1723
42 1709 my @r = eval {
43 1709 ▶ $cb->($self->{failed} ? $self->{error} : @{ $self->{result} });
Branch: 1 branch
BranchTrueFalseTotal
$self->{'failed'} ? : 20 1689 1709
44 };
45 1709 ▶ return ref($self)->fail($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 6 1703 1709
46 1703 ▶ return $r[0]
Branch: 1 branch
BranchTrueFalseTotal
if @r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__) 1583 120 1703
Condition83%5/6
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
!ll&&!rl&&r
46741583
@r == 1 and builtin::blessed($r[0])
!ll&&!rl&&r
0461657
MC/DC66%2/3
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
@r == 1 builtin::blessed($r[0]) $r[0]->isa(__PACKAGE__)
Truth table75%3/4
A and B and C
A= @r == 1B= builtin::blessed($r[0])C= $r[0]->isa(__PACKAGE__)
ABCresult
0XX0
10X0
1100
1111
47 if @r == 1 && Scalar::Util::blessed($r[0]) && $r[0]->isa(__PACKAGE__);
48 120 return ref($self)->done(@r);
49 }
50  
51  
52 20 ▶sub catch {
Subroutine catch: called CC=7 SCAR=19.5
Pod documented
53 20 my ($self, $cb) = @_;
54 20 ▶ return $self unless $self->{failed} and $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"failed"} and $cb 2 18 20
Condition100%3/3
$self->{"failed"} and $cb
!ll&&!rl&&r
1118
MC/DC100%2/2
$self->{"failed"} and $cb
$self->{"failed"} $cb
Truth table100%3/3
A and B
A= $self->{"failed"}B= $cb
ABresult
0X0
100
111
55 18 my @r = eval { $cb->($self->{error}) };
56 18 ▶ return ref($self)->fail($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 18 18
57 18 ▶ return $r[0]
Branch: 1 branch
BranchTrueFalseTotal
if @r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__) 13 5 18
Condition83%5/6
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
!ll&&!rl&&r
5013
@r == 1 and builtin::blessed($r[0])
!ll&&!rl&&r
2313
MC/DC66%2/3
@r == 1 and builtin::blessed($r[0]) and $r[0]->isa(__PACKAGE__)
@r == 1 builtin::blessed($r[0]) $r[0]->isa(__PACKAGE__)
Truth table75%3/4
A and B and C
A= @r == 1B= builtin::blessed($r[0])C= $r[0]->isa(__PACKAGE__)
ABCresult
0XX0
10X0
1100
1111
58 if @r == 1 && Scalar::Util::blessed($r[0]) && $r[0]->isa(__PACKAGE__);
59 5 return ref($self)->done(@r);
60 }
61  
62  
63 1 ▶sub and_then {
Subroutine and_then: called CC=5 SCAR=18.1
Pod documented
64 1 my ($self, $cb) = @_;
65 1 ▶ return $self if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 1 1
66 1 my $inner = eval { $cb->(@{ $self->{result} }) };
67 1 ▶ return ref($self)->fail($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
68 1 ▶ return $inner if ref($inner) && $inner->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if ref $inner and $inner->isa(__PACKAGE__) 1 0 1
Condition33%1/3
ref $inner and $inner->isa(__PACKAGE__)
!ll&&!rl&&r
001
MC/DC0%0/2
ref $inner and $inner->isa(__PACKAGE__)
ref $inner $inner->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= ref $innerB= $inner->isa(__PACKAGE__)
ABresult
0X0
100
111
69 0 return ref($self)->done($inner);
70 }
71  
72  
73 2 ▶sub needs_all {
Subroutine needs_all: called CC=3 SCAR=11.0
Pod documented
74 2 my ($class, @futures) = @_;
75 2 my @results;
76 2 for my $f (@futures) {
77 5 ▶ return $f if $f->is_failed;
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_failed 1 4 5
78 4 push @results, $f->get;
79 }
80 1 return $class->done(@results);
81 }
82  
83 39 1;
84  
85 __END__
« blib/lib/DBIO/Relationship/HasOne.pm ↑ Summary blib/lib/DBIO/Deploy/Base/TempDatabase.pm »