blib/lib/DBIO/Async/Future.pm

filter: Statementstmt 100% 45 / 45 Branchbran 64.2% 9 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 86.5% 71 / 82 CC 11 SCAR 11.1
CC
11
Cov
88%
_withdraw_dying_wait
5.9
await
3.0
new
3.0
CRAP 3.0
« blib/lib/DBIO/Async/Storage.pm ↑ Summary blib/lib/DBIO/Async/Pool.pm »
1 package DBIO::Async::Future;
2 # ABSTRACT: The Future a caller waits on for a pool connection, blocking via Future::IO
3  
4 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 44 our $VERSION = '0.900007';
8  
9 44 ▶use base 'Future';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 44 ▶use Future::IO ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 44 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16 78 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
17 78 my $proto = shift;
18 78 my $self = $proto->SUPER::new(@_);
19 78 ▶ if (ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")) 49 29 78
Condition66%2/3
ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")
!ll&&!rl&&r
29049
MC/DC50%1/2
ref $proto and my $mark = $proto->udata("dbio_async_pool_wait")
ref $proto my $mark = $proto->udata("dbio_async_pool_wait")
Truth table66%2/3
A and B
A= ref $protoB= my $mark = $proto->udata("dbio_async_pool_wait")
ABresult
0X0
100
111
20 49 $self->set_udata(dbio_async_pool_wait => $mark);
21 }
22 78 return $self;
23 }
24  
25  
26 29 ▶sub mark_pool_wait {
Subroutine mark_pool_wait: called CC=2 SCAR=6.9
Pod documented
27 29 my ($self, $pool) = @_;
28 29 my $mark = [ $pool, $self ];
29 29 Scalar::Util::weaken($_) for @$mark;
30 29 $self->set_udata(dbio_async_pool_wait => $mark);
31 29 return $self;
32 }
33  
34  
35 6 ▶sub await {
Subroutine await: called CC=3 SCAR=11.0
Pod documented
36 6 my $self = shift;
37 6 ▶ return $self if $self->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_ready 0 6 6
38  
39 # A pending Future of the implementation's class, made by cloning one of its
40 # own: its await runs the implementation's loop until it is ready. The
41 # sleep it is cloned from is left to elapse -- this dist cancels a Future in
42 # one place only (Storage _let_go, t/13) -- and the tick is never cancelled,
43 # only dropped with this Future when the wait dies.
44 6 my $tick = Future::IO->sleep(0)->new;
45  
46 6 ▶ $self->on_ready(sub { $tick->done unless $tick->is_ready });
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless $tick->is_ready 6 0 6
47  
48 6 my $ok = eval { $tick->await; 1 };
49 6 my $error = $@;
50 6 ▶ return $self if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 5 1 6
51  
52 1 $self->_withdraw_dying_wait($error);
53 1 die $error;
54 }
55  
56 1 ▶sub _withdraw_dying_wait {
Subroutine _withdraw_dying_wait: called CC=5 SCAR=17.8
57 1 my ($self, $error) = @_;
58 1 ▶ my $mark = $self->udata("dbio_async_pool_wait") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $mark = $self->udata("dbio_async_pool_wait") or return 1 0 1
59 1 my ($pool, $waiter) = @$mark;
60 1 ▶ return unless $pool && $waiter;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool and $waiter 0 1 1
Condition33%1/3
$pool and $waiter
!ll&&!rl&&r
001
MC/DC0%0/2
$pool and $waiter
$pool $waiter
Truth table33%1/3
A and B
A= $poolB= $waiter
ABresult
0X0
100
111
61 1 ▶ $waiter->fail($error) if $pool->_withdraw_waiter($waiter);
Branch: 1 branch
BranchTrueFalseTotal
if $pool->_withdraw_waiter($waiter) 1 0 1
62 1 return;
63 }
64  
65 44 1;
66  
67 __END__
« blib/lib/DBIO/Async/Storage.pm ↑ Summary blib/lib/DBIO/Async/Pool.pm »