| 1 | package DBIO::Storage; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Generic Storage Handler | ||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 345 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 345 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 345 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 345 | ▶ | use base qw/DBIO::Base/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 345 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | DBIO::Storage::NESTED_ROLLBACK_EXCEPTION; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 345 | ▶ | use base 'DBIO::Exception'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 345 | ▶ | use DBIO::Carp; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 345 | ▶ | use DBIO::Storage::BlockRunner; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 345 | ▶ | use Scalar::Util qw/blessed weaken/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 345 | ▶ | use DBIO::Storage::TxnScopeGuard; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 345 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 345 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 345 | __PACKAGE__->mk_group_accessors(simple => qw/ | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | debug schema transaction_depth deferred_rollback auto_savepoint savepoints | ||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | access_broker access_broker_mode | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | /); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 345 | __PACKAGE__->mk_group_accessors(component_class => 'cursor_class'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 345 | __PACKAGE__->cursor_class('DBIO::Cursor'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub cursor { shift->cursor_class(@_); } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cursor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3724 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3724 | my ($self, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3724 | ▶ | $self = ref $self if ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3724 | my $new = bless( { | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | transaction_depth => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | savepoints => [], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | }, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3724 | $new->set_schema($schema); | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | $new->debug($self->_trace_level_of($ENV{DBIO_TRACE})) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3724 | ▶ | if $ENV{DBIO_TRACE}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3724 | $new; | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # The trace level a flag stands for: its leading digits (2=/path is level 2), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # level 1 for any other true value, 0 for a false one. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1550 | ▶ | sub _trace_level_of { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trace_level_of: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1550 | my ($class, $flag) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1550 | ▶ | return 0 unless $flag; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 72 | ▶ | return $flag =~ /^(\d+)/ ? $1 + 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3732 | ▶ | sub set_schema { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_schema: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3732 | my ($self, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3732 | $self->schema($schema); | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3732 | ▶ | weaken $self->{schema} if ref $self->{schema}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 721 | ▶ | sub set_access_broker { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_access_broker: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 721 | my ($self, $broker, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 721 | ▶ | $self->throw_exception('set_access_broker() requires a broker object') | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | unless blessed($broker); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 704 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 'set_access_broker() requires a DBIO::AccessBroker instance' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ) unless $broker->isa('DBIO::AccessBroker'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # A broker that is replaced lets go of this storage first, so it does not | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # go on answering for a storage that no longer uses it (karr k278). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 695 | my $old = $self->access_broker; | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 695 | ▶ | $old->unset_storage($self) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($old) and $old->can("unset_storage")
MC/DC50%1/2
builtin::blessed($old) and $old->can("unset_storage")
builtin::blessed($old)
$old->can("unset_storage")
Truth table66%2/3
A and B
A= builtin::blessed($old)B= $old->can("unset_storage")
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | if blessed($old) && $old->can('unset_storage'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 695 | $self->access_broker($broker); | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 695 | ▶ | $self->access_broker_mode($mode || 'write'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mode || 'write'
MC/DC100%1/1
$mode || 'write'
$mode
Truth table100%2/2
A
A= $mode
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 695 | $broker->set_storage($self); | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 695 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2414 | ▶ | sub clear_access_broker { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_access_broker: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2414 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2414 | my $broker = $self->access_broker; | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2414 | ▶ | $broker->unset_storage($self) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($broker) and $broker->can("unset_storage")
MC/DC50%1/2
builtin::blessed($broker) and $broker->can("unset_storage")
builtin::blessed($broker)
$broker->can("unset_storage")
Truth table66%2/3
A and B
A= builtin::blessed($broker)B= $broker->can("unset_storage")
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | if blessed($broker) && $broker->can('unset_storage'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2414 | $self->access_broker(undef); | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2414 | $self->access_broker_mode(undef); | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2414 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1431 | ▶ | sub current_access_broker_connect_info { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_access_broker_connect_info: called CC=15 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1431 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1431 | ▶ | my $broker = $self->access_broker or return; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1430 | ▶ | $mode ||= $self->access_broker_mode || 'write'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition20%1/5
$mode ||= $self->access_broker_mode || "write"
$self->access_broker_mode || 'write'
MC/DC0%0/2
$mode ||= $self->access_broker_mode || "write"
$mode
$self->access_broker_mode
Truth table33%1/3
A ||= B
A= $modeB= $self->access_broker_mode
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1430 | my $answer = $broker->current_connect_info_for_storage($self, $mode); | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1373 | ▶ | my $nothing = !defined $answer ? 'undef' | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
ref $answer || $answer
MC/DC100%2/2
ref $answer || $answer
ref $answer
$answer
Truth table100%3/3
A || B
A= ref $answerB= $answer
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | : ref $answer eq 'HASH' ? (%$answer ? undef : 'an empty hashref') | ||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | : ref $answer eq 'ARRAY' ? (@$answer ? undef : 'an empty arrayref') | ||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | : !ref $answer && !$answer ? 'a false value' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1373 | ▶ | return $answer unless defined $nothing; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # A view (HostBound) answers nothing only when the broker it wraps did. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 45 | my ($answered, @views) = ($broker); | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 45 | ▶ | while ($answered->can('underlying_broker')) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 10 | ▶ | my $inner = $answered->underlying_broker or last; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | push @views, ref $answered; | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | $answered = $inner; | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 45 | ▶ | 'AccessBroker ' . ref($answered) . " answered no connect info ($nothing)" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | . (@views ? ' through ' . join(' over ', @views) : '') . '. ' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | . "A new connection is opened only with the broker's current answer, never " | ||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | . 'with the connect info of an earlier one.' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # One rule for a setting that a connection gets both from the hash beside its | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # AccessBroker ([ $broker, \%options ]) and from the broker's answer (ADR 0030 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # addendum, karr k243): both must name the same value -- the same plain value, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # both undef, or the very same reference -- or this throws, naming the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # setting (never its values, which may carry secrets). Returns the merged | ||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # hashref; neither argument is modified. Shared by the sync storage and by an | ||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # async transport merging the same settings into each connection it opens. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 334 | ▶ | sub _merge_access_broker_settings { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_access_broker_settings: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 334 | my ($self, $answer, $beside) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 334 | ▶ | my %merged = %{ $answer || {} }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$answer || {}
MC/DC100%1/1
$answer || {}
$answer
Truth table100%2/2
A
A= $answer
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 334 | ▶ | for my $key (sort keys %{ $beside || {} }) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$beside || {}
MC/DC0%0/1
$beside || {}
$beside
Truth table50%1/2
A
A= $beside
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 360 | my $value = $beside->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | "Connection setting '$key' is given both beside the AccessBroker and in " | ||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | . "the broker's answer, with different values. Give it in one place, or " | ||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | . 'give both the same value.' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 360 | ▶ | ) if exists $merged{$key} && !_same_access_broker_setting($merged{$key}, $value); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $merged{$key} and not _same_access_broker_setting($merged{$key}, $value)
MC/DC100%2/2
exists $merged{$key} and not _same_access_broker_setting($merged{$key}, $value)
exists $merged{$key}
not _same_access_broker_setting($merged{$key}, $value)
Truth table100%3/3
A and not(B)
A= exists $merged{$key}B= not _same_access_broker_setting($merged{$key}, $value)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 347 | $merged{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 321 | return \%merged; | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | ▶ | sub _same_access_broker_setting { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_same_access_broker_setting: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 17 | my ($x, $y) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 17 | ▶ | return !defined $y if !defined $x; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 17 | ▶ | return 0 if !defined $y; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | ▶ | return 0 if !!ref $x != !!ref $y; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 17 | ▶ | return ref $x ? Scalar::Util::refaddr($x) == Scalar::Util::refaddr($y) : $x eq $y; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub connected { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connected: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub disconnect { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub ensure_connected { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensure_connected: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1620 | ▶ | sub throw_exception { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_exception: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1620 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1620 | ▶ | if (ref $self and $self->schema) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $self and $self->schema
MC/DC100%2/2
ref $self and $self->schema
ref $self
$self->schema
Truth table100%3/3
A and B
A= ref $selfB= $self->schema
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 767 | $self->schema->throw_exception(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 853 | DBIO::Exception->throw(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 111 | ▶ | sub txn_do { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_do: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 111 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 111 | ▶ | $self->_throw_deferred_rollback if $self->deferred_rollback; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | DBIO::Storage::BlockRunner->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | storage => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | wrap_txn => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 47 | ▶ | retry_handler => sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 47 | ▶ | $_[0]->failed_attempt_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | and | ||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ! $_[0]->storage->connected | ||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 111 | )->run(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 932 | ▶ | sub txn_begin { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_begin: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 932 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 932 | ▶ | $self->_throw_deferred_rollback if $self->deferred_rollback; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 932 | $self->_assert_transaction_safe_access_broker; | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 932 | ▶ | if($self->transaction_depth == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 233 | ▶ | $self->debugobj->txn_begin() | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 233 | $self->_exec_txn_begin; | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | elsif ($self->auto_savepoint) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | $self->svp_begin; | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 932 | $self->{transaction_depth}++; | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2588 | ▶ | sub _assert_transaction_safe_access_broker { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_transaction_safe_access_broker: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2588 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2588 | ▶ | return if $self->{_access_broker_txn_safety_checked}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1658 | ▶ | return if $self->transaction_depth; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 959 | ▶ | my $broker = $self->access_broker or return; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 59 | ▶ | return if $broker->is_transaction_safe; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 47 | my @reasons; | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 47 | ▶ | push @reasons, 'credential rotation' if $broker->has_rotating_credentials; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 47 | ▶ | my $reason = @reasons | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ? join(' and ', @reasons) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | : 'broker-specific transaction safety constraints'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 47 | ▶ | if ($ENV{DBIO_ALLOW_UNSAFE_BROKER_TRANSACTIONS}) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 19 | ▶ | carp sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $broker || $broker
MC/DC0%0/2
ref $broker || $broker
ref $broker
$broker
Truth table33%1/3
A || B
A= ref $brokerB= $broker
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 'Starting a transaction with unsafe AccessBroker %s via override: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ref($broker) || $broker, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | $reason, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 28 | ▶ | $self->throw_exception(sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $broker || $broker
MC/DC0%0/2
ref $broker || $broker
ref $broker
$broker
Truth table33%1/3
A || B
A= ref $brokerB= $broker
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 'Refusing to start a transaction with unsafe AccessBroker %s: %s can break transactional consistency', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ref($broker) || $broker, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | $reason, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 842 | ▶ | sub txn_commit { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_commit: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 842 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 842 | ▶ | $self->_throw_deferred_rollback if $self->deferred_rollback; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 842 | ▶ | if ($self->transaction_depth == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 150 | ▶ | $self->debugobj->txn_commit() if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 150 | ▶ | unless (eval { $self->_exec_txn_commit; 1 }) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 9 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 9 | $self->_abandon_after_failed_commit; | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 9 | die $err; | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 141 | $self->{transaction_depth}--; | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 141 | $self->savepoints([]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | elsif($self->transaction_depth > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 692 | $self->{transaction_depth}--; | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 692 | ▶ | $self->svp_release if $self->auto_savepoint; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->throw_exception( 'Refusing to commit without a started transaction' ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 86 | ▶ | sub txn_rollback { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_rollback: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 86 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 86 | ▶ | if ($self->transaction_depth == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 78 | ▶ | $self->debugobj->txn_rollback() if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # a rollback that fails leaves nothing to rely on: the transaction may | ||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # still be open on the server. Do not keep claiming depth 1 on it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 78 | ▶ | unless (eval { $self->_exec_txn_rollback; 1 }) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 11 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 11 | $self->_abandon_after_failed_rollback; | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 11 | die $err; | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 67 | $self->{transaction_depth}--; | |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 67 | $self->savepoints([]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 67 | $self->deferred_rollback(undef); | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | elsif ($self->transaction_depth > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | $self->{transaction_depth}--; | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 7 | ▶ | if ($self->auto_savepoint) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $self->svp_rollback; | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $self->svp_release; | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 7 | $self->deferred_rollback(1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 7 | DBIO::Storage::NESTED_ROLLBACK_EXCEPTION->throw( | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | "A txn_rollback in nested transaction is ineffective! (depth $self->{transaction_depth})" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | $self->throw_exception( 'Refusing to roll back without a started transaction' ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | ▶ | sub _abandon_after_failed_rollback { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_abandon_after_failed_rollback: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | $self->{transaction_depth} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | $self->savepoints([]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | $self->deferred_rollback(undef); | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 9 | ▶ | sub _abandon_after_failed_commit { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_abandon_after_failed_commit: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 9 | $self->{transaction_depth} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 9 | $self->savepoints([]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 9 | $self->deferred_rollback(undef); | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 9 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | $self->_abandon_after_failed_rollback | ||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 9 | ▶ | unless eval { $self->_exec_txn_rollback; 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | sub _abandon_handle_before_reconnect { } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_abandon_handle_before_reconnect: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | sub _throw_deferred_rollback { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw_deferred_rollback: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | DBIO::Storage::NESTED_ROLLBACK_EXCEPTION->throw( | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | "You are in the middle of a deferred rollback from a nested transaction." | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ." No further statements can be executed until the rollback is complete." | ||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | sub svp_begin { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp_begin: called CC=6 SCAR=19.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | ▶ | $self->throw_exception ("You can't use savepoints outside a transaction") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | unless $self->transaction_depth; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | my $exec = $self->can('_exec_svp_begin') | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | or $self->throw_exception ("Your Storage implementation doesn't support savepoints"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # This could happen if savepoints were not enabled at the time rollback was called | ||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | $self->_throw_deferred_rollback if $self->deferred_rollback; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | $name = $self->_svp_generate_name | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | unless defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | push @{ $self->{savepoints} }, $name; | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | ▶ | $self->debugobj->svp_begin($name) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | $exec->($self, $name); | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | ▶ | sub _svp_generate_name { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_svp_generate_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | return 'savepoint_'.scalar(@{ $self->{'savepoints'} }); | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | sub svp_release { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp_release: called CC=9 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | $self->throw_exception ("You can't use savepoints outside a transaction") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | unless $self->transaction_depth; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | my $exec = $self->can('_exec_svp_release') | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | or $self->throw_exception ("Your Storage implementation doesn't support savepoints"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # This could happen if savepoints were not enabled at the time rollback was called | ||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | ▶ | $self->_throw_deferred_rollback if $self->deferred_rollback; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my @stack = @{ $self->savepoints }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $svp = ''; | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | while( $svp ne $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | $self->throw_exception ("Savepoint '$name' does not exist") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $svp = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->savepoints(\@stack); # put back what's left | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | $name = pop @{ $self->savepoints } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | or $self->throw_exception('No savepoints to release');; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | $self->debugobj->svp_release($name) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | $exec->($self, $name); | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | sub svp_rollback { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp_rollback: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | $self->throw_exception ("You can't use savepoints outside a transaction") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | unless $self->transaction_depth; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | my $exec = $self->can('_exec_svp_rollback') | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | or $self->throw_exception ("Your Storage implementation doesn't support savepoints"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # This could happen if savepoints were not enabled at the time rollback was called | ||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | $self->_throw_deferred_rollback if $self->deferred_rollback; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my @stack = @{ $self->savepoints }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $svp; | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # a rollback doesn't remove the named savepoint, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # only everything after it | ||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | while (@stack and $stack[-1] ne $name) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@stack and $stack[-1] ne $name
MC/DC0%0/2
@stack and $stack[-1] ne $name
@stack
$stack[-1] ne $name
Truth table0%0/3
A and B
A= @stackB= $stack[-1] ne $name
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | pop @stack | ||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $self->throw_exception ("Savepoint '$name' does not exist") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $self->savepoints(\@stack); # put back what's left | |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $name = $self->savepoints->[-1] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | or $self->throw_exception('No savepoints to rollback');; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | $self->debugobj->svp_rollback($name) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $exec->($self, $name); | |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 798 | ▶ | sub txn_scope_guard { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_scope_guard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 798 | return DBIO::Storage::TxnScopeGuard->new($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub sql_maker { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_maker: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 3 | ▶ | sub debugfh { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debugfh: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 3 | ▶ | if ($self->debugobj->can('debugfh')) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | return $self->debugobj->debugfh(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 14117 | ▶ | sub debugobj { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debugobj: called CC=5 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 14117 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 14117 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 113 | return $self->{debugobj} = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 14004 | ▶ | $self->{debugobj} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"debugobj"} ||= do {
if (my $profile = $ENV{"DBIO_TRACE_PROFILE"}) {
require DBIO::Storage::Debug::PrettyTrace;
my @pp_args;
if ($profile =~ m[^\.?/]) {
require Config::Any;
my $cfg = &try(sub {
"Config::Any"->load_files({"files", [$profile], "use_ext", 1});
}
, &catch(sub {
$_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x;
$self->throw_exception("Failure processing \$ENV{DBIO_TRACE_PROFILE}: $_");
}
));
@pp_args = values %{$$cfg[0];};
}
else {
@pp_args = {"profile", $profile};
};
&try(sub {
"DBIO::Storage::Debug::PrettyTrace"->new(@pp_args);
}
, &catch(sub {
$self->throw_exception($_);
}
));
}
else {
require DBIO::Storage::Statistics;
"DBIO::Storage::Statistics"->new;
}
}
MC/DC0%0/2
$self->{"debugobj"} ||= do {
if (my $profile = $ENV{"DBIO_TRACE_PROFILE"}) {
require DBIO::Storage::Debug::PrettyTrace;
my @pp_args;
if ($profile =~ m[^\.?/]) {
require Config::Any;
my $cfg = &try(sub {
"Config::Any"->load_files({"files", [$profile], "use_ext", 1});
}
, &catch(sub {
$_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x;
$self->throw_exception("Failure processing \$ENV{DBIO_TRACE_PROFILE}: $_");
}
));
@pp_args = values %{$$cfg[0];};
}
else {
@pp_args = {"profile", $profile};
};
&try(sub {
"DBIO::Storage::Debug::PrettyTrace"->new(@pp_args);
}
, &catch(sub {
$self->throw_exception($_);
}
));
}
else {
require DBIO::Storage::Statistics;
"DBIO::Storage::Statistics"->new;
}
}
$self->{"debugobj"}
do {
if (my $profile = $ENV{"DBIO_TRACE_PROFILE"}) {
require DBIO::Storage::Debug::PrettyTrace;
my @pp_args;
if ($profile =~ m[^\.?/]) {
require Config::Any;
my $cfg = &try(sub {
"Config::Any"->load_files({"files", [$profile], "use_ext", 1});
}
, &catch(sub {
$_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x;
$self->throw_exception("Failure processing \$ENV{DBIO_TRACE_PROFILE}: $_");
}
));
@pp_args = values %{$$cfg[0];};
}
else {
@pp_args = {"profile", $profile};
};
&try(sub {
"DBIO::Storage::Debug::PrettyTrace"->new(@pp_args);
}
, &catch(sub {
$self->throw_exception($_);
}
));
}
else {
require DBIO::Storage::Statistics;
"DBIO::Storage::Statistics"->new;
}
}
Truth table66%2/3
A ||= B
A= $self->{"debugobj"}B= do {
if (my $profile = $ENV{"DBIO_TRACE_PROFILE"}) {
require DBIO::Storage::Debug::PrettyTrace;
my @pp_args;
if ($profile =~ m[^\.?/]) {
require Config::Any;
my $cfg = &try(sub {
"Config::Any"->load_files({"files", [$profile], "use_ext", 1});
}
, &catch(sub {
$_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x;
$self->throw_exception("Failure processing \$ENV{DBIO_TRACE_PROFILE}: $_");
}
));
@pp_args = values %{$$cfg[0];};
}
else {
@pp_args = {"profile", $profile};
};
&try(sub {
"DBIO::Storage::Debug::PrettyTrace"->new(@pp_args);
}
, &catch(sub {
$self->throw_exception($_);
}
));
}
else {
require DBIO::Storage::Statistics;
"DBIO::Storage::Statistics"->new;
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 492 | ▶ | if (my $profile = $ENV{DBIO_TRACE_PROFILE}) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | require DBIO::Storage::Debug::PrettyTrace; | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my @pp_args; | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ($profile =~ /^\.?\//) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | require Config::Any; | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | my $cfg = try { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | Config::Any->load_files({ files => [$profile], use_ext => 1 }); | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # sanitize the error message a bit | ||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x; | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $self->throw_exception("Failure processing \$ENV{DBIO_TRACE_PROFILE}: $_"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | @pp_args = values %{$cfg->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | @pp_args = { profile => $profile }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # FIXME - FRAGILE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # Hash::Merge is a sorry piece of shit and tramples all over $@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # *without* throwing an exception | ||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # This is a rather serious problem in the debug codepath | ||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # Insulate the condition here with a try{} until a review of | ||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # DBIO::Storage::Debug::PrettyTrace takes place | ||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # we do rethrow the error unconditionally, the only reason | ||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # to try{} is to preserve the precise state of $@ (down | ||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # to the scalar (if there is one) address level) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # Yes I am aware this is fragile and TxnScopeGuard needs | ||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # a better fix. This is another yak to shave... :( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | DBIO::Storage::Debug::PrettyTrace->new(@pp_args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | $self->throw_exception($_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 492 | require DBIO::Storage::Statistics; | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 492 | DBIO::Storage::Statistics->new | |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 16 | ▶ | sub debugcb { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debugcb: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 16 | ▶ | if ($self->debugobj->can('callback')) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 16 | return $self->debugobj->callback(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | sub deploy { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | sub connect_info { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # --- DBIO-private connect attributes ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # Single authoritative source for the attribute names a caller may pass in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # connect_info that are DBIO-private and must NEVER reach DBI->connect. Both | ||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # connect-info paths consume these lists -- the sync normalizer | ||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # (DBIO::Storage::DBI::_normalize_connect_info) and the async strip | ||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # (DBIO::Storage::Async::connect_info) -- so the two paths can never drift on | ||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # what counts as DBIO-private. They live on this shared base (the common | ||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # ancestor of both DBI and Async storage) rather than on DBIO::Storage::DBI, so | ||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # the async base can reach them without a new Async->DBI dependency direction. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # Storage-config options: routed to the storage, kept out of DBI->connect. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # (cursor_class is a storage option too, but carries its own component_class | ||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # accessor, so it is appended at the split sites rather than listed here.) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # A driver storage may extend this -- override, return | ||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # SUPER::_dbio_storage_option_names plus the driver's own names, and register | ||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # an accessor for each added name in the driver class body | ||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # (mk_group_accessors 'simple'), because both split sites set the option by | ||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # calling that accessor -- the one _dbio_storage_option_accessor names. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 6147 | ▶ | sub _dbio_storage_option_names { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbio_storage_option_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 6147 | qw/ | |||||||||||||||||||||||||||||||||||||||||||||||
| 563 | on_connect_call on_disconnect_call on_connect_do on_disconnect_do | ||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | disable_sth_caching unsafe auto_savepoint schema | ||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | /; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # An option is set through the accessor of its own name, unless it is listed | ||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # here: 'schema' (the connection's namespace, ADR 0065) shares its name with the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # accessor holding the back-reference to the DBIO schema class, so it is kept | ||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # under connection_schema. The map lives once, beside the names; the sync | ||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # normaliser, the connect_info setter and the accessor registration all ask | ||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # _dbio_storage_option_accessor. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 21861 | ▶ | sub _dbio_storage_option_accessor_map { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbio_storage_option_accessor_map: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 21861 | schema => 'connection_schema', | |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 21861 | ▶ | sub _dbio_storage_option_accessor { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbio_storage_option_accessor: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 21861 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 21861 | my %map = $self->_dbio_storage_option_accessor_map; | |||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 21861 | ▶ | return $map{$name} // $name; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$map{$name} // $name
MC/DC0%0/2
$map{$name} // $name
$map{$name}
$name
Truth table66%2/3
A // B
A= $map{$name}B= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # Async options (karr core k397): the connect options an async backend takes. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # With an async mode set they are kept out of the sync storage's own | ||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # DBI->connect and handed to the backend. This is the one place the core names | ||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # are listed; a backend adds its own through | ||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # DBIO::Storage::Async->async_option_names, and the sync storage asks | ||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # DBIO::Storage::DBI::_async_option_names for the union. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 428 | ▶ | sub _core_async_option_names { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_core_async_option_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 428 | qw/ pool_size acquire_timeout max_waiters txn_timeout reset_timeout /; | |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # SQL-maker options: routed to the sql_maker, kept out of DBI->connect. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 3445 | ▶ | sub _dbio_sql_maker_option_names { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbio_sql_maker_option_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 3445 | qw/ quote_char name_sep quote_names /; | |||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | sub select { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | sub insert { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | sub update { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub delete { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | sub select_single { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_single: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # The force_pool value the read of a read-then-write call (find_or_create, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | # find_or_new, update_or_create, update_or_new, the upsert fallback) carries in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | # its attributes. Nothing by default; DBIO::Replicated::Storage answers 'master'. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 901 | ▶ | sub _read_pool_for_read_modify_write { undef } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_pool_for_read_modify_write: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # Live async backend (a DBIO::Storage::Async) or undef when none configured. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # Overridden in DBIO::Storage::DBI to do real discovery. Base = no backend. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | sub _async_storage { undef } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_async_storage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # The connect-time async mode name (ADR 0030), or undef for a sync instance. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | # Overridden by the _async_mode accessor on DBIO::Storage::DBI; the base stub | ||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # keeps non-DBI storages on the sync path (their *_async croak). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | sub _async_mode { undef } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_async_mode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # Shared dispatch for the six *_async methods (ADR 0030). Three outcomes: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # - an embedded backend is live -> route ${op}_async to it (real async) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # - the instance is in 'immediate' -> run $op synchronously, wrap the result | ||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # mode (no backend, mode chosen) in an immediately-resolved future | ||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # - the instance is sync -> croak loudly: *_async was called but no | ||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # (no async mode chosen) async mode was chosen at connect time | ||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # _async_storage croaks on its own for a chosen-but-unavailable or wrong-type | ||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # mode; the guard below also makes any future undef backend fail closed unless | ||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # its literal mode is 'immediate'. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 153 | ▶ | sub _run_async { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_async: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 153 | my ($self, $op, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 153 | ▶ | if (my $async = $self->_async_storage) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 42 | my $method = "${op}_async"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 42 | return $async->$method(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 108 | my $mode = $self->_async_mode; | |||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 108 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | "not an async connection -- connect with { async => ... } to use ${op}_async" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | ) unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 104 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | "async mode '$mode' did not produce a DBIO::Storage::Async backend" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | ) unless $mode eq 'immediate'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 104 | my $fc = $self->future_class; | |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 104 | my @r = eval { $self->_run_immediate($op, @args) }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 104 | ▶ | return $fc->done(@r) unless $@; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 39 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | # Inside an immediate txn_do_async this failed Future is a statement the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # transaction's context handed out: its failure fails the transaction, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | # awaited or not (_run_immediate_txn, karr k236). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 39 | $self->_note_immediate_failure($error); | |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 39 | return $fc->fail($error); | |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # The failed-statement ledger of an immediate txn_do_async (karr k236, k331): | ||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # every failed *_async Future inside the transaction lands here, from the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | # storage's own _run_async and from the unbound Row/ResultSet paths, which | ||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | # build their failed Future themselves. No-op outside such a transaction. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 51 | ▶ | sub _note_immediate_failure { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_note_immediate_failure: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 51 | my ($self, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 12 | push @{ $self->{_immediate_txn_failures} }, $error | |||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 51 | ▶ | if $self->{_immediate_txn_failures}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 51 | return; | |||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # Produce the 'immediate'-mode result for one *_async op (ADR 0053). The value | ||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # a storage-level *_async resolves with is backend-independent: it is the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # transport form a real DBIO::Storage::Async backend resolves with -- the raw | ||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | # form the ORM inflation consumes -- NOT whatever the synchronous method happens | ||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # to hand back. In immediate mode there is no backend, so the sync op runs | ||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # in-process here; its return is then shaped to that canonical form. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # For most ops the synchronous return already IS the canonical form -- insert | ||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # gives the returned-columns hashref, update/delete the affected-row count -- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # so they pass through untouched. The two reads are the exceptions the ticket | ||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # confirmed: sync select returns a cursor and sync select_single a flat row | ||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # list, whereas the canonical async forms are the raw row arrayrefs a cursor's | ||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # ->all yields (select_async) and a single such arrayref, or undef (select_ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # single_async). Shape exactly those two, matching a real backend by | ||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # construction (cf. the delegating backend in t/resultset/async_backend.t). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # txn_do is the third exception (ADR 0055, karr k207): its callback contract -- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # the context handed in and the adoption of a returned Future -- also has to | ||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # match a real backend, so it routes through _run_immediate_txn rather than the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # bare $self->$op pass-through. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 104 | ▶ | sub _run_immediate { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_immediate: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 104 | my ($self, $op, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 104 | ▶ | if ($op eq 'select') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 8 | return $self->select(@args)->all; | |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | elsif ($op eq 'select_single') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 4 | my @row = $self->select_single(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 4 | ▶ | return @row ? [ @row ] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | elsif ($op eq 'txn_do') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 66 | return $self->_run_immediate_txn(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | elsif ($op eq '_query') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # The raw-SQL seam (DBIO::Storage::DBI::_query_async, karr k282): a | ||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # statement core rendered itself, resolving with its rows. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 1 | my (undef, $sth) = $self->_execute_rendered(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 1 | return @{ $sth->fetchall_arrayref }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 25 | return $self->$op(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # 'immediate'-mode txn_do_async, matching the storage-level txn_do_async | ||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # callback contract of a real DBIO::Storage::Async backend (ADR 0055, karr | ||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # k207). Two axes: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | # 1. Context argument. A real backend calls $coderef->($txn_ctx, @args) with a | ||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # DBIO::Storage::Async::TransactionContext pinned to the transaction | ||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # connection. immediate has no event loop and no pinned connection: the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | # sync op each *_async runs happens IN-PROCESS, already inside the sync | ||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # transaction this wrapper opens -- so the storage itself IS the context, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # and $self->*_async are exactly the methods a real backend's context | ||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | # exposes (the documented portable pattern only ever uses *_async / | ||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # txn_do_async, all present on $self). Hand $self in as the first argument. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # 2. Returned-Future adoption. A real backend's _txn_terminal_chain adopts a | ||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # Future the coderef returns: it commits on the Future's success and | ||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # resolves with its VALUE(S), or rolls back on its failure. Under immediate | ||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # every *_async Future is already resolved, so ->get extracts the value(s) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # without blocking -- and re-raising a failed Future's error as a throw is | ||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # what makes the enclosing sync txn_do roll back, so the commit-on-success | ||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # / rollback-on-failure decision matches too. A plain (non-Future) return | ||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # passes straight through, exactly as $fc->done($inner) would carry it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # 3. A failed statement fails the transaction (karr k236). A real backend | ||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # refuses COMMIT when any statement Future its context handed out failed, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # awaited or not, handled by the coderef or not. Here every *_async on the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # context goes through _run_async, which notes each failure in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # _immediate_txn_failures while this transaction runs; the first one is | ||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # rethrown so the enclosing sync txn_do rolls back -- after a failed | ||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # returned Future, whose own error comes first, as it does there. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # The whole body runs in the list context _run_async invokes it under, so | ||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | # ->get resolves the full value list a multi-value Future carries. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 66 | ▶ | sub _run_immediate_txn { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_immediate_txn: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 66 | my ($self, $coderef, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 65 | ▶ | return $self->txn_do(sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 65 | local $self->{_immediate_txn_failures} = []; | |||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 65 | my $inner = $coderef->($self, @args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 48 | ▶ | my $adopt = blessed($inner) && $inner->can('then') && $inner->can('get'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
builtin::blessed($inner) && $inner->can('then') && $inner->can('get')
builtin::blessed($inner) and $inner->can("then")
MC/DC33%1/3
builtin::blessed($inner) && $inner->can('then') && $inner->can('get')
builtin::blessed($inner)
$inner->can("then")
$inner->can('get')
Truth table50%2/4
A and B && C
A= builtin::blessed($inner)B= $inner->can("then")C= $inner->can('get')
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 48 | ▶ | $inner->get if $adopt && $inner->is_failed; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$adopt and $inner->is_failed
MC/DC100%2/2
$adopt and $inner->is_failed
$adopt
$inner->is_failed
Truth table100%3/3
A and B
A= $adoptB= $inner->is_failed
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | die $self->{_immediate_txn_failures}[0] | ||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 45 | ▶ | if @{ $self->{_immediate_txn_failures} }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 35 | ▶ | return $adopt ? $inner->get : $inner; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 66 | }); | |||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 18 | ▶ | sub select_async { shift->_run_async('select', @_) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 7 | ▶ | sub select_single_async { shift->_run_async('select_single', @_) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_single_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 21 | ▶ | sub insert_async { shift->_run_async('insert', @_) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 6 | ▶ | sub update_async { shift->_run_async('update', @_) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 2 | ▶ | sub delete_async { shift->_run_async('delete', @_) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 98 | ▶ | sub txn_do_async { shift->_run_async('txn_do', @_) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_do_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 768 | ▶ | sub future_class { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
future_class: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 768 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 768 | ▶ | if (ref $self and my $async = $self->_async_storage) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self and my $async = $self->_async_storage
MC/DC50%1/2
ref $self and my $async = $self->_async_storage
ref $self
my $async = $self->_async_storage
Truth table66%2/3
A and B
A= ref $selfB= my $async = $self->_async_storage
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 530 | return $async->future_class; | |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 238 | require DBIO::Future::Immediate; | |||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 238 | 'DBIO::Future::Immediate'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub columns_info_for { die "Virtual method!" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns_info_for: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | # Type registry: maps type names to behavior descriptors, keyed by class so | ||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | # subclasses can add or override entries. Use type_info() for MRO-aware lookup. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 345 | my %_type_registry; | |||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 2752 | ▶ | sub register_type { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 2752 | my ($class, $type_name, $info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 2752 | $_type_registry{$class}{$type_name} = $info; | |||||||||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 636 | ▶ | sub type_info { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type_info: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 636 | my ($class, $type_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 636 | for my $pkg (@{ mro::get_linear_isa($class) }) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 810 | return $_type_registry{$pkg}{$type_name} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | if exists $_type_registry{$pkg} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 2418 | ▶ | && exists $_type_registry{$pkg}{$type_name}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $_type_registry{$pkg} and exists $_type_registry{$pkg}{$type_name}
MC/DC100%2/2
exists $_type_registry{$pkg} and exists $_type_registry{$pkg}{$type_name}
exists $_type_registry{$pkg}
exists $_type_registry{$pkg}{$type_name}
Truth table100%3/3
A and B
A= exists $_type_registry{$pkg}B= exists $_type_registry{$pkg}{$type_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 198 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 53 | ▶ | sub all_type_names { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_type_names: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 53 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 53 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 53 | for my $pkg (@{ mro::get_linear_isa($class) }) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 530 | ▶ | $seen{$_}++ for keys %{ $_type_registry{$pkg} || {} }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_type_registry{$pkg} || {}
MC/DC100%1/1
$_type_registry{$pkg} || {}
$_type_registry{$pkg}
Truth table100%2/2
A
A= $_type_registry{$pkg}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 53 | return keys %seen; | |||||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 345 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||