blib/lib/DBIO/Async/Pool.pm

filter: Statementstmt 100% 47 / 47 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 1 / 1 totaltotal 95.0% 76 / 80 CC 8 SCAR 5.5
CC
8
Cov
95%
_retire_connection
3.0
new
2.0
_create_connection
2.0
CRAP 1.7
« blib/lib/DBIO/Async/Future.pm ↑ Summary blib/lib/DBIO/Async.pm »
1 package DBIO::Async::Pool;
2 # ABSTRACT: Generic async connection pool for DBIO drivers
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 'DBIO::Storage::PoolBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 44 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 44 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 44 ▶use DBIO::Async::Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 44 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17  
18 313 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
19 313 my ($class, %args) = @_;
20 313 ▶ croak('storage required') unless $args{storage};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"storage"} 0 313 313
21  
22 # Handed on to core: it reads the pool's limits (acquire_timeout, max_waiters,
23 # reset_timeout) off the storage, and keeps the reference weak.
24 313 return $class->SUPER::new(%args);
25 }
26  
27  
28 383 ▶sub _connection_ready_future {
Subroutine _connection_ready_future: called CC=1 SCAR=0.0
29 383 my ($self, $conn) = @_;
30 383 return $self->_await_conn_ready($conn);
31 }
32  
33  
34 383 ▶sub _await_conn_ready {
Subroutine _await_conn_ready: called CC=2 SCAR=6.9
35 383 my ($self, $conn) = @_;
36 # No `use Future` in this file on purpose: DBIO::Storage::PoolBase::new
37 # require()s whatever future_class names, so the CONFIGURED class -- not just
38 # the default -- is loaded before any instance method can run.
39 383 ▶ return $self->future_class->done($conn) unless $self->{storage};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"storage"} 1 382 383
40 382 return $self->{storage}->_await_conn_ready($conn);
41 }
42  
43  
44 60 ▶sub _idle_connection_alive {
Subroutine _idle_connection_alive: called CC=2 SCAR=6.9
45 60 my ($self, $conn) = @_;
46 60 ▶ return 1 unless $self->{storage};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"storage"} 2 58 60
47 58 return $self->{storage}->_idle_connection_alive($conn);
48 }
49  
50  
51 29 ▶sub _new_waiter {
Subroutine _new_waiter: called CC=1 SCAR=0.0
52 29 my ($self) = @_;
53 29 return DBIO::Async::Future->new->mark_pool_wait($self);
54 }
55  
56  
57 315 ▶sub _create_connection {
Subroutine _create_connection: called CC=2 SCAR=7.1
58 315 my ($self, $conninfo) = @_;
59 315 ▶ croak 'Storage reference lost; cannot create connection' unless $self->{storage};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"storage"} 0 315 315
60 315 return $self->{storage}->_create_pool_connection($conninfo);
61 }
62  
63  
64 269 ▶sub _shutdown_connection {
Subroutine _shutdown_connection: called CC=2 SCAR=6.9
65 269 my ($self, $conn) = @_;
66 269 ▶ return unless $self->{storage};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"storage"} 1 268 269
67 268 $self->{storage}->_abandon_flights_on($conn);
68 268 $self->{storage}->_shutdown_pool_connection($conn);
69 }
70  
71  
72 69 ▶sub _retire_connection {
Subroutine _retire_connection: called CC=3 SCAR=11.0
73 69 my ($self, $conn) = @_;
74 69 $self->SUPER::_retire_connection($conn);
75 # The pool's own flag: during shutdown the pool fails its callers with its
76 # own reason and cancels the chain on the readiness Future itself.
77 69 ▶ $self->{storage}->_ready_end($conn) if $self->{storage} && !$self->{_shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"storage"} and not $self->{"_shutdown"} 63 6 69
Condition66%2/3
$self->{"storage"} and not $self->{"_shutdown"}
!ll&&!rl&&r
0663
MC/DC50%1/2
$self->{"storage"} and not $self->{"_shutdown"}
$self->{"storage"} not $self->{"_shutdown"}
Truth table66%2/3
A and not(B)
A= $self->{"storage"}B= not $self->{"_shutdown"}
ABresult
0X0
100
111
78 69 return;
79 }
80  
81 44 1;
82  
83 __END__
« blib/lib/DBIO/Async/Future.pm ↑ Summary blib/lib/DBIO/Async.pm »