| 1 | 13 | ▶ | use 5.008001; use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package DBIx::Connector; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use DBI '1.605'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use DBIx::Connector::Driver; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | our $VERSION = '0.60'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 30 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 30 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 30 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | bless { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 63 | ▶ | _args => sub { @args }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 30 | _svp_depth => 0, | |||||||||||||||||||||||||||||||||||||||||
| 16 | _mode => 'no_ping', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | _dond => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } => $class; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 26 | ▶ | sub DESTROY { $_[0]->disconnect if $_[0]->{_dond} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 61 | ▶ | sub _connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 61 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 61 | my @args = $self->{_args}->(); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 61 | ▶ | my $dbh = do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 61 | ▶ | if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"}
MC/DC50%1/2
$INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"}
$INC{"Apache/DBI.pm"}
$ENV{"MOD_PERL"}
Truth table66%2/3
A and B
A= $INC{"Apache/DBI.pm"}B= $ENV{"MOD_PERL"}
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | local $DBI::connect_via = 'connect'; # Disable Apache::DBI. | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | DBI->connect( @args ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 60 | DBI->connect( @args ); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } or return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # Modify default values. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | $dbh->STORE(AutoInactiveDestroy => 1) if DBI->VERSION > 1.613 && ( | ||||||||||||||||||||||||||||||||||||||||||
| 37 | @args < 4 || !exists $args[3]->{AutoInactiveDestroy} | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 60 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
"DBI"->VERSION > "1.613" and @args < 4 || !exists $args[3]{"AutoInactiveDestroy"}
@args < 4 or not exists $args[3]{"AutoInactiveDestroy"}
MC/DC66%2/3
"DBI"->VERSION > "1.613" and @args < 4 || !exists $args[3]{"AutoInactiveDestroy"}
"DBI"->VERSION > "1.613"
@args < 4
not exists $args[3]{"AutoInactiveDestroy"}
Truth table75%3/4
A and B or not(C)
A= "DBI"->VERSION > "1.613"B= @args < 4C= not exists $args[3]{"AutoInactiveDestroy"}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | $dbh->STORE(RaiseError => 1) if @args < 4 || ( | ||||||||||||||||||||||||||||||||||||||||||
| 41 | !exists $args[3]->{RaiseError} && !exists $args[3]->{HandleError} | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 60 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@args < 4 or not exists $args[3]{"RaiseError"} || exists $args[3]{"HandleError"}
exists $args[3]{'RaiseError'} || exists $args[3]{'HandleError'}
MC/DC100%3/3
@args < 4 or not exists $args[3]{"RaiseError"} || exists $args[3]{"HandleError"}
@args < 4
exists $args[3]{'RaiseError'}
exists $args[3]{'HandleError'}
Truth table100%4/4
A or not(B || C)
A= @args < 4B= exists $args[3]{'RaiseError'}C= exists $args[3]{'HandleError'}
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Where are we? | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 60 | $self->{_pid} = $$; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 60 | ▶ | $self->{_tid} = threads->tid if $INC{'threads.pm'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 60 | $self->{_dbh} = $dbh; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 60 | ▶ | $self->{driver_name} ||= $dbh->{Driver}{Name}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"driver_name"} ||= $dbh->{"Driver"}{"Name"}
MC/DC0%0/2
$self->{"driver_name"} ||= $dbh->{"Driver"}{"Name"}
$self->{"driver_name"}
$dbh->{"Driver"}{"Name"}
Truth table66%2/3
A ||= B
A= $self->{"driver_name"}B= $dbh->{"Driver"}{"Name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Set up the driver and go! | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 60 | return $self->driver->_connect($dbh, @args); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub dsn { ( $_[0]{_args}->() )[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dsn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | sub driver_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
driver_name: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | $self->{driver_name} ||= ( DBI->parse_dsn( $self->dsn ) )[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"driver_name"} ||= ("DBI"->parse_dsn($self->dsn))[1]
MC/DC0%0/2
$self->{"driver_name"} ||= ("DBI"->parse_dsn($self->dsn))[1]
$self->{"driver_name"}
("DBI"->parse_dsn($self->dsn))[1]
Truth table33%1/3
A ||= B
A= $self->{"driver_name"}B= ("DBI"->parse_dsn($self->dsn))[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 229 | ▶ | sub driver { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
driver: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 229 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 229 | ▶ | $self->{driver} ||= DBIx::Connector::Driver->new( $self->{driver_name} || $self->driver_name ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{"driver"} ||= "DBIx::Connector::Driver"->new($self->{"driver_name"} || $self->driver_name)
$self->{'driver_name'} || $self->driver_name
MC/DC0%0/2
$self->{"driver"} ||= "DBIx::Connector::Driver"->new($self->{"driver_name"} || $self->driver_name)
$self->{"driver"}
"DBIx::Connector::Driver"->new($self->{"driver_name"} || $self->driver_name)
MC/DC0%0/2
$self->{'driver_name'} || $self->driver_name
$self->{'driver_name'}
$self->driver_name
Truth table66%2/3
A ||= B
A= $self->{"driver"}B= "DBIx::Connector::Driver"->new($self->{"driver_name"} || $self->driver_name)
Truth table66%2/3
A || B
A= $self->{'driver_name'}B= $self->driver_name
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | my $self = shift->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | $self->{_dond} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 99 | ▶ | sub dbh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 99 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 99 | ▶ | my $dbh = $self->_seems_connected or return $self->_connect; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 64 | ▶ | return $dbh if $self->{_in_run}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 39 | ▶ | return $self->connected ? $dbh : $self->_connect; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # Just like dbh(), except it doesn't ping the server. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 95 | ▶ | sub _dbh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 95 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 95 | ▶ | $self->_seems_connected || $self->_connect; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 65 | ▶ | sub connected { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connected: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 65 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 65 | ▶ | return unless $self->_seems_connected; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 60 | ▶ | my $dbh = $self->{_dbh} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 60 | return $self->driver->ping($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 42 | ▶ | sub mode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mode: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 42 | ▶ | return $self->{_mode} unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 18 | ▶ | require Carp && Carp::croak(qq{Invalid mode: "$_[0]"}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$_[0] =~ /^(?:fixup|(?:no_)?ping)$/ || require Carp && Carp::croak(qq[Invalid mode: "$_[0]"])
require Carp and Carp::croak(qq[Invalid mode: "$_[0]"])
MC/DC0%0/2
$_[0] =~ /^(?:fixup|(?:no_)?ping)$/ || require Carp && Carp::croak(qq[Invalid mode: "$_[0]"])
$_[0] =~ /^(?:fixup|(?:no_)?ping)$/
require Carp
Truth table66%2/3
A || B
A= $_[0] =~ /^(?:fixup|(?:no_)?ping)$/B= require Carp
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | unless $_[0] =~ /^(?:fixup|(?:no_)?ping)$/; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 17 | $self->{_mode} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | sub disconnect_on_destroy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect_on_destroy: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | return $self->{_dond} unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | $self->{_dond} = !!shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 71 | ▶ | sub in_txn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_txn: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 71 | ▶ | my $dbh = shift->{_dbh} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 70 | return !$dbh->FETCH('AutoCommit'); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # returns true if there is a database handle and the PID and TID have not | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # changed and the handle's Active attribute is true. | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 261 | ▶ | sub _seems_connected { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seems_connected: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 261 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 261 | ▶ | my $dbh = $self->{_dbh} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 232 | ▶ | if ( defined $self->{_tid} && $self->{_tid} != threads->tid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $self->{"_tid"} and $self->{"_tid"} != "threads"->tid
MC/DC100%2/2
defined $self->{"_tid"} and $self->{"_tid"} != "threads"->tid
defined $self->{"_tid"}
$self->{"_tid"} != "threads"->tid
Truth table100%3/3
A and B
A= defined $self->{"_tid"}B= $self->{"_tid"} != "threads"->tid
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } elsif ( $self->{_pid} != $$ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # We've forked, so prevent the parent process handle from touching the | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # DB on DESTROY. Here in the child process, that could really screw | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # things up. This is superfluous when AutoInactiveDestroy is set, but | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # harmless. It's better to be proactive anyway. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | $dbh->STORE(InactiveDestroy => 1); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # Use FETCH() to avoid death when called from during global destruction. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 227 | ▶ | return $dbh->FETCH('Active') ? $dbh : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 25 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 25 | ▶ | if (my $dbh = $self->{_dbh}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Some databases need this to stop spewing warnings, according to | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # DBIx::Class::Storage::DBI. Probably Sybase, as the code was added | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # when Sybase ASA and SQLAnywhere support were added to DBIx::Class. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # If that ever becomes an issue for us, add a _disconnect to the | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # Driver class that does it, don't do it here. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # $dbh->STORE(CachedKids => {}); | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 16 | $dbh->disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 16 | $self->{_dbh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 44 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 44 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 44 | ▶ | my $mode = ref $_[0] eq 'CODE' ? $self->{_mode} : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 44 | local $self->{_mode} = $mode; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 44 | ▶ | return $self->_fixup_run(@_) if $mode eq 'fixup'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 29 | return $self->_run(@_); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 29 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 29 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 29 | ▶ | my $dbh = $self->{_mode} eq 'ping' ? $self->dbh : $self->_dbh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 29 | local $self->{_in_run} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 29 | return _exec( $dbh, $code, wantarray ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 15 | ▶ | sub _fixup_run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixup_run: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 15 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 15 | my $dbh = $self->_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 15 | my $wantarray = wantarray; | |||||||||||||||||||||||||||||||||||||||||
| 166 | return _exec( $dbh, $code, $wantarray ) | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 15 | ▶ | if $self->{_in_run} || !$dbh->FETCH('AutoCommit'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_in_run"} or not $dbh->FETCH("AutoCommit")
MC/DC50%1/2
$self->{"_in_run"} or not $dbh->FETCH("AutoCommit")
$self->{"_in_run"}
not $dbh->FETCH("AutoCommit")
Truth table66%2/3
A or not(B)
A= $self->{"_in_run"}B= not $dbh->FETCH("AutoCommit")
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 13 | local $self->{_in_run} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 13 | my ($err, @ret); | |||||||||||||||||||||||||||||||||||||||||
| 171 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 13 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 13 | @ret = eval { _exec( $dbh, $code, $wantarray ) }; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 13 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | die $err if $self->connected; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | # Not connected. Try again. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | return _exec( $self->_connect, $code, $wantarray, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 11 | ▶ | return $wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 79 | ▶ | sub txn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 79 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 79 | ▶ | my $mode = ref $_[0] eq 'CODE' ? $self->{_mode} : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 79 | local $self->{_mode} = $mode; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 79 | ▶ | return $self->_txn_fixup_run(@_) if $mode eq 'fixup'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 53 | return $self->_txn_run(@_); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 53 | ▶ | sub _txn_run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_txn_run: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 53 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 53 | my $driver = $self->driver; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 53 | my $wantarray = wantarray; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 53 | ▶ | my $dbh = $self->{_mode} eq 'ping' ? $self->dbh : $self->_dbh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 53 | ▶ | unless ($dbh->FETCH('AutoCommit')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | local $self->{_in_run} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | return _exec( $dbh, $code, $wantarray ); | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 47 | my ($err, @ret); | |||||||||||||||||||||||||||||||||||||||||
| 206 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 47 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 47 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 209 | 47 | local $self->{_in_run} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 47 | $driver->begin_work($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 47 | @ret = _exec( $dbh, $code, $wantarray ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 40 | $driver->commit($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 213 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 47 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 47 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | $err = $driver->_rollback($dbh, $err); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 7 | die $err; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 40 | ▶ | return $wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 26 | ▶ | sub _txn_fixup_run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_txn_fixup_run: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 26 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 26 | my $dbh = $self->_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 26 | my $driver = $self->driver; | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 26 | my $wantarray = wantarray; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 26 | local $self->{_in_run} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 26 | ▶ | return _exec( $dbh, $code, $wantarray ) unless $dbh->FETCH('AutoCommit'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 22 | my ($err, @ret); | |||||||||||||||||||||||||||||||||||||||||
| 236 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 22 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 22 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 239 | 22 | $driver->begin_work($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 240 | 22 | @ret = _exec( $dbh, $code, $wantarray ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 17 | $driver->commit($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 242 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 22 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 22 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | ▶ | if ($self->connected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | $err = $driver->_rollback($dbh, $err); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | die $err; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | # Not connected. Try again. | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | $dbh = $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 254 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | $driver->begin_work($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | @ret = _exec( $dbh, $code, $wantarray ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $driver->commit($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 260 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | $err = $driver->_rollback($dbh, $err); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | die $err; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | ▶ | return $wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 39 | ▶ | sub svp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 39 | my $dbh = $self->{_dbh}; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | # Gotta have a transaction. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 39 | ▶ | return $self->txn( @_ ) if !$dbh || $dbh->FETCH('AutoCommit'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $dbh or $dbh->FETCH("AutoCommit")
MC/DC50%1/2
not $dbh or $dbh->FETCH("AutoCommit")
not $dbh
$dbh->FETCH("AutoCommit")
Truth table66%2/3
not(A) or B
A= not $dbhB= $dbh->FETCH("AutoCommit")
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 24 | ▶ | my $mode = ref $_[0] eq 'CODE' ? $self->{_mode} : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 24 | local $self->{_mode} = $mode; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 24 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 24 | my ($err, @ret); | |||||||||||||||||||||||||||||||||||||||||
| 284 | 24 | my $wantarray = wantarray; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 24 | my $driver = $self->driver; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 24 | my $name = "savepoint_$self->{_svp_depth}"; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 24 | ++$self->{_svp_depth}; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 24 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 24 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 292 | 24 | $driver->savepoint($dbh, $name); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 24 | @ret = _exec( $dbh, $code, $wantarray ); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 20 | $driver->release($dbh, $name); | |||||||||||||||||||||||||||||||||||||||||
| 295 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 24 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 24 | --$self->{_svp_depth}; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 24 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | # If we died, there is nothing to be done. | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | if ($self->connected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | $err = $driver->_rollback_and_release($dbh, $name, $err); | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 4 | die $err; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 20 | ▶ | return $wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 152 | ▶ | sub _exec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 152 | my ($dbh, $code, $wantarray) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 152 | ▶ | local $_ = $dbh or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | # Block prevents exiting via next or last, otherwise no commit/rollback. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | NOEXIT: { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 152 | ▶ | return $wantarray ? $code->($dbh) : scalar $code->($dbh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | if defined $wantarray; | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 70 | return $code->($dbh); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 18 | return; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | __END__ | ||||||||||||||||||||||||||||||||||||||||||