| 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
Condition50%1/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||
| 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'}
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'}
| |||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||
| 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";}
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";}
| |||||||||||||||||||||||||||||||||||||||
| 36 | @mro[ $at + 1 .. $#mro ]; | ||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | 14 | ▶ | $self->_refuse_undeclared_driver( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$given or $decided_later
$backend // "DBIO::Storage::DBI"
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
Truth table50%1/2
A
A= $backend
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 55 | 13 | my $storage = $self->storage; | |||||||||||||||||||||||||||||||||||||
| 56 | 13 | ▶ | if ($storage && !$storage->isa('DBIO::Replicated::Storage')) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$storage and not $storage->isa("DBIO::Replicated::Storage")
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")
| |||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||