| 1 | package DBIx::TryAgain::db; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | our @ISA = 'DBI::db'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our %defaults = ( | |||||||||||||||||||||||||||
| 8 | private_dbix_try_again_algorithm => 'fibonacci', # or exponential or linear or constant | ||||||||||||||||||||||||||||
| 9 | private_dbix_try_again_max_retries => 5, | ||||||||||||||||||||||||||||
| 10 | private_dbix_try_again_on_messages => [ qr/database is locked/i ], | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub try_again_algorithm { | ||||||||||||||||||||||||||
|
Subroutine
try_again_algorithm: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 15 | 1 | my $attr = 'private_dbix_try_again_algorithm'; | |||||||||||||||||||||||||||
| 16 | 1 | ▶ | return $self->{$attr} || $defaults{$attr} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
MC/DC0%0/2
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
$self->{$attr}
$DBIx::TryAgain::db::defaults{$attr}
Truth table33%1/3
A || B
A= $self->{$attr}B= $DBIx::TryAgain::db::defaults{$attr}
| |||||||||||||||||||||||||||||
| 17 | 0 | $self->{$attr} = shift; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | sub try_again_max_retries { | ||||||||||||||||||||||||||
|
Subroutine
try_again_max_retries: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | 4 | my $attr = 'private_dbix_try_again_max_retries'; | |||||||||||||||||||||||||||
| 23 | 4 | ▶ | return $self->{$attr} || $defaults{$attr} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
MC/DC0%0/2
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
$self->{$attr}
$DBIx::TryAgain::db::defaults{$attr}
Truth table66%2/3
A || B
A= $self->{$attr}B= $DBIx::TryAgain::db::defaults{$attr}
| |||||||||||||||||||||||||||||
| 24 | 2 | $self->{$attr} = shift; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | sub try_again_on_messages { | ||||||||||||||||||||||||||
|
Subroutine
try_again_on_messages: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | 2 | my $attr = 'private_dbix_try_again_on_messages'; | |||||||||||||||||||||||||||
| 30 | 2 | ▶ | return $self->{$attr} || $defaults{$attr} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
MC/DC0%0/2
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
$self->{$attr}
$DBIx::TryAgain::db::defaults{$attr}
Truth table33%1/3
A || B
A= $self->{$attr}B= $DBIx::TryAgain::db::defaults{$attr}
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | die "messages should be an array ref" if ref($_[0]) ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | $self->{$attr} = shift; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 14 | ▶ | sub try_again_on_prepare { | ||||||||||||||||||||||||||
|
Subroutine
try_again_on_prepare: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 14 | my $attr = 'private_dbix_try_again_on_prepare'; | |||||||||||||||||||||||||||
| 38 | 14 | ▶ | return $self->{$attr} || $defaults{$attr} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
MC/DC50%1/2
$self->{$attr} || $DBIx::TryAgain::db::defaults{$attr}
$self->{$attr}
$DBIx::TryAgain::db::defaults{$attr}
Truth table66%2/3
A || B
A= $self->{$attr}B= $DBIx::TryAgain::db::defaults{$attr}
| |||||||||||||||||||||||||||||
| 39 | 1 | $self->{$attr} = shift; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | sub _should_try_again { | ||||||||||||||||||||||||||
|
Subroutine
_should_try_again: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 43 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 8 | ▶ | return unless $self->try_again_on_prepare; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 8 | return $self->DBIx::TryAgain::st::_should_try_again(@_); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 8 | ▶ | sub _sleep { | ||||||||||||||||||||||||||
|
Subroutine
_sleep: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 8 | return shift->DBIx::TryAgain::st::_sleep(@_); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | ▶ | sub prepare { | ||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | 4 | my @args = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | for (keys %defaults) { | |||||||||||||||||||||||||||
| 57 | 12 | ▶ | $self->{$_} = $defaults{$_} unless defined($self->{$_}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | my $sth = $self->SUPER::prepare(@args); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | ▶ | if ($self->try_again_on_prepare) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 2 | $self->_sleep('init'); | |||||||||||||||||||||||||||
| 64 | 2 | $self->{private_dbix_try_again_tries} = 0; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | ▶ | while (!$sth && $self->_should_try_again) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $sth and $self->_should_try_again
MC/DC100%2/2
not $sth and $self->_should_try_again
not $sth
$self->_should_try_again
Truth table100%3/3
not(A) and B
A= not $sthB= $self->_should_try_again
| |||||||||||||||||||||||||||||
| 68 | 6 | $self->{private_dbix_try_again_tries}++; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 6 | for ("DBIx::TryAgain [$$] prepare attempt number ".$self->{private_dbix_try_again_tries}."\n") { | |||||||||||||||||||||||||||
| 71 | 6 | DBI->trace_msg($_); | |||||||||||||||||||||||||||
| 72 | 6 | ▶ | warn $_ if $self->{PrintError}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | $self->_sleep; | |||||||||||||||||||||||||||
| 76 | 6 | $self->set_err(undef, undef); | |||||||||||||||||||||||||||
| 77 | 6 | $sth = $self->SUPER::prepare(@args); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | ▶ | return unless $sth; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 2 | $sth->{$_} = $self->{$_} for keys %defaults; | |||||||||||||||||||||||||||
| 82 | 2 | return $sth; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 3 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||