| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Footprintless::Plugin::Database::AbstractProvider; | ||||||||||||||||||||||||||||
| 5 | 1 | $Footprintless::Plugin::Database::AbstractProvider::VERSION = '1.06'; | |||||||||||||||||||||||||||
| 6 | # ABSTRACT: A base class for database providers | ||||||||||||||||||||||||||||
| 7 | # PODNAME: Footprintless::Plugin::Database::AbstractProvider | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use parent qw(Footprintless::MixableBase); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use overload q{""} => 'to_string', fallback => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Footprintless::Mixins qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | _entity | ||||||||||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Log::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | my $logger = Log::Any->get_logger(); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub backup { | ||||||||||||||||||||||||||
|
Subroutine
backup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | die("abstract method invocation"); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub begin_transaction { | ||||||||||||||||||||||||||
|
Subroutine
begin_transaction: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | croak("not connected") unless ( $self->{connection} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | $self->{connection}->begin_work(); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | return $self; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub client { | ||||||||||||||||||||||||||
|
Subroutine
client: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $in_file; | |||||||||||||||||||||||||||
| 39 | 0 | eval { | |||||||||||||||||||||||||||
| 40 | 0 | my $in_handle = delete( $options{in_handle} ); | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( $options{in_file} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | open( $in_file, '<', delete( $options{in_file} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | || croak("invalid in_file: $!"); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( $options{in_string} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my $string = delete( $options{in_string} ); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | open( $in_file, '<', \$string ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | || croak("invalid in_string: $!"); | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | $self->_connect_tunnel(); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $local_in = $in_handle || $in_file; | ||||||||||||||||||||||||||
|
Condition0%0/3
$in_handle || $in_file
MC/DC0%0/2
$in_handle || $in_file
$in_handle
$in_file
Truth table0%0/3
A || B
A= $in_handleB= $in_file
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | local (*STDIN) = $local_in if ($local_in); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | require Footprintless::Plugin::Database::SqlShellAdapter; | |||||||||||||||||||||||||||
| 56 | Footprintless::Plugin::Database::SqlShellAdapter::sql_shell( $self->_connection_string(), | ||||||||||||||||||||||||||||
| 57 | 0 | $self->{username}, $self->{password}, @{ $options{client_options} } ); | |||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||
| 59 | 0 | my $error = $@; | |||||||||||||||||||||||||||
| 60 | 0 | $self->disconnect(); | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($in_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | close($in_file); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | croak($error) if ($error); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub _column_info { | ||||||||||||||||||||||||||
|
Subroutine
_column_info: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 69 | 0 | my ( $self, $statement_handle ) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | my $column_info = []; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( defined( $statement_handle->{NUM_OF_FIELDS} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | $column_info = [ | ||||||||||||||||||||||||||||
| 73 | map { | ||||||||||||||||||||||||||||
| 74 | 0 | my $element = {}; | |||||||||||||||||||||||||||
| 75 | $element->{name} = $statement_handle->{NAME}->[$_] | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if defined( $statement_handle->{NAME} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | $element->{type} = $statement_handle->{TYPE}->[$_] | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if defined( $statement_handle->{TYPE} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( my $type_info = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | $self->{connection}->type_info( $statement_handle->{TYPE}->[$_] ) ) | ||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | $element->{type_name} = $type_info->{TYPE_NAME} | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if defined( $type_info->{TYPE_NAME} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $element->{type_info} = $type_info if defined( $type_info->{NAME} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | $element->{column_size} = $statement_handle->{PRECISION}->[$_] | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if defined( $statement_handle->{PRECISION} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | $element->{scale} = $statement_handle->{SCALE}->[$_] | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if defined( $statement_handle->{SCALE} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( defined( $statement_handle->{NULLABLE} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $statement_handle->{"NULLABLE"} and (my $nullable = $statement_handle->{"NULLABLE"}[$_]) != 2
MC/DC0%0/2
defined $statement_handle->{"NULLABLE"} and (my $nullable = $statement_handle->{"NULLABLE"}[$_]) != 2
defined $statement_handle->{"NULLABLE"}
(my $nullable = $statement_handle->{"NULLABLE"}[$_]) != 2
Truth table0%0/3
A and B
A= defined $statement_handle->{"NULLABLE"}B= (my $nullable = $statement_handle->{"NULLABLE"}[$_]) != 2
| |||||||||||||||||||||||||||||
| 91 | && ( my $nullable = $statement_handle->{NULLABLE}->[$_] ) != 2 ) | ||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $element->{nullable} = $nullable ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | $element; | |||||||||||||||||||||||||||
| 96 | 0 | } 0 .. $statement_handle->{NUM_OF_FIELDS} - 1 | |||||||||||||||||||||||||||
| 97 | ]; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | return $column_info; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub commit_transaction { | ||||||||||||||||||||||||||
|
Subroutine
commit_transaction: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | croak("not connected") unless ( $self->{connection} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | $self->{connection}->commit(); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | return $self; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 5 | ▶ | sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 5 | ▶ | return if ( $self->{connection} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | $self->_connect_tunnel(); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 5 | my ( $hostname, $port ) = $self->_hostname_port(); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 5 | $logger->debugf( 'connecting to %s', $self->to_string() ); | |||||||||||||||||||||||||||
| 121 | $self->{connection} = DBI->connect( $self->_connection_string(), | ||||||||||||||||||||||||||||
| 122 | 5 | ▶ | $self->{username}, $self->{password}, { RaiseError => 1, AutoCommit => 1 } ) | ||||||||||||||||||||||||||
|
Condition50%1/2
'DBI'->connect($self->_connection_string, $self->{'username'}, $self->{'password'}, {'RaiseError', 1, 'AutoCommit', 1}) || croak("unable to connect to $hostname on port ${port}: $@")
MC/DC0%0/1
'DBI'->connect($self->_connection_string, $self->{'username'}, $self->{'password'}, {'RaiseError', 1, 'AutoCommit', 1}) || croak("unable to connect to $hostname on port ${port}: $@")
'DBI'->connect($self->_connection_string, $self->{'username'}, $self->{'password'}, {'RaiseError', 1, 'AutoCommit', 1})
Truth table50%1/2
A
A= 'DBI'->connect($self->_connection_string, $self->{'username'}, $self->{'password'}, {'RaiseError', 1, 'AutoCommit', 1})
| |||||||||||||||||||||||||||||
| 123 | || croak("unable to connect to $hostname on port $port: $@"); | ||||||||||||||||||||||||||||
| 124 | 5 | $logger->tracef('connected'); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 5 | return $self; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 5 | ▶ | sub _connect_tunnel { | ||||||||||||||||||||||||||
|
Subroutine
_connect_tunnel: called CC=4 SCAR=19.4
| |||||||||||||||||||||||||||||
| 130 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | return if ( $self->{tunnel} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 5 | ▶ | if ( $self->{tunnel_hostname} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | $logger->debugf( 'opening tunnel through %s', $self->{tunnel_hostname} ); | |||||||||||||||||||||||||||
| 136 | $self->{tunnel} = $self->{factory}->tunnel( | ||||||||||||||||||||||||||||
| 137 | $self->{coordinate}, | ||||||||||||||||||||||||||||
| 138 | destination_hostname => $self->{tunnel_destination_hostname} || $self->{hostname}, | ||||||||||||||||||||||||||||
| 139 | destination_port => $self->{port} | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'tunnel_destination_hostname'} || $self->{'hostname'}
MC/DC0%0/2
$self->{'tunnel_destination_hostname'} || $self->{'hostname'}
$self->{'tunnel_destination_hostname'}
$self->{'hostname'}
Truth table0%0/3
A || B
A= $self->{'tunnel_destination_hostname'}B= $self->{'hostname'}
| |||||||||||||||||||||||||||||
| 141 | 0 | $self->{tunnel}->open(); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | return $self; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub _connection_string { | ||||||||||||||||||||||||||
|
Subroutine
_connection_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 148 | 0 | die("abstract method invocation"); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 7 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 152 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 153 | 7 | $self->disconnect(); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 12 | ▶ | sub disconnect { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 12 | ▶ | if ( $self->{connection} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 5 | $logger->debugf( 'disconnecting from %s', $self->to_string() ); | |||||||||||||||||||||||||||
| 161 | 5 | $self->{connection}->disconnect(); | |||||||||||||||||||||||||||
| 162 | 5 | delete( $self->{connection} ); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 12 | ▶ | if ( $self->{tunnel} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | $logger->debug('closing tunnel'); | |||||||||||||||||||||||||||
| 167 | 0 | $self->{tunnel}->close(); | |||||||||||||||||||||||||||
| 168 | 0 | delete( $self->{tunnel} ); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 12 | return $self; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 1 | my ( $self, $query ) = @_; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | my $result; | |||||||||||||||||||||||||||
| 178 | $self->_process_sql( | ||||||||||||||||||||||||||||
| 179 | $query, | ||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 181 | 1 | $result = $_[1]; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 1 | ); | |||||||||||||||||||||||||||
| 184 | 1 | return $result; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub get_schema { | ||||||||||||||||||||||||||
|
Subroutine
get_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 0 | return $_[0]->{schema}; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 25 | ▶ | sub _hostname_port { | ||||||||||||||||||||||||||
|
Subroutine
_hostname_port: called CC=4 SCAR=16.6
| |||||||||||||||||||||||||||||
| 192 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 25 | my ( $hostname, $port ); | |||||||||||||||||||||||||||
| 195 | 25 | ▶ | if ( $self->{tunnel} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | $hostname = $self->{tunnel}->get_local_hostname() || 'localhost'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'tunnel'}->get_local_hostname || 'localhost'
MC/DC0%0/1
$self->{'tunnel'}->get_local_hostname || 'localhost'
$self->{'tunnel'}->get_local_hostname
Truth table0%0/2
A
A= $self->{'tunnel'}->get_local_hostname
| |||||||||||||||||||||||||||||
| 197 | 0 | $port = $self->{tunnel}->get_local_port(); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||
| 200 | 25 | $hostname = $self->{hostname}; | |||||||||||||||||||||||||||
| 201 | 25 | $port = $self->{port}; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 25 | ▶ | return ( $hostname eq 'localhost' ? '127.0.0.1' : $hostname, $port ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 7 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 208 | 7 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 7 | my $entity = $self->_entity( $self->{coordinate} ); | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 7 | $self->{backup} = $entity->{backup}; | |||||||||||||||||||||||||||
| 213 | 7 | $self->{database} = $entity->{database}; | |||||||||||||||||||||||||||
| 214 | 7 | ▶ | $self->{hostname} = $entity->{hostname} || 'localhost'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$entity->{'hostname'} || 'localhost'
MC/DC0%0/1
$entity->{'hostname'} || 'localhost'
$entity->{'hostname'}
Truth table50%1/2
A
A= $entity->{'hostname'}
| |||||||||||||||||||||||||||||
| 215 | 7 | $self->{password} = $entity->{password}; | |||||||||||||||||||||||||||
| 216 | 7 | $self->{port} = $entity->{port}; | |||||||||||||||||||||||||||
| 217 | 7 | $self->{schema} = $entity->{schema}; | |||||||||||||||||||||||||||
| 218 | 7 | $self->{tunnel_destination_hostname} = $entity->{tunnel_destination_hostname}; | |||||||||||||||||||||||||||
| 219 | 7 | $self->{tunnel_hostname} = $entity->{tunnel_hostname}; | |||||||||||||||||||||||||||
| 220 | 7 | $self->{tunnel_username} = $entity->{tunnel_username}; | |||||||||||||||||||||||||||
| 221 | 7 | $self->{username} = $entity->{username}; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 7 | return $self; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 11 | ▶ | sub _process_sql { | ||||||||||||||||||||||||||
|
Subroutine
_process_sql: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||
| 227 | 11 | my ( $self, $query, $statement_handler ) = @_; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | my ( $sql, $parameters ) = | ||||||||||||||||||||||||||||
| 230 | ref($query) eq 'HASH' | ||||||||||||||||||||||||||||
| 231 | ? ( $query->{sql}, $query->{parameters} ) | ||||||||||||||||||||||||||||
| 232 | 11 | ▶ | : ($query); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 11 | eval { | |||||||||||||||||||||||||||
| 234 | 11 | ▶ | if ( $logger->is_trace() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $logger->trace( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | "$self->{hostname}: '$sql'", | ||||||||||||||||||||||||||||
| 237 | ( $parameters | ||||||||||||||||||||||||||||
| 238 | ? ( ",[" . join( ',', @$parameters ) . "]" ) | ||||||||||||||||||||||||||||
| 239 | : '' | ||||||||||||||||||||||||||||
| 240 | ) | ||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 11 | my $statement_handle = $self->{connection}->prepare_cached($sql); | |||||||||||||||||||||||||||
| 244 | 11 | ▶ | &{$statement_handler}( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | $statement_handle, | ||||||||||||||||||||||||||||
| 246 | ( defined($parameters) | ||||||||||||||||||||||||||||
| 247 | ? $statement_handle->execute(@$parameters) | ||||||||||||||||||||||||||||
| 248 | : $statement_handle->execute() | ||||||||||||||||||||||||||||
| 249 | ) | ||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||
| 251 | 11 | $statement_handle->finish(); | |||||||||||||||||||||||||||
| 252 | }; | ||||||||||||||||||||||||||||
| 253 | 11 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | croak("query failed: $@"); | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 8 | ▶ | sub query { | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 259 | 8 | my ( $self, $query, $result_handler, %options ) = @_; | |||||||||||||||||||||||||||
| 260 | 8 | my $hash = $options{hash}; | |||||||||||||||||||||||||||
| 261 | 8 | ▶ | my $column_info = $options{column_info} || ( $hash && [] ); | ||||||||||||||||||||||||||
|
Condition40%2/5
$options{'column_info'} || $hash && []
$hash and []
MC/DC0%0/2
$options{'column_info'} || $hash && []
$options{'column_info'}
$hash
Truth table33%1/3
A || B
A= $options{'column_info'}B= $hash
| |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | $self->_process_sql( | ||||||||||||||||||||||||||||
| 264 | $query, | ||||||||||||||||||||||||||||
| 265 | 8 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.3
| |||||||||||||||||||||||||||||
| 266 | 8 | my ( $statement_handle, $execute_result ) = @_; | |||||||||||||||||||||||||||
| 267 | 0 | ▶ | @$column_info = @{ $self->_column_info($statement_handle) } if $column_info; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 8 | ▶ | if ( !$options{no_fetch} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 8 | ▶ | while ( my @row = $statement_handle->fetchrow_array() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | @row = | ||||||||||||||||||||||||||||
| 271 | 0 | ▶ | map { $column_info->[$_]->{name} => $row[$_] } 0 .. ( scalar(@row) - 1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | if $hash; | ||||||||||||||||||||||||||||
| 273 | 16 | &{$result_handler}(@row); | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | 8 | ); | |||||||||||||||||||||||||||
| 278 | 8 | return; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 2 | ▶ | sub query_for_list { | ||||||||||||||||||||||||||
|
Subroutine
query_for_list: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 282 | 2 | ▶ | my ( $self, $query, $row_mapper, %options ) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | ( shift, shift, ( scalar(@_) % 2 ) ? shift : undef, @_ ); | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 2 | my @results = (); | |||||||||||||||||||||||||||
| 286 | 2 | my $hash = $options{hash}; | |||||||||||||||||||||||||||
| 287 | $self->query( | ||||||||||||||||||||||||||||
| 288 | $query, | ||||||||||||||||||||||||||||
| 289 | 4 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 290 | 4 | ▶ | if ($row_mapper) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 4 | push( @results, &{$row_mapper}(@_) ); | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | else { | ||||||||||||||||||||||||||||
| 294 | 0 | ▶ | push( @results, $hash ? {@_} : \@_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | }, | ||||||||||||||||||||||||||||
| 297 | 2 | %options | |||||||||||||||||||||||||||
| 298 | ); | ||||||||||||||||||||||||||||
| 299 | 2 | ▶ | return wantarray() ? @results : \@results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 4 | ▶ | sub query_for_map { | ||||||||||||||||||||||||||
|
Subroutine
query_for_map: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 303 | 4 | ▶ | my ( $self, $query, $row_mapper, %options ) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | ( shift, shift, ( scalar(@_) % 2 ) ? shift : undef, @_ ); | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 4 | my %results = (); | |||||||||||||||||||||||||||
| 307 | 4 | my $hash = $options{hash}; | |||||||||||||||||||||||||||
| 308 | $self->query( | ||||||||||||||||||||||||||||
| 309 | $query, | ||||||||||||||||||||||||||||
| 310 | 8 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 311 | 8 | ▶ | if ($row_mapper) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 4 | my $key_value_pair = &{$row_mapper}(@_); | |||||||||||||||||||||||||||
| 313 | 4 | $results{ $key_value_pair->[0] } = $key_value_pair->[1]; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | else { | ||||||||||||||||||||||||||||
| 316 | 4 | ▶ | $results{ $_[ $hash ? 1 : 0 ] } = $hash ? {@_} : \@_; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | }, | ||||||||||||||||||||||||||||
| 319 | 4 | %options | |||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||
| 321 | 4 | ▶ | return wantarray() ? %results : \%results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 2 | ▶ | sub query_for_scalar { | ||||||||||||||||||||||||||
|
Subroutine
query_for_scalar: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 325 | 2 | my ( $self, $query, $row_mapper ) = @_; | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 2 | my $result; | |||||||||||||||||||||||||||
| 328 | $self->_process_sql( | ||||||||||||||||||||||||||||
| 329 | $query, | ||||||||||||||||||||||||||||
| 330 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 331 | 2 | my ( $statement_handle, $execute_result ) = @_; | |||||||||||||||||||||||||||
| 332 | 2 | ▶ | if ( my @row = $statement_handle->fetchrow_array() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 2 | ▶ | if ($row_mapper) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 1 | $result = &$row_mapper(@row); | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | else { | ||||||||||||||||||||||||||||
| 337 | 1 | $result = $row[0]; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 2 | ); | |||||||||||||||||||||||||||
| 342 | 2 | return $result; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | sub restore { | ||||||||||||||||||||||||||
|
Subroutine
restore: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 346 | 0 | die("abstract method invocation"); | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub rollback_transaction { | ||||||||||||||||||||||||||
|
Subroutine
rollback_transaction: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 350 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 351 | 0 | ▶ | croak("not connected") unless ( $self->{connection} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | $self->{connection}->rollback(); | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | return $self; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 359 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 360 | 0 | return "{schema=>'$self->{schema}',hostname=>'$self->{hostname}',port=>$self->{port}}"; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 1 | 1; | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | __END__ | ||||||||||||||||||||||||||||