blib/lib/DBIO/Replicated.pm

filter: Statementstmt 100% 39 / 39 Branchbran 83.3% 10 / 12 Conditioncond 76.1% 16 / 21 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 85.7% 78 / 91 CC 15 SCAR 25.1
CC
15
Cov
90%
connection
15.3
BEGIN
1.0
BEGIN
1.0
CRAP 12.3
« blib/lib/DBIO/Admin.pm ↑ Summary blib/lib/DBIO/Replicated/Pool.pm »
1 package DBIO::Replicated;
2 # ABSTRACT: Replicated storage support for DBIO
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.900007';
8  
9 6 ▶use base 'DBIO::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 14 ▶sub connection {
Subroutine connection: called CC=15 SCAR=27.3
Pod documented
13 14 my ($self, @info) = @_;
14  
15 # The master and every replicant are storages of the declared driver
16 # (ADR 0067), read before the storage class becomes the replicated one. A
17 # repeated connect finds the replicated storage_type set here, and the
18 # driver in its arguments.
19 14 my ($declared, $args) = $self->_resolved_storage_type;
20 14 my $replicated = $declared eq 'DBIO::Replicated::Storage';
21 14 ▶ my $backend = $replicated ? ($args || {})->{backend_storage_class} : $declared;
Branch: 1 branch
BranchTrueFalseTotal
$replicated ? : 2 12 14
Condition50%1/2
$args || {}
l!l
20
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
22  
23 # backend_storage_class in the connect info wins, and is a declaration too.
24 my $given = grep {
25 14 ref $_ eq 'HASH' && defined $_->{backend_storage_class}
26 49 ▶ } @info;
Condition100%3/3
ref $_ eq 'HASH' && defined $_->{'backend_storage_class'}
!ll&&!rl&&r
4216
MC/DC100%2/2
ref $_ eq 'HASH' && defined $_->{'backend_storage_class'}
ref $_ eq 'HASH' defined $_->{'backend_storage_class'}
Truth table100%3/3
A && B
A= ref $_ eq 'HASH'B= defined $_->{'backend_storage_class'}
ABresult
0X0
100
111
27  
28 # A component after this one with a connection() of its own -- a driver
29 # component loaded after Replicated -- decides the storage class itself;
30 # that order is refused below, naming the class it set.
31 14 my $decided_later = do {
32 14 ▶ my @mro = @{ mro::get_linear_isa(ref $self || $self) };
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
1220
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
33 14 my ($at) = grep { $mro[$_] eq __PACKAGE__ } 0 .. $#mro;
34 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 14 ▶ grep { $_ ne 'DBIO::Schema' && defined &{"${_}::connection"} }
Condition100%3/3
$_ ne 'DBIO::Schema' && defined &{"${_}::connection";}
!ll&&!rl&&r
14561
MC/DC100%2/2
$_ ne 'DBIO::Schema' && defined &{"${_}::connection";}
$_ ne 'DBIO::Schema' defined &{"${_}::connection";}
Truth table100%3/3
A && B
A= $_ ne 'DBIO::Schema'B= defined &{"${_}::connection";}
ABresult
0X0
100
111
36 @mro[ $at + 1 .. $#mro ];
37 };
38  
39 14 ▶ $self->_refuse_undeclared_driver(
Branch: 1 branch
BranchTrueFalseTotal
unless $given or $decided_later 7 7 14
Condition80%4/5
$given or $decided_later
l!l&&r!l&&!r
617
$backend // "DBIO::Storage::DBI"
l!l
70
MC/DC100%2/2
$given or $decided_later
$given $decided_later
MC/DC0%0/1
$backend // "DBIO::Storage::DBI"
$backend
Truth table100%3/3
A or B
A= $givenB= $decided_later
ABresult
1X1
011
000
Truth table50%1/2
A
A= $backend
Aresult
11
00
40 $backend // 'DBIO::Storage::DBI',
41 'DBIO::Replicated runs the master and every replicant on the driver the '
42 . 'schema declares when it connects: declare it with the shortcut, or load '
43 . 'the driver component before Replicated: '
44 . 'load_components(qw(PostgreSQL Replicated)).',
45 ) unless $given or $decided_later;
46  
47 $self->storage_type([ '+DBIO::Replicated::Storage', {
48 13 ▶ ( $replicated ? %{ $args || {} } : () ),
Branch: 2 branches
BranchTrueFalseTotal
$replicated ? : 2 11 13
defined $backend ? : 13 0 13
Condition50%1/2
$args || {}
l!l
20
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
49 ( defined $backend ? ( backend_storage_class => $backend ) : () ),
50 } ]);
51  
52 13 my $ret = $self->next::method(@info);
53  
54 13 ▶ if (@info) {
Branch: 1 branch
BranchTrueFalseTotal
if (@info) 13 0 13
55 13 my $storage = $self->storage;
56 13 ▶ if ($storage && !$storage->isa('DBIO::Replicated::Storage')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storage and not $storage->isa("DBIO::Replicated::Storage")) 1 12 13
Condition66%2/3
$storage and not $storage->isa("DBIO::Replicated::Storage")
!ll&&!rl&&r
0121
MC/DC50%1/2
$storage and not $storage->isa("DBIO::Replicated::Storage")
$storage not $storage->isa("DBIO::Replicated::Storage")
Truth table66%2/3
A and not(B)
A= $storageB= not $storage->isa("DBIO::Replicated::Storage")
ABresult
0X0
100
111
57 1 my $class = ref $storage;
58 1 $self->storage(undef);
59 1 $self->throw_exception(
60 "DBIO::Replicated is loaded before the driver component, whose "
61 . "storage class ($class) took the place of DBIO::Replicated::Storage "
62 . "and left the schema without replication. Load the driver component "
63 . "first and Replicated last: "
64 . "load_components(qw(PostgreSQL Replicated))"
65 );
66 }
67 }
68  
69 12 return $ret;
70 }
71  
72 6 1;
73  
74 __END__
« blib/lib/DBIO/Admin.pm ↑ Summary blib/lib/DBIO/Replicated/Pool.pm »