lib/DB/Object.pm

filter: Statementstmt 31.1% 563 / 1809 Branchbran 14.5% 150 / 1034 Conditioncond 9.5% 82 / 856 MC/DCmcdc 1.3% 6 / 455 Subroutinesub 38.0% 99 / 260 Podpod 100% 101 / 101 totaltotal 22.1% 1001 / 4515 CC 863 SCAR 70.8
CC
863
Cov
21%
_cache_this
5700.0
cache_query_get
5550.0
AUTOLOAD
2437.4
CRAP 1183.0
« blib/lib/DB/Object/Statement.pm ↑ Summary blib/lib/DB/Object/Query.pm »
1 # -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Database Object Interface - ~/lib/m
4 ## Version v1.11.0
5 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2017/07/19
8 ## Modified 2026/09/23
9 ## All rights reserved
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 ## This is the subclassable module for driver specific ones.
15 package DB::Object;
16 BEGIN
17 8 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 require 5.16.0;
19 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶ use parent qw( Module::Generic DBI );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 $VERSION $AUTOLOAD $CACHE_DIR $CACHE_SIZE $DRIVER2PACK
25 $ERROR $DEBUG $MOD_PERL $USE_BIND $USE_CACHE $PLACEHOLDER_REGEXP $SERIALISER
26 $SERIALISATION_VERSION $EXCEPTION_CLASS
27 8 );
28 8 ▶ use Regexp::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 8 ▶ use Scalar::Util qw( blessed weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 8 ▶ use DB::Object::Cache::Tables;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 8 ▶ use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 8 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 8 ▶ use Module::Generic::File qw( sys_tmpdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 8 ▶ use Module::Generic::Global qw( :const );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 8 ▶ use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 8 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 8 our $PLACEHOLDER_REGEXP = qr/(?<![?\w])\?(?![?\w])/;
38 8 our $EXCEPTION_CLASS = 'DB::Object::Exception';
39 8 our $VERSION = 'v1.11.0';
40 };
41  
42 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 8 our $DEBUG = 0;
46 # A global setting variable. This is not changed dynamically, and can be set by the user
47 8 our $CACHE_SIZE = 10;
48 8 our $USE_BIND = 0;
49 8 our $USE_CACHE = 0;
50 8 our $MOD_PERL = 0;
51 # A global variable that can be set by the user to serve as a default value
52 8 our $CACHE_DIR = '';
53 8 ▶if( $INC{ 'Apache/DBI.pm' } &&
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Apache/DBI.pm"} and substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl") 0 8 8
Condition20%1/5
$INC{"Apache/DBI.pm"} and substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
!ll&&!rl&&r
800
$ENV{'GATEWAY_INTERFACE'} || ''
l!l
00
MC/DC0%0/2
$INC{"Apache/DBI.pm"} and substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
$INC{"Apache/DBI.pm"} substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
MC/DC0%0/1
$ENV{'GATEWAY_INTERFACE'} || ''
$ENV{'GATEWAY_INTERFACE'}
Truth table33%1/3
A and B
A= $INC{"Apache/DBI.pm"}B= substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
ABresult
0X0
100
111
Truth table0%0/2
A
A= $ENV{'GATEWAY_INTERFACE'}
Aresult
11
00
54 substr( $ENV{GATEWAY_INTERFACE} || '', 0, 8 ) eq 'CGI-Perl' )
55 {
56 0 $MOD_PERL++;
57 }
58 # Global constant
59 8 our $DRIVER2PACK =
60 {
61 mysql => 'DB::Object::Mysql',
62 Pg => 'DB::Object::Postgres',
63 SQLite => 'DB::Object::SQLite',
64 };
65 # Default value
66 8 our $SERIALISER = 'Storable';
67 8 our $SERIALISATION_VERSION = 1;
68 8 my $CONNECTION_ID_SEQUENCE = 0;
69  
70 sub new
71 8 ▶{
Subroutine new: called CC=2 SCAR=7.2
Pod documented
72 8 my $that = shift( @_ );
73 8 ▶ my $class = ref( $that ) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
74 8 my $self = {};
75 8 bless( $self, $class );
76 8 return( $self->init( @_ ) );
77 }
78  
79 sub init
80 10 ▶{
Subroutine init: called CC=2 SCAR=6.9
Pod documented
81 10 my $self = shift( @_ );
82 10 $self->{cache_connections} = 1;
83 10 $self->{cache_dir} = sys_tmpdir();
84 # Cache query on file ? Only works if 'cache_dir' is set too.
85 10 $self->{cache_query} = 0;
86 10 $self->{cache_size} = $CACHE_SIZE;
87 10 $self->{cache_table} = 0;
88 10 $self->{driver} = '';
89 10 $self->{enhance} = 0;
90 10 $self->{id} = undef;
91 # Auto-decode json data into perl hash
92 10 $self->{auto_decode_json} = 1;
93 10 $self->{auto_convert_datetime_to_object} = 0;
94 10 $self->{allow_bulk_delete} = 0;
95 10 $self->{allow_bulk_update} = 0;
96 10 $self->{serialiser} = undef;
97 10 $self->{unknown_field} = 'ignore';
98 10 $self->{_init_strict_use_sub} = 1;
99 10 $self->{_core_fields} = [grep( !/^_/, keys( %$self ) )];
100 10 $self->{_exception_class} = $EXCEPTION_CLASS;
101 10 ▶ $self->Module::Generic::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->Module::Generic::init(@_) or return $self->pass_error 10 0 10
102 10 return( $self );
103 }
104  
105 sub active_transactions
106 5 ▶{
Subroutine active_transactions: called CC=2 SCAR=7.3
Pod documented
107 5 my $self = shift( @_ );
108 5 my $found = [];
109 5 my $error;
110 DBI->visit_handles(sub
111 20 ▶ {
Subroutine __ANON__: called CC=9 SCAR=24.4
112 20 my( $handle, $transactions ) = @_;
113 20 ▶ my $type = $handle->{Type} // '';
Condition50%1/2
$handle->{"Type"} // ""
l!l
200
MC/DC0%0/1
$handle->{"Type"} // ""
$handle->{"Type"}
Truth table50%1/2
A
A= $handle->{"Type"}
Aresult
11
00
114  
115 # Driver handle: descend towards its database handles.
116 20 ▶ return( $transactions ) if( $type eq 'dr' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "dr" 5 15 20
117  
118 # Database handle: inspect it, but do not descend towards statements.
119 15 ▶ return if( $type ne 'db' );
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "db" 0 15 15
120  
121 15 my $meta = $handle->{private_db_object};
122 15 ▶ if( ref( $meta ) eq 'HASH' && $meta->{transaction} )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $meta eq 'HASH' and $meta->{'transaction'}) { } 3 12 15
elsif (not $handle->{'AutoCommit'}) { } 0 12 12
Condition100%3/3
ref $meta eq "HASH" and $meta->{"transaction"}
!ll&&!rl&&r
1113
MC/DC100%2/2
ref $meta eq "HASH" and $meta->{"transaction"}
ref $meta eq "HASH" $meta->{"transaction"}
Truth table100%3/3
A and B
A= ref $meta eq "HASH"B= $meta->{"transaction"}
ABresult
0X0
100
111
123 {
124 3 ▶ if( $handle->{AutoCommit} )
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{"AutoCommit"}) 0 3 3
125 {
126 0 ▶ $error = "DB::Object transaction metadata for connection ID '" . ( defined( $meta->{id} ) ? $meta->{id} : 'unknown' ) . "' indicates an active transaction, but DBI AutoCommit is enabled on handle '$handle'.";
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{'id'} ? : 0 0 0
127 0 return;
128 }
129  
130 push( @$transactions,
131 {
132 id => $meta->{id},
133 3 handle => $handle,
134 });
135 }
136 elsif( !$handle->{AutoCommit} )
137 {
138 0 $error = "DBI handle '$handle' has AutoCommit disabled, but is not marked as an active DB::Object transaction.";
139 }
140  
141 15 return;
142 5 }, $found );
143  
144 5 ▶ return( $self->error( $error ) ) if( defined( $error ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 5 5
145 5 return( $found );
146 }
147  
148 0 ▶sub allow_bulk_delete { return( shift->_set_get_scalar( 'allow_bulk_delete', @_ ) ); }
Subroutine allow_bulk_delete: not called CC=1 SCAR=6.9
Pod documented
149  
150 0 ▶sub allow_bulk_update { return( shift->_set_get_scalar( 'allow_bulk_update', @_ ) ); }
Subroutine allow_bulk_update: not called CC=1 SCAR=6.9
Pod documented
151  
152 0 ▶sub ALL { return( shift->_operator_object_create( 'DB::Object::ALL', @_ ) ); }
Subroutine ALL: not called CC=1 SCAR=6.9
Pod documented
153  
154 0 ▶sub AND { return( shift->_operator_object_create( 'DB::Object::AND', @_ ) ); }
Subroutine AND: not called CC=1 SCAR=6.9
Pod documented
155  
156 0 ▶sub ANY { return( shift->_operator_object_create( 'DB::Object::ANY', @_ ) ); }
Subroutine ANY: not called CC=1 SCAR=6.9
Pod documented
157  
158 1 ▶sub auto_convert_datetime_to_object { return( shift->_set_get_scalar( 'auto_convert_datetime_to_object', @_ ) ); }
Subroutine auto_convert_datetime_to_object: called CC=1 SCAR=0.0
Pod documented
159  
160 2 ▶sub auto_decode_json { return( shift->_set_get_scalar( 'auto_decode_json', @_ ) ); }
Subroutine auto_decode_json: called CC=1 SCAR=0.0
Pod documented
161  
162 sub attribute($;$@)
163 0 ▶{
Subroutine attribute: not called CC=8 SCAR=42.8
Pod documented
164 0 my $self = shift( @_ );
165 # $h->{AttributeName} = ...; # set/write
166 # ... = $h->{AttributeName}; # get/read
167 # 1 means that the attribute may be modified
168 # 0 mneas that the attribute may only be read
169 0 ▶ my $name = shift( @_ ) if( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
170 0 my %arg = ( @_ );
171 0 my %attr =
172 (
173 Active => 0,
174 ActiveKids => 0,
175 AutoCommit => 1,
176 AutoInactiveDestroy => 1,
177 CachedKids => 0,
178 Callbacks => 1,
179 ChildHandles => 0,
180 ChopBlanks => 1,
181 CompatMode => 1,
182 CursorName => 0,
183 ErrCount => 0,
184 Executed => 0,
185 FetchHashKeyName => 0,
186 HandleError => 1,
187 HandleSetErr => 1,
188 InactiveDestroy => 1,
189 Kids => 0,
190 LongReadLen => 1,
191 LongTruncOk => 1,
192 NAME => 0,
193 NULLABLE => 0,
194 NUM_OF_FIELDS => 0,
195 NUM_OF_PARAMS => 0,
196 Name => 0,
197 PRECISION => 0,
198 PrintError => 1,
199 PrintWarn => 1,
200 Profile => 0,
201 RaiseError => 1,
202 ReadOnly => 1,
203 RowCacheSize => 0,
204 RowsInCache => 0,
205 SCALE => 0,
206 ShowErrorStatement => 1,
207 Statement => 0,
208 TYPE => 0,
209 Taint => 1,
210 TaintIn => 1,
211 TaintOut => 1,
212 TraceLevel => 1,
213 Type => 0,
214 Warn => 1,
215 );
216 # Only those attribute exist
217 # Using an a non existing attribute produce an exception, so we better avoid
218 0 ▶ if( $name )
Branch: 1 branch
BranchTrueFalseTotal
if ($name) { } 0 0 0
219 {
220 0 ▶ return( $self->{dbh}->{ $name } ) if( exists( $attr{ $name } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr{$name} 0 0 0
221 }
222 else
223 {
224 0 my $value;
225 0 ▶ while( ( $name, $value ) = each( %arg ) )
Branch: 1 branch
BranchTrueFalseTotal
if (($name, $value) = each %arg) 0 0 0
226 {
227 # We intend to modifiy the value of an attribute
228 # we are allowed to modify this value if it is true
229 0 ▶ if( exists( $attr{ $name } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr{$name} and defined $value and $attr{$name}) 0 0 0
Condition0%0/6
exists $attr{$name} and defined $value and $attr{$name}
!ll&&!rl&&r
000
exists $attr{$name} and defined $value
!ll&&!rl&&r
000
MC/DC0%0/3
exists $attr{$name} and defined $value and $attr{$name}
exists $attr{$name} defined $value $attr{$name}
Truth table0%0/4
A and B and C
A= exists $attr{$name}B= defined $valueC= $attr{$name}
ABCresult
0XX0
10X0
1100
1111
230 defined( $value ) &&
231 $attr{ $name } )
232 {
233 0 $self->{dbh}->{ $name } = $value;
234 }
235 }
236 }
237 }
238  
239 sub available_drivers(@)
240 0 ▶{
Subroutine available_drivers: not called CC=1 SCAR=6.9
Pod documented
241 # @ary = DBI->available_drivers( $quiet );
242 0 return( DBI->available_drivers(1) );
243 }
244  
245 sub base_class
246 7 ▶{
Subroutine base_class: called CC=3 SCAR=11.0
Pod documented
247 7 my $self = shift( @_ );
248 7 ▶ my $this = @_ ? shift( @_ ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 7 7
249 7 my @supported_classes = $self->supported_class;
250 7 push( @supported_classes, 'DB::Object' );
251 7 my $ok_classes = CORE::join( '|', CORE::map{ CORE::quotemeta( $_ ) } @supported_classes );
252 7 ▶ my $class = ref( $this ) ? ref( $this ) : $this;
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 5 2 7
253 7 my $base_class = ( $class =~ /^($ok_classes)/ )[0];
254 7 return( $base_class );
255 }
256  
257 # This method is common to DB::Object and DB::Object::Statement
258 sub bind
259 0 ▶{
Subroutine bind: not called CC=4 SCAR=30.0
Pod documented
260 0 my $self = shift( @_ );
261 # Usage:
262 # This activate the binding stuff
263 # $dbh->bind() or $dbh->bind->where( "something" ) or $dbh->bind->select->fetchrow_hashref();
264 # Later, $dbh->bind( 'thingy' )->select->fetchrow_hashref()
265 # When used like $table->bind; this means the user is setting the use bind option as a setting for all transactions, but
266 # when used like $table->bind->select then the use bind option is only used for this transaction only and is reset after
267 $self->{bind} = want('VOID')
268 ? 2
269 # Otherwise is it already set maybe?
270 : $self->{bind}
271 # Then use it
272 ? $self->{bind}
273 0 ▶ : 1;
Branch: 2 branches
BranchTrueFalseTotal
want('VOID') ? : 0 0 0
$self->{'bind'} ? : 0 0 0
274 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
275 {
276 # If we are using the cache system, we search the object of this query
277 0 my $obj = $self;
278 0 $obj->{binded} = [ @_ ];
279 # Since new binded parameters have been passed, since mean a new request to the
280 # same statement is pending, so we need to re-execute the statement
281 # and since most of the fetch method rely on AUTOLOAD that call
282 # execute() automatically *IF* the statement was not already executed....
283 # we need to delete 'executed' value or set it to false, so the statement gets re-executed
284 0 $obj->{executed} = 0;
285 0 return( $obj );
286 }
287 0 return( $self );
288 }
289  
290 sub cache
291 0 ▶{
Subroutine cache: not called CC=1 SCAR=6.9
Pod documented
292 0 my $self = shift( @_ );
293 # activate cache
294 # So we may be called as: $tbl->cache->select->fetchrow_hashref();
295 0 $self->{cache}++;
296 0 return( $self );
297 }
298  
299 2 ▶sub cache_connections { return( shift->_set_get_boolean( 'cache_connections', @_ ) ); }
Subroutine cache_connections: called CC=1 SCAR=0.0
Pod documented
300  
301 6 ▶sub cache_dir { return( shift->_set_get_scalar( 'cache_dir', @_ ) ); }
Subroutine cache_dir: called CC=1 SCAR=0.0
Pod documented
302  
303 3 ▶sub cache_query { return( shift->_set_get_scalar( 'cache_query', @_ ) ); }
Subroutine cache_query: called CC=1 SCAR=0.0
Pod documented
304  
305 sub cache_query_get
306 0 ▶{
Subroutine cache_query_get: not called CC=74 SCAR=86.2
Pod documented
307 0 my $self = shift( @_ );
308 0 ▶ my $name = shift( @_ ) || return( $self->error( "No name for this query cache was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No name for this query cache was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No name for this query cache was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
309 0 my $opts = $self->_get_args_as_hash( @_ );
310 0 my $base_class = $self->base_class;
311  
312 # Because we need the database object to revive the statement handler after having thawed it.
313 0 ▶ if( ref( $self ) ne $base_class )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $base_class) 0 0 0
314 {
315 0 return( $self->error( "This method must be called by the database object itself." ) );
316 }
317  
318 # Cannot be called without using a DB::Object
319 0 my $dbo = $self;
320 0 my $dbh = $self->{dbh};
321 0 ▶ my $cache_size = $dbo->cache_size // 0;
Condition0%0/2
$dbo->cache_size // 0
l!l
00
MC/DC0%0/1
$dbo->cache_size // 0
$dbo->cache_size
Truth table0%0/2
A
A= $dbo->cache_size
Aresult
11
00
322 0 my $cache = $dbo->{cache};
323 # We want to know what kind of cache we are expected to use
324 0 ▶ my $cache_query = $opts->{cache_query} // $dbo->cache_query // 1;
Condition0%0/5
($opts->{"cache_query"} // $dbo->cache_query) // 1
l!l
00
$opts->{"cache_query"} // $dbo->cache_query
l!l&&r!l&&!r
000
MC/DC0%0/2
($opts->{"cache_query"} // $dbo->cache_query) // 1
$opts->{"cache_query"} $dbo->cache_query
Truth table0%0/3
A // B
A= $opts->{"cache_query"}B= $dbo->cache_query
ABresult
1X1
011
000
325 0 ▶ my $cache_dir = $opts->{cache_dir} // $dbo->cache_dir // $self->sys_tmpdir;
Condition0%0/6
($opts->{"cache_dir"} // $dbo->cache_dir) // $self->sys_tmpdir
l!l&&r!l&&!r
000
$opts->{"cache_dir"} // $dbo->cache_dir
l!l&&r!l&&!r
000
MC/DC0%0/3
($opts->{"cache_dir"} // $dbo->cache_dir) // $self->sys_tmpdir
$opts->{"cache_dir"} $dbo->cache_dir $self->sys_tmpdir
Truth table0%0/4
A // B // C
A= $opts->{"cache_dir"}B= $dbo->cache_dirC= $self->sys_tmpdir
ABCresult
1XX1
01X1
0011
0000
326 0 ▶ my $ext = $opts->{extension} // 'bin';
Condition0%0/2
$opts->{"extension"} // "bin"
l!l
00
MC/DC0%0/1
$opts->{"extension"} // "bin"
$opts->{"extension"}
Truth table0%0/2
A
A= $opts->{"extension"}
Aresult
11
00
327  
328 0 ▶ my $use_file_cache = ( defined( $cache_query ) && $cache_query eq 'file' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_query && $cache_query eq 'file' ? : 0 0 0
Condition0%0/3
defined $cache_query and $cache_query eq "file"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_query and $cache_query eq "file"
defined $cache_query $cache_query eq "file"
Truth table0%0/3
A and B
A= defined $cache_queryB= $cache_query eq "file"
ABresult
0X0
100
111
329  
330 # Not a hard error
331 0 ▶ if( $cache_query !~ /^1|0|file$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($cache_query =~ /^1|0|file$/) 0 0 0
332 {
333 0 ▶ warn( "Unknown value for cache_query '$cache_query'" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
334 }
335  
336 0 ▶ my $serialiser = $opts->{serialiser} || $self->serialiser || $DB::Object::SERIALISER || 'Storable';
Condition0%0/8
$opts->{'serialiser'} || $self->serialiser || $DB::Object::SERIALISER || 'Storable'
l!l
00
$opts->{"serialiser"} or $self->serialiser or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
$opts->{"serialiser"} or $self->serialiser
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{'serialiser'} || $self->serialiser || $DB::Object::SERIALISER || 'Storable'
$opts->{"serialiser"} $self->serialiser $DB::Object::SERIALISER
Truth table0%0/4
A or B or C
A= $opts->{"serialiser"}B= $self->serialiserC= $DB::Object::SERIALISER
ABCresult
1XX1
01X1
0011
0000
337 # If the serialiser selected is the default one, and we have Sereal installed, we use it instead.
338 0 ▶ if( $serialiser eq 'Storable' && $self->_load_class( 'Sereal' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Storable" and $self->_load_class("Sereal")) 0 0 0
Condition0%0/3
$serialiser eq "Storable" and $self->_load_class("Sereal")
!ll&&!rl&&r
000
MC/DC0%0/2
$serialiser eq "Storable" and $self->_load_class("Sereal")
$serialiser eq "Storable" $self->_load_class("Sereal")
Truth table0%0/3
A and B
A= $serialiser eq "Storable"B= $self->_load_class("Sereal")
ABresult
0X0
100
111
339 {
340 0 $serialiser = 'Sereal';
341 }
342 0 $name = lc( $serialiser ) . "-${name}";
343  
344 # We make sure the extension passed to '_get_cache_filepath' is coherent with ours
345 0 ▶ my $cache_file = $self->_get_cache_filepath( %$opts, name => $name, extension => $ext, prefix => 'query' ) ||
Condition0%0/2
$self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query') || (return $self->pass_error)
$self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query')
Truth table0%0/2
A
A= $self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query')
Aresult
11
00
346 return( $self->pass_error );
347 0 my $cache_key = $cache_file->basename( ".${ext}" );
348  
349 # NOTE: Ensure all classes are loaded before deserialising, so the deserialiser can call their THAW methods.
350 # This is especially important for Sereal, which needs classes to be defined when unmarshalling blessed objects.
351 0 ▶ $self->_load_class( 'Module::Generic', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic", {"force", 1}) or return $self->pass_error 0 0 0
352 0 ▶ $self->_load_class( 'Module::Generic::Array', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array", {"force", 1}) or return $self->pass_error 0 0 0
353 0 ▶ $self->_load_class( 'Module::Generic::Hash', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash", {"force", 1}) or return $self->pass_error 0 0 0
354 0 ▶ $self->_load_class( 'Module::Generic::Number', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Number", {"force", 1}) or return $self->pass_error 0 0 0
355 0 ▶ $self->_load_class( 'Module::Generic::Scalar', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar", {"force", 1}) or return $self->pass_error 0 0 0
356  
357 # Need to ensure DB::Object::Statement is loaded, so the deserialisation of the statement object has a proper inheritance.
358 0 ▶ $self->_load_class( $base_class, { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($base_class, {"force", 1}) or return $self->pass_error 0 0 0
359 0 ▶ $self->_load_class( 'DB::Object::Query::Clause', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Query::Clause", {"force", 1}) or return $self->pass_error 0 0 0
360 0 ▶ $self->_load_class( 'DB::Object::Query::Elements', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Query::Elements", {"force", 1}) or return $self->pass_error 0 0 0
361 0 ▶ $self->_load_class( 'DB::Object::Query::Element', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Query::Element", {"force", 1}) or return $self->pass_error 0 0 0
362 0 ▶ $self->_load_class( 'DB::Object::Constraint::Check', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Check", {"force", 1}) or return $self->pass_error 0 0 0
363 0 ▶ $self->_load_class( 'DB::Object::Constraint::Foreign', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Foreign", {"force", 1}) or return $self->pass_error 0 0 0
364 0 ▶ $self->_load_class( 'DB::Object::Constraint::Index', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Index", {"force", 1}) or return $self->pass_error 0 0 0
365 0 ▶ $self->_load_class( 'DB::Object::Statement', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Statement", {"force", 1}) or return $self->pass_error 0 0 0
366 0 ▶ $self->_load_class( "${base_class}::Query", { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Query", {"force", 1}) or return $self->pass_error 0 0 0
367 0 ▶ $self->_load_class( "${base_class}::Statement", { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Statement", {"force", 1}) or return $self->pass_error 0 0 0
368 0 ▶ $self->_load_class( "${base_class}::Tables", { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Tables", {"force", 1}) or return $self->pass_error 0 0 0
369 0 ( my $mod_path = "${base_class}::Statement" ) =~ s,::,/,g;
370 0 $mod_path .= '.pm';
371 0 my $lock;
372 0 ▶ my $repo = Module::Generic::Global->new( queries_cache => $base_class,
Condition0%0/2
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Aresult
11
00
373 max_size => $cache_size,
374 serialiser => $serialiser,
375 key => $cache_key,
376 ) || return( $self->pass_error( Module::Generic::Global->error ) );
377 # The lock gets removed automatically when it gets out of scope, so we store it in $lock
378 0 $lock = $repo->lock;
379 0 local $@;
380 0 my $sth = eval{ $repo->get };
381 # The deserialisation of the in-memory object died, most likely in the THAW, and maybe due to a serialisation version mismatch
382 0 ▶ if( !$sth && $@ )
Branch: 1 branch
BranchTrueFalseTotal
if (not $sth and $@) 0 0 0
Condition0%0/3
not $sth and $@
!ll&&!rl&&r
000
MC/DC0%0/2
not $sth and $@
not $sth $@
Truth table0%0/3
not(A) and B
A= not $sthB= $@
ABresult
0X0
100
111
383 {
384 0 ▶ if( $@ =~ /Serialisation[[:blank:]]+version[[:blank:]]+mismatch/i )
Branch: 2 branches
BranchTrueFalseTotal
if ($@ =~ /Serialisation[[:blank:]]+version[[:blank:]]+mismatch/i) { } 0 0 0
elsif ($self->_is_object($@)) { } 0 0 0
385 {
386 # We just warn, and since no object has been deserialise, we will return nothing, thus leading the caller to create a fresh object.
387 0 warn( $@ );
388 }
389 elsif( $self->_is_object( $@ ) )
390 {
391 0 return( $self->pass_error( $@ ) );
392 }
393 else
394 {
395 0 return( $self->error( "Unable to deserialise in-memory statement object: $@" ) );
396 }
397 }
398  
399  
400 0 ▶ if( !$sth && $cache_query eq 'file' )
Branch: 1 branch
BranchTrueFalseTotal
if (not $sth and $cache_query eq "file") 0 0 0
Condition0%0/3
not $sth and $cache_query eq "file"
!ll&&!rl&&r
000
MC/DC0%0/2
not $sth and $cache_query eq "file"
not $sth $cache_query eq "file"
Truth table0%0/3
not(A) and B
A= not $sthB= $cache_query eq "file"
ABresult
0X0
100
111
401 {
402 0 ▶ if( !$cache_file->exists ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $cache_file->exists && $cache_file->is_file or $cache_file->is_empty) 0 0 0
Condition0%0/6
not $cache_file->exists && $cache_file->is_file or $cache_file->is_empty
l!l&&r!l&&!r
000
$cache_file->exists && $cache_file->is_file
!ll&&!rl&&r
000
MC/DC0%0/3
not $cache_file->exists && $cache_file->is_file or $cache_file->is_empty
$cache_file->exists $cache_file->is_file $cache_file->is_empty
Truth table0%0/4
not(A && B) or C
A= $cache_file->existsB= $cache_file->is_fileC= $cache_file->is_empty
ABCresult
0XX1
10X1
1111
1100
403 !$cache_file->is_file ||
404 $cache_file->is_empty )
405 {
406 0 return( '' );
407 }
408 0 $sth = eval{
409 0 $self->Module::Generic::deserialise(
410 file => $cache_file,
411 lock => 1,
412 serialiser => $serialiser,
413 );
414 };
415 0 ▶ if( !$sth )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth) 0 0 0
416 {
417 # A fatal exception occurred in the THAW hook maybe?
418 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
419 {
420 0 ▶ if( $@ =~ /Serialisation[[:blank:]]+version[[:blank:]]+mismatch/i )
Branch: 2 branches
BranchTrueFalseTotal
if ($@ =~ /Serialisation[[:blank:]]+version[[:blank:]]+mismatch/i) { } 0 0 0
elsif ($self->_is_object($@)) { } 0 0 0
421 {
422 # We just warn, and since no object has been deserialise, we will return nothing, thus leading the caller to create a fresh object.
423 0 warn( $@ );
424 }
425 elsif( $self->_is_object( $@ ) )
426 {
427 0 return( $self->pass_error( $@ ) );
428 }
429 else
430 {
431 0 return( $self->error( "Unable to deserialise in-memory statement object: $@" ) );
432 }
433 }
434 else
435 {
436 0 return( $self->pass_error );
437 }
438 }
439 0 ▶ $repo->set( $sth ) || return( $self->pass_error( $repo->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$repo->set($sth) or return $self->pass_error($repo->error) 0 0 0
440 }
441  
442 # No statement object found, so we return empty, but not undefined, which is reserved for errors.
443 0 ▶ if( !$sth )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth) 0 0 0
444 {
445 0 return( '' );
446 }
447  
448 0 ▶ unless( $self->_is_a( $sth => "${base_class}::Statement" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($sth, "${base_class}::Statement")) 0 0 0
449 {
450 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
451 0 die( "Statement object found (", $self->_str_val( $sth ), ") in this statement object is actually not a statement object (${base_class}::Statement) !" );
452 }
453  
454 # my $sth_class = ref( $sth );
455 # if( !$self->_load_class( $sth_class ) )
456 # {
457 # $repo->unlock if( $repo );
458 # return( $self->pass_error );
459 # }
460 # my $sth_base_class = $dbo->base_class( $sth_class );
461 # if( !$self->_load_class( "${sth_base_class}::Query" ) )
462 # {
463 # $repo->unlock if( $repo );
464 # return( $self->pass_error );
465 # }
466 # if( !$self->_load_class( "${sth_base_class}::Tables" ) )
467 # {
468 # $repo->unlock if( $repo );
469 # return( $self->pass_error );
470 # }
471 # bless( $sth => $sth_class );
472 # Detect "zombie" DBI handles (blessed but no magic) without leaking warnings
473 0 my $dbh_ok = 0;
474 0 ▶ if( $dbh && ref( $dbh ) =~ /^DBI::db\b/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh and ref($dbh) =~ /^DBI::db\b/) 0 0 0
Condition0%0/3
$dbh and ref($dbh) =~ /^DBI::db\b/
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh and ref($dbh) =~ /^DBI::db\b/
$dbh ref($dbh) =~ /^DBI::db\b/
Truth table0%0/3
A and B
A= $dbhB= ref($dbh) =~ /^DBI::db\b/
ABresult
0X0
100
111
475 {
476 local $SIG{__WARN__} = sub
477 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
478 0 die( $_[0] );
479 0 };
480 0 local $@;
481 $dbh_ok = eval
482 0 {
483 0 ▶ $dbh->ping ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->ping ? : 0 0 0
484 };
485 0 ▶ $dbh_ok = 0 if( !$dbh_ok || $@ );
Branch: 1 branch
BranchTrueFalseTotal
if not $dbh_ok or $@ 0 0 0
Condition0%0/3
not $dbh_ok or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
not $dbh_ok or $@
not $dbh_ok $@
Truth table0%0/3
not(A) or B
A= not $dbh_okB= $@
ABresult
1X1
011
000
486 }
487  
488 0 ▶ if( !$dbh_ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh_ok) 0 0 0
489 {
490 0 $dbh = $self->_dbi_connect;
491 0 ▶ if( !$dbh )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
492 {
493 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
494 0 return( $self->pass_error );
495 }
496 0 $dbo->{dbh} = $dbh;
497 }
498  
499 0 $sth->debug( $self->debug );
500 # We reattach the database object to that statement
501 0 ▶ if( !$sth->attach( $dbo ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->attach($dbo)) 0 0 0
502 {
503 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
504 0 return( $self->pass_error( $sth->error ) );
505 }
506 0 my $query = $sth->as_string;
507 0 ▶ if( !defined( $query ) || !CORE::length( $query ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $query and length $query) 0 0 0
Condition0%0/3
defined $query and length $query
!ll&&!rl&&r
000
MC/DC0%0/2
defined $query and length $query
defined $query length $query
Truth table0%0/3
A and B
A= defined $queryB= length $query
ABresult
0X0
100
111
508 {
509 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
510 0 return( $self->error( "No SQL query string could be found." ) );
511 }
512 0 my $prepare_options = {};
513 0 ▶ if( my $q = $sth->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $q = $sth->query_object) 0 0 0
514 {
515 0 $prepare_options = $q->prepare_options->as_hash;
516 }
517  
518 0 local $@;
519 my $sth_dbi = eval
520 0 {
521 0 ▶ $dbh->prepare( $query, ( scalar( keys( %$prepare_options ) ) ? $prepare_options : () ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$prepare_options ? : 0 0 0
522 };
523  
524 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $sth_dbi) { } 0 0 0
525 {
526 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
527 0 return( $self->error( "Error preparing cached SQL query: $@\nQuery was:\n$query" ) );
528 }
529 elsif( !$sth_dbi )
530 {
531 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
532 0 ▶ my $err = ( $self->{dbh}->errstr() || 'unknown DBI error' );
Condition0%0/2
$self->{'dbh'}->errstr || 'unknown DBI error'
l!l
00
MC/DC0%0/1
$self->{'dbh'}->errstr || 'unknown DBI error'
$self->{'dbh'}->errstr
Truth table0%0/2
A
A= $self->{'dbh'}->errstr
Aresult
11
00
533 0 return( $self->error( "Error while trying to prepare query: ${err}\nQuery was:\n$query" ) );
534 }
535  
536 0 $sth->{sth} = $sth_dbi;
537  
538 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
539 0 return( $sth );
540 }
541  
542 sub cache_query_set
543 0 ▶{
Subroutine cache_query_set: not called CC=30 SCAR=68.4
Pod documented
544 0 my $self = shift( @_ );
545 0 ▶ my $name = shift( @_ ) || return( $self->error( "No name for this query cache was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No name for this query cache was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No name for this query cache was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
546 0 ▶ my $sth = shift( @_ ) || return( $self->error( "No statement handler was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No statement handler was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No statement handler was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
547 0 my $opts = $self->_get_args_as_hash( @_ );
548 0 my $base_class = $self->base_class;
549  
550 # Because we need the database object to revive the statement handler after having thawed it.
551 0 ▶ if( ref( $self ) ne $base_class )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $base_class) 0 0 0
552 {
553 0 return( $self->error( "This method must be called by the database object itself." ) );
554 }
555  
556 # Cannot be called without using a DB::Object
557 0 my $dbo = $self;
558 0 ▶ my $cache_size = $dbo->cache_size // 0;
Condition0%0/2
$dbo->cache_size // 0
l!l
00
MC/DC0%0/1
$dbo->cache_size // 0
$dbo->cache_size
Truth table0%0/2
A
A= $dbo->cache_size
Aresult
11
00
559 0 my $cache = $dbo->{cache};
560 # We want to know what kind of cache we are expected to use
561 0 ▶ my $cache_query = $opts->{cache_query} // $dbo->cache_query // 1;
Condition0%0/5
($opts->{"cache_query"} // $dbo->cache_query) // 1
l!l
00
$opts->{"cache_query"} // $dbo->cache_query
l!l&&r!l&&!r
000
MC/DC0%0/2
($opts->{"cache_query"} // $dbo->cache_query) // 1
$opts->{"cache_query"} $dbo->cache_query
Truth table0%0/3
A // B
A= $opts->{"cache_query"}B= $dbo->cache_query
ABresult
1X1
011
000
562 0 ▶ my $cache_dir = $opts->{cache_dir} // $dbo->cache_dir // $self->sys_tmpdir;
Condition0%0/6
($opts->{"cache_dir"} // $dbo->cache_dir) // $self->sys_tmpdir
l!l&&r!l&&!r
000
$opts->{"cache_dir"} // $dbo->cache_dir
l!l&&r!l&&!r
000
MC/DC0%0/3
($opts->{"cache_dir"} // $dbo->cache_dir) // $self->sys_tmpdir
$opts->{"cache_dir"} $dbo->cache_dir $self->sys_tmpdir
Truth table0%0/4
A // B // C
A= $opts->{"cache_dir"}B= $dbo->cache_dirC= $self->sys_tmpdir
ABCresult
1XX1
01X1
0011
0000
563 0 ▶ my $ext = $opts->{extension} // 'bin';
Condition0%0/2
$opts->{"extension"} // "bin"
l!l
00
MC/DC0%0/1
$opts->{"extension"} // "bin"
$opts->{"extension"}
Truth table0%0/2
A
A= $opts->{"extension"}
Aresult
11
00
564  
565 0 ▶ my $use_file_cache = ( defined( $cache_query ) && $cache_query eq 'file' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_query && $cache_query eq 'file' ? : 0 0 0
Condition0%0/3
defined $cache_query and $cache_query eq "file"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_query and $cache_query eq "file"
defined $cache_query $cache_query eq "file"
Truth table0%0/3
A and B
A= defined $cache_queryB= $cache_query eq "file"
ABresult
0X0
100
111
566  
567 # Not a hard error
568 0 ▶ if( $cache_query !~ /^1|0|file$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($cache_query =~ /^1|0|file$/) 0 0 0
569 {
570 0 ▶ warn( "Unknown value for cache_query '$cache_query'" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
571 }
572  
573 0 ▶ my $serialiser = $opts->{serialiser} || $self->serialiser || $DB::Object::SERIALISER || 'Storable';
Condition0%0/8
$opts->{'serialiser'} || $self->serialiser || $DB::Object::SERIALISER || 'Storable'
l!l
00
$opts->{"serialiser"} or $self->serialiser or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
$opts->{"serialiser"} or $self->serialiser
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{'serialiser'} || $self->serialiser || $DB::Object::SERIALISER || 'Storable'
$opts->{"serialiser"} $self->serialiser $DB::Object::SERIALISER
Truth table0%0/4
A or B or C
A= $opts->{"serialiser"}B= $self->serialiserC= $DB::Object::SERIALISER
ABCresult
1XX1
01X1
0011
0000
574 # If the serialiser selected is the default one, and we have Sereal installed, we use it instead.
575 0 ▶ if( $serialiser eq 'Storable' && $self->_load_class( 'Sereal' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Storable" and $self->_load_class("Sereal")) 0 0 0
Condition0%0/3
$serialiser eq "Storable" and $self->_load_class("Sereal")
!ll&&!rl&&r
000
MC/DC0%0/2
$serialiser eq "Storable" and $self->_load_class("Sereal")
$serialiser eq "Storable" $self->_load_class("Sereal")
Truth table0%0/3
A and B
A= $serialiser eq "Storable"B= $self->_load_class("Sereal")
ABresult
0X0
100
111
576 {
577 0 $serialiser = 'Sereal';
578 }
579 0 $name = lc( $serialiser ) . "-${name}";
580  
581 # We make sure the extension passed to '_get_cache_filepath' is coherent with ours
582 0 ▶ my $cache_file = $self->_get_cache_filepath( %$opts, name => $name, extension => $ext, prefix => 'query' ) ||
Condition0%0/2
$self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query') || (return $self->pass_error)
$self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query')
Truth table0%0/2
A
A= $self->_get_cache_filepath(%$opts, 'name', $name, 'extension', $ext, 'prefix', 'query')
Aresult
11
00
583 return( $self->pass_error );
584 0 my $cache_key = $cache_file->basename( ".${ext}" );
585  
586 0 my $lock;
587 0 ▶ my $repo = Module::Generic::Global->new( queries_cache => $base_class,
Condition0%0/2
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Aresult
11
00
588 max_size => $cache_size,
589 serialiser => $serialiser,
590 key => $cache_key,
591 ) || return( $self->pass_error( Module::Generic::Global->error ) );
592 # The lock gets removed automatically when it gets out of scope, so we store it in $lock
593 0 $lock = $repo->lock;
594  
595 0 ▶ if( $cache_query eq 'file' )
Branch: 2 branches
BranchTrueFalseTotal
if ($cache_query eq 'file') { } 0 0 0
elsif ($cache_query) { } 0 0 0
596 {
597 # If it is already there, we return immediately. There is nothing more to do.
598 0 ▶ if( $cache_file->exists &&
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_file->exists and not $cache_file->is_file) 0 0 0
Condition0%0/3
$cache_file->exists and not $cache_file->is_file
!ll&&!rl&&r
000
MC/DC0%0/2
$cache_file->exists and not $cache_file->is_file
$cache_file->exists not $cache_file->is_file
Truth table0%0/3
A and not(B)
A= $cache_file->existsB= not $cache_file->is_file
ABresult
0X0
100
111
599 !$cache_file->is_file )
600 {
601 0 return( $self->error( "There already existing a cache file $cache_file, but it is not a file!" ) );
602 }
603 0 ▶ if( $cache_file->exists &&
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_file->exists and $cache_file->is_file and not $cache_file->is_empty) 0 0 0
Condition0%0/6
$cache_file->exists and $cache_file->is_file and not $cache_file->is_empty
!ll&&!rl&&r
000
$cache_file->exists and $cache_file->is_file
!ll&&!rl&&r
000
MC/DC0%0/3
$cache_file->exists and $cache_file->is_file and not $cache_file->is_empty
$cache_file->exists $cache_file->is_file not $cache_file->is_empty
Truth table0%0/4
A and B and not(C)
A= $cache_file->existsB= $cache_file->is_fileC= not $cache_file->is_empty
ABCresult
0XX0
10X0
1100
1111
604 $cache_file->is_file &&
605 !$cache_file->is_empty )
606 {
607 0 return( $sth );
608 }
609 0 ▶ $self->Module::Generic::serialise( $sth,
Branch: 2 branches
BranchTrueFalseTotal
$self->Module::Generic::serialise($sth, "file", $cache_file, "lock", 1, "serialiser", $serialiser, $serialiser eq "Sereal" ? ("freeze_callbacks", 1) : ()) or return $self->pass_error 0 0 0
$serialiser eq 'Sereal' ? : 0 0 0
610 file => $cache_file,
611 lock => 1,
612 serialiser => $serialiser,
613 ( $serialiser eq 'Sereal' ? ( freeze_callbacks => 1 ) : () ),
614 ) || return( $self->pass_error );
615 }
616 elsif( $cache_query )
617 {
618 0 $repo->set( $sth );
619 0 $repo->unlock;
620 }
621 0 return( $sth );
622 }
623  
624 3 ▶sub cache_size { return( shift->_set_get_scalar( 'cache_size', @_ ) ); }
Subroutine cache_size: called CC=1 SCAR=0.0
Pod documented
625  
626 3 ▶sub cache_table { return( shift->_set_get_scalar( 'cache_table', @_ ) ); }
Subroutine cache_table: called CC=1 SCAR=0.0
Pod documented
627  
628 3 ▶sub cache_tables { return( shift->_set_get_object( 'cache_tables', 'DB::Object::Cache::Tables', @_ ) ); }
Subroutine cache_tables: called CC=1 SCAR=0.0
Pod documented
629  
630 sub check_driver()
631 0 ▶{
Subroutine check_driver: not called CC=4 SCAR=30.0
Pod documented
632 0 my $self = shift( @_ );
633 0 ▶ my $driver = shift( @_ ) || return( $self->error( "No SQL driver provided to check" ) );
Condition0%0/2
shift @_ || (return $self->error('No SQL driver provided to check'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No SQL driver provided to check'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
634 0 my $ok = undef();
635 0 local $_;
636 0 my @drivers = $self->available_drivers();
637 0 foreach( @drivers )
638 {
639 0 ▶ if( m/$driver/s )
Branch: 1 branch
BranchTrueFalseTotal
if (/$driver/s) 0 0 0
640 {
641 0 $ok++;
642 0 last;
643 }
644 }
645 0 return( $ok );
646 }
647  
648 sub connect
649 3 ▶{
Subroutine connect: called CC=64 SCAR=52.9
Pod documented
650 3 my $this = shift( @_ );
651 3 ▶ my $class = ref( $this ) || $this;
Condition66%2/3
ref $this || $this
l!l&&r!l&&!r
120
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table66%2/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
652 3 my $base_class = $this->base_class;
653 3 my $opts = $this->_get_args_as_hash( @_ );
654 # We pass the arguments so that debug and other init parameters can be set early
655 3 ▶ my $that = ref( $this ) ? $this : $this->Module::Generic::new( debug => $opts->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 1 2 3
656 3 ▶ my $param = $that->_connection_params2hash( $opts ) || return( $this->error( "No valid connection parameters found" ) );
Condition50%1/2
$that->_connection_params2hash($opts) || (return $this->error('No valid connection parameters found'))
l!l
30
MC/DC0%0/1
$that->_connection_params2hash($opts) || (return $this->error('No valid connection parameters found'))
$that->_connection_params2hash($opts)
Truth table50%1/2
A
A= $that->_connection_params2hash($opts)
Aresult
11
00
657 3 $param = $that->_connection_params2hash_driver( $param );
658 3 my $driver2pack =
659 {
660 mysql => 'DB::Object::Mysql',
661 Pg => 'DB::Object::Postgres',
662 SQLite => 'DB::Object::SQLite',
663 };
664 3 my $pack2driver = +{ map{ $driver2pack->{ $_ } => $_ } keys( %$driver2pack ) };
665 3 my $driver_class;
666 3 ▶ if( exists( $param->{driver} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param->{'driver'}) { } 2 1 3
elsif (exists $pack2driver->{$base_class}) { } 1 0 1
667 {
668 2 ▶ if( !exists( $driver2pack->{ $param->{driver} } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$driver2pack{$param->{"driver"}}) 0 2 2
669 {
670 0 return( $this->error( "Driver $param->{driver} is not supported." ) );
671 }
672 # For example, will make this object a DB::ObjectD::Postgres object
673 2 $driver_class = $driver2pack->{ $param->{driver} };
674 2 my $driver_module = $driver_class;
675 2 $driver_module =~ s|::|/|g;
676 2 $driver_module .= '.pm';
677 eval
678 2 {
679 2 local $DEBUG;
680 2 require $driver_module;
681 };
682 2 ▶ return( $this->error( "Unable to load module $driver_class ($driver_module): $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
683 }
684 elsif( exists( $pack2driver->{ $base_class } ) )
685 {
686 1 $driver_class = $base_class;
687 1 $param->{driver} = $pack2driver->{ $base_class };
688 }
689 else
690 {
691 0 return( $this->error( "No driver was provided." ) );
692 }
693 3 ▶ my $self = $driver_class->new || return( $this->error( "Cannot get object from package $driver_class" ) );
Condition50%1/2
$driver_class->new || (return $this->error("Cannot get object from package $driver_class"))
l!l
30
MC/DC0%0/1
$driver_class->new || (return $this->error("Cannot get object from package $driver_class"))
$driver_class->new
Truth table50%1/2
A
A= $driver_class->new
Aresult
11
00
694 $self->debug(
695 CORE::exists( $param->{debug} )
696 ? CORE::delete( $param->{debug} )
697 : CORE::exists( $param->{Debug} )
698 ? CORE::delete( $param->{Debug} )
699 3 ▶ : $DEBUG
Branch: 2 branches
BranchTrueFalseTotal
exists $param->{'debug'} ? : 0 3 3
exists $param->{'Debug'} ? : 0 3 3
700 );
701 # Needed to be specified if the user does not want to cache connections
702 # Will be used in _dbi_connect()
703 3 ▶ $self->cache_connections( CORE::delete( $param->{cache_connections} ) ) if( CORE::exists( $param->{cache_connections} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $param->{"cache_connections"} 2 1 3
704 3 ▶ $self->connect_via( CORE::delete( $param->{connect_via} ) ) if( CORE::exists( $param->{connect_via} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $param->{"connect_via"} 0 3 3
705 $self->cache_dir(
706 CORE::exists( $param->{cache_dir} )
707 ? CORE::delete( $param->{cache_dir} )
708 : CORE::exists( $that->{cache_dir} )
709 ? $that->{cache_dir}
710 3 ▶ : $CACHE_DIR
Branch: 2 branches
BranchTrueFalseTotal
exists $param->{'cache_dir'} ? : 0 3 3
exists $that->{'cache_dir'} ? : 3 0 3
711 );
712  
713 3 ▶ if( CORE::exists( $param->{cache_table} ) && defined( $param->{cache_table} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param->{'cache_table'} and defined $param->{'cache_table'}) { } 0 3 3
elsif (exists $that->{'cache_table'} and defined $that->{'cache_table'}) { } 3 0 3
Condition33%1/3
exists $param->{"cache_table"} and defined $param->{"cache_table"}
!ll&&!rl&&r
300
MC/DC0%0/2
exists $param->{"cache_table"} and defined $param->{"cache_table"}
exists $param->{"cache_table"} defined $param->{"cache_table"}
Truth table33%1/3
A and B
A= exists $param->{"cache_table"}B= defined $param->{"cache_table"}
ABresult
0X0
100
111
714 {
715 0 $self->cache_table( CORE::delete( $param->{cache_table} ) );
716 }
717 ▶ elsif( CORE::exists( $that->{cache_table} ) && defined( $that->{cache_table} ) )
Condition33%1/3
exists $that->{"cache_table"} and defined $that->{"cache_table"}
!ll&&!rl&&r
003
MC/DC0%0/2
exists $that->{"cache_table"} and defined $that->{"cache_table"}
exists $that->{"cache_table"} defined $that->{"cache_table"}
Truth table33%1/3
A and B
A= exists $that->{"cache_table"}B= defined $that->{"cache_table"}
ABresult
0X0
100
111
718 {
719 3 $self->cache_table( $that->{cache_table} );
720 }
721  
722 3 ▶ if( CORE::exists( $param->{cache_query} ) && defined( $param->{cache_query} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param->{'cache_query'} and defined $param->{'cache_query'}) { } 0 3 3
elsif (exists $that->{'cache_query'} and defined $that->{'cache_query'}) { } 3 0 3
Condition33%1/3
exists $param->{"cache_query"} and defined $param->{"cache_query"}
!ll&&!rl&&r
300
MC/DC0%0/2
exists $param->{"cache_query"} and defined $param->{"cache_query"}
exists $param->{"cache_query"} defined $param->{"cache_query"}
Truth table33%1/3
A and B
A= exists $param->{"cache_query"}B= defined $param->{"cache_query"}
ABresult
0X0
100
111
723 {
724 0 $self->cache_query( CORE::delete( $param->{cache_query} ) );
725 }
726 ▶ elsif( CORE::exists( $that->{cache_query} ) && defined( $that->{cache_query} ) )
Condition33%1/3
exists $that->{"cache_query"} and defined $that->{"cache_query"}
!ll&&!rl&&r
003
MC/DC0%0/2
exists $that->{"cache_query"} and defined $that->{"cache_query"}
exists $that->{"cache_query"} defined $that->{"cache_query"}
Truth table33%1/3
A and B
A= exists $that->{"cache_query"}B= defined $that->{"cache_query"}
ABresult
0X0
100
111
727 {
728 3 $self->cache_query( $that->{cache_query} );
729 }
730  
731 3 ▶ if( CORE::exists( $param->{cache_size} ) && defined( $param->{cache_size} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param->{'cache_size'} and defined $param->{'cache_size'}) { } 0 3 3
elsif (exists $that->{'cache_size'} and defined $that->{'cache_size'}) { } 3 0 3
Condition33%1/3
exists $param->{"cache_size"} and defined $param->{"cache_size"}
!ll&&!rl&&r
300
MC/DC0%0/2
exists $param->{"cache_size"} and defined $param->{"cache_size"}
exists $param->{"cache_size"} defined $param->{"cache_size"}
Truth table33%1/3
A and B
A= exists $param->{"cache_size"}B= defined $param->{"cache_size"}
ABresult
0X0
100
111
732 {
733 0 $self->cache_size( $param->{cache_size} );
734 }
735 ▶ elsif( CORE::exists( $that->{cache_size} ) && defined( $that->{cache_size} ) )
Condition33%1/3
exists $that->{"cache_size"} and defined $that->{"cache_size"}
!ll&&!rl&&r
003
MC/DC0%0/2
exists $that->{"cache_size"} and defined $that->{"cache_size"}
exists $that->{"cache_size"} defined $that->{"cache_size"}
Truth table33%1/3
A and B
A= exists $that->{"cache_size"}B= defined $that->{"cache_size"}
ABresult
0X0
100
111
736 {
737 3 $self->cache_size( $that->{cache_size} );
738 }
739  
740 3 ▶ if( CORE::exists( $param->{use_cache} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param->{'use_cache'}) { } 0 3 3
elsif (exists $param->{'cache'}) { } 0 3 3
741 {
742 0 $self->{cache} = CORE::delete( $param->{use_cache} );
743 }
744 elsif( CORE::exists( $param->{cache} ) )
745 {
746 0 $self->{cache} = CORE::delete( $param->{cache} );
747 }
748 else
749 {
750 3 $self->{cache} = $USE_CACHE;
751 }
752  
753 3 ▶ if( CORE::exists( $param->{serialiser} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param->{'serialiser'}) { } 0 3 3
elsif (exists $param->{'serializer'}) { } 0 3 3
754 {
755 0 $self->{serialiser} = CORE::delete( $param->{serialiser} );
756 }
757 elsif( CORE::exists( $param->{serializer} ) )
758 {
759 0 $self->{serialiser} = CORE::delete( $param->{serializer} );
760 }
761 else
762 {
763 3 $self->{serialiser} = $SERIALISER;
764 }
765  
766 3 ▶ my $id = CORE::exists( $param->{id} ) ? CORE::delete( $param->{id} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $param->{'id'} ? : 1 2 3
767 3 ▶ if( defined( $id ) && CORE::length( $id ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and length $id) { } 1 2 3
Condition66%2/3
defined $id and length $id
!ll&&!rl&&r
201
MC/DC50%1/2
defined $id and length $id
defined $id length $id
Truth table66%2/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
768 {
769 1 $self->id( $id );
770 }
771 else
772 {
773 2 $self->id( $self->_new_connection_id );
774 }
775  
776 3 ▶ $self->{unknown_field} = CORE::delete( $param->{unknown_field} ) if( CORE::exists( $param->{unknown_field} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $param->{"unknown_field"} 0 3 3
777  
778 # Other remaining params, we check if they are supported with a corresponding method
779 # We do all this jazz so we can handle other parameters a bit more dynamically.
780 3 foreach my $key ( keys( %$param ) )
781 {
782 # Those are special, and are dealt with a bit later
783 8 ▶ if( $key eq 'opt' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server" or $key eq "login" or $key eq "passwd" or $key eq "driver" or $key eq "use_bind") 6 2 8
Condition70%17/24
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server" or $key eq "login" or $key eq "passwd" or $key eq "driver" or $key eq "use_bind"
l!l&&r!l&&!r
602
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server" or $key eq "login" or $key eq "passwd" or $key eq "driver"
l!l&&r!l&&!r
332
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server" or $key eq "login" or $key eq "passwd"
l!l&&r!l&&!r
305
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server" or $key eq "login"
l!l&&r!l&&!r
305
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server"
l!l&&r!l&&!r
305
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host"
l!l&&r!l&&!r
305
$key eq "opt" or $key eq "database" or $key eq "db"
l!l&&r!l&&!r
305
$key eq "opt" or $key eq "database"
l!l&&r!l&&!r
035
MC/DC22%2/9
$key eq "opt" or $key eq "database" or $key eq "db" or $key eq "host" or $key eq "server" or $key eq "login" or $key eq "passwd" or $key eq "driver" or $key eq "use_bind"
$key eq "opt" $key eq "database" $key eq "db" $key eq "host" $key eq "server" $key eq "login" $key eq "passwd" $key eq "driver" $key eq "use_bind"
Truth table30%3/10
A or B or C or D or E or F or G or H or I
A= $key eq "opt"B= $key eq "database"C= $key eq "db"D= $key eq "host"E= $key eq "server"F= $key eq "login"G= $key eq "passwd"H= $key eq "driver"I= $key eq "use_bind"
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
784 $key eq 'database' ||
785 $key eq 'db' ||
786 $key eq 'host' ||
787 $key eq 'server' ||
788 $key eq 'login' ||
789 $key eq 'passwd' ||
790 $key eq 'driver' ||
791 $key eq 'use_bind' )
792 {
793 6 next;
794 }
795 2 ▶ if( my $coderef = $self->can( $key ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = $self->can($key)) 0 2 2
796 {
797 0 $coderef->( $self, CORE::delete( $param->{ $key } ) );
798 }
799 }
800  
801 3 ▶ $param = $self->_check_connect_param( $param ) || return( $this->pass_error( $self->error ) );
Condition50%1/2
$self->_check_connect_param($param) || (return $this->pass_error($self->error))
l!l
30
MC/DC0%0/1
$self->_check_connect_param($param) || (return $this->pass_error($self->error))
$self->_check_connect_param($param)
Truth table50%1/2
A
A= $self->_check_connect_param($param)
Aresult
11
00
802 3 my $opt = {};
803 3 ▶ if( exists( $param->{opt} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param->{"opt"}) 3 0 3
804 {
805 3 $opt = CORE::delete( $param->{opt} );
806 3 $opt = $self->_check_default_option( $opt );
807 }
808 # print( STDERR ref( $self ), "::connect(): \$param is: ", $self->dumper( $param ), "\n" );
809 $self->{database} = CORE::exists( $param->{database} )
810 ? CORE::delete( $param->{database} )
811 : CORE::exists( $param->{db} )
812 ? CORE::delete( $param->{db} )
813 3 ▶ : undef();
Branch: 2 branches
BranchTrueFalseTotal
exists $param->{'database'} ? : 3 0 3
exists $param->{'db'} ? : 0 0 0
814 $self->{host} = CORE::exists( $param->{host} )
815 ? CORE::delete( $param->{host} )
816 : CORE::exists( $param->{server} )
817 ? CORE::delete( $param->{server} )
818 3 ▶ : undef();
Branch: 2 branches
BranchTrueFalseTotal
exists $param->{'host'} ? : 3 0 3
exists $param->{'server'} ? : 0 0 0
819 3 $self->{port} = CORE::delete( $param->{port} );
820 # $self->{database} = CORE::delete( $param->{ 'db' } );
821 3 $self->{login} = CORE::delete( $param->{login} );
822 3 $self->{passwd} = CORE::delete( $param->{passwd} );
823 3 $self->{driver} = CORE::delete( $param->{driver} );
824 $self->{bind} = CORE::exists( $param->{use_bind} )
825 ? CORE::delete( $param->{use_bind} )
826 3 ▶ : $USE_BIND;
Branch: 1 branch
BranchTrueFalseTotal
exists $param->{'use_bind'} ? : 0 3 3
827  
828 # If parameters starting with an upper case are provided, they are DBI database parameters
829 #my @dbi_opts = grep( /^[A-Z][a-zA-Z]+/, keys( %$param ) );
830 #@$opt{ @dbi_opts } = @$param{ @dbi_opts };
831  
832  
833 3 ▶ if( my $driver = $self->driver )
Branch: 1 branch
BranchTrueFalseTotal
if (my $driver = $self->driver) 3 0 3
834 {
835 3 local $@;
836 3 ▶ my $drh = eval {
Condition50%1/2
eval { do { 'DBI'->install_driver($driver) } } || (return $this->error($@ || $DBI::errstr))
l!l
30
MC/DC0%0/1
eval { do { 'DBI'->install_driver($driver) } } || (return $this->error($@ || $DBI::errstr))
eval { do { 'DBI'->install_driver($driver) } }
Truth table50%1/2
A
A= eval { do { 'DBI'->install_driver($driver) } }
Aresult
11
00
837 3 ▶ DBI->install_driver( $driver )
Condition0%0/3
$@ || $DBI::errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $DBI::errstr
$@ $DBI::errstr
Truth table0%0/3
A || B
A= $@B= $DBI::errstr
ABresult
1X1
011
000
838 } || return( $this->error( $@ || $DBI::errstr ) );
839 3 $self->{drh} = $drh;
840 }
841 3 ▶ $opt->{RaiseError} = 0 if( !CORE::exists( $opt->{RaiseError} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"RaiseError"} 3 0 3
842 3 ▶ $opt->{AutoCommit} = 1 if( !CORE::exists( $opt->{AutoCommit} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"AutoCommit"} 3 0 3
843 3 ▶ $opt->{PrintError} = 0 if( !CORE::exists( $opt->{PrintError} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"PrintError"} 3 0 3
844 3 $self->{opt} = $opt;
845 3 ▶ my $dbh = $self->_dbi_connect || return( $this->pass_error( $self->error ) );
Condition50%1/2
$self->_dbi_connect || (return $this->pass_error($self->error))
l!l
30
MC/DC0%0/1
$self->_dbi_connect || (return $this->pass_error($self->error))
$self->_dbi_connect
Truth table50%1/2
A
A= $self->_dbi_connect
Aresult
11
00
846 # This is possibly a Apache::DBI::db object
847 3 $self->{dbh} = $dbh;
848 #$self->param(
849 # ## Do not allow SELECT that will take too long or too much resource, i.e. over 2Gb of data
850 # ## This is idiot proof mode
851 # 'SQL_BIG_SELECTS' => 0,
852 # ## SQL will abort if a DELETE or UPDATE is being executed w/o LIMIT nor WHERE clause
853 # 'SQL_SAFE_MODE' => 1,
854 #);
855 3 local $/ = "\n";
856 3 my $tables = [];
857 # 1 day
858 # my $tbl_cache_timeout = 86400;
859 3 ▶ my $host = $self->host || 'localhost';
Condition50%1/2
$self->host || 'localhost'
l!l
30
MC/DC0%0/1
$self->host || 'localhost'
$self->host
Truth table50%1/2
A
A= $self->host
Aresult
11
00
860 3 ▶ my $port = $self->port || 0;
Condition50%1/2
$self->port || 0
l!l
03
MC/DC0%0/1
$self->port || 0
$self->port
Truth table50%1/2
A
A= $self->port
Aresult
11
00
861 3 my $driver = $self->driver;
862 3 my $database = $self->database;
863 3 my $cache_params = {};
864 3 ▶ if( my $cache_dir = $self->cache_dir )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache_dir = $self->cache_dir) 3 0 3
865 {
866 3 $cache_params->{cache_dir} = $cache_dir;
867 }
868 3 $cache_params->{debug} = $self->debug;
869 3 my $cache_tables = DB::Object::Cache::Tables->new( $cache_params );
870 3 $self->cache_tables( $cache_tables );
871 3 $tables = $self->tables_info;
872 3 my $cache =
873 {
874 host => $host,
875 driver => $driver,
876 port => $port,
877 database => $database,
878 tables => $tables,
879 };
880 3 ▶ if( !defined( $cache_tables->set( $cache ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cache_tables->set($cache)) 0 3 3
881 {
882 0 warn( "Unable to write to tables cache: ", $cache_tables->error, "\n" );
883 }
884 3 return( $self );
885 }
886  
887 3 ▶sub connect_via { return( shift->_set_get_scalar( 'connect_via', @_ ) ); }
Subroutine connect_via: called CC=1 SCAR=0.0
Pod documented
888  
889 sub constant_queries_cache_get
890 0 ▶{
Subroutine constant_queries_cache_get: not called CC=24 SCAR=64.0
Pod documented
891 0 my( $self, $def ) = @_;
892 0 my $base_class = $self->base_class;
893  
894 # Because we need the database object to revive the statement handler after having thawed it.
895 0 ▶ if( ref( $self ) ne $base_class )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $base_class) 0 0 0
896 {
897 0 return( $self->error( "This method must be called by the database object itself." ) );
898 }
899  
900 0 my $dbo = $self;
901 0 ▶ my $cache_size = $dbo->cache_size // 0;
Condition0%0/2
$dbo->cache_size // 0
l!l
00
MC/DC0%0/1
$dbo->cache_size // 0
$dbo->cache_size
Truth table0%0/2
A
A= $dbo->cache_size
Aresult
11
00
902  
903 0 ▶ if( !defined( $def ) || ref( $def // '' ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $def or ref($def // "") ne "HASH") 0 0 0
Condition0%0/5
not defined $def or ref($def // "") ne "HASH"
l!l&&r!l&&!r
000
$def // ""
l!l
00
MC/DC0%0/2
not defined $def or ref($def // "") ne "HASH"
not defined $def $def
Truth table0%0/3
not(A) or B
A= not defined $defB= $def
ABresult
1X1
011
000
904 {
905 0 ▶ return( $self->error( "Parameter provided must be a hash, but I got '", $self->_str_val( $def // 'undef' ), "'." ) );
Condition0%0/2
$def // "undef"
l!l
00
MC/DC0%0/1
$def // "undef"
$def
Truth table0%0/2
A
A= $def
Aresult
11
00
906 }
907  
908 0 foreach my $k ( qw( pack file line ) )
909 {
910 return( $self->error( "Parameter \"$k\" is missing from the hash." ) )
911 0 ▶ if( !defined( $def->{ $k } ) || !CORE::length( $def->{ $k } // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{$k} and length($def->{$k} // "") 0 0 0
Condition0%0/5
defined $def->{$k} and length($def->{$k} // "")
!ll&&!rl&&r
000
$def->{$k} // ""
l!l
00
MC/DC0%0/2
defined $def->{$k} and length($def->{$k} // "")
defined $def->{$k} $def->{$k}
Truth table0%0/3
A and B
A= defined $def->{$k}B= $def->{$k}
ABresult
0X0
100
111
912 }
913  
914 0 my $cache_key = CORE::join( '|', @$def{qw( pack file line )} );
915 0 ▶ my $serialiser = CORE::delete( $def->{serialiser} ) || $DB::Object::SERIALISER || 'Storable';
Condition0%0/5
delete $def->{'serialiser'} || $DB::Object::SERIALISER || 'Storable'
l!l
00
delete $def->{"serialiser"} or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $def->{'serialiser'} || $DB::Object::SERIALISER || 'Storable'
delete $def->{"serialiser"} $DB::Object::SERIALISER
Truth table0%0/3
A or B
A= delete $def->{"serialiser"}B= $DB::Object::SERIALISER
ABresult
1X1
011
000
916  
917 0 my $lock;
918 0 ▶ my $repo = Module::Generic::Global->new( queries_cache => $base_class,
Condition0%0/2
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Aresult
11
00
919 max_size => $cache_size,
920 serialiser => $serialiser,
921 key => $cache_key,
922 ) || return( $self->pass_error( Module::Generic::Global->error ) );
923 0 $repo->lock;
924  
925 0 my $store = $repo->get;
926 0 ▶ return( '' ) if( !$store );
Branch: 1 branch
BranchTrueFalseTotal
unless $store 0 0 0
927  
928 # $ts is thee timestamp of the file recorded at the time
929 0 ▶ my $ts = $store->{ts} || return( $self->error( "No timestamp set in this constant statement object." ) );
Condition0%0/2
$store->{'ts'} || (return $self->error('No timestamp set in this constant statement object.'))
l!l
00
MC/DC0%0/1
$store->{'ts'} || (return $self->error('No timestamp set in this constant statement object.'))
$store->{'ts'}
Truth table0%0/2
A
A= $store->{'ts'}
Aresult
11
00
930 0 ▶ my $sth = $repo->{sth} || return( '' );
Condition0%0/2
$repo->{'sth'} || (return '')
l!l
00
MC/DC0%0/1
$repo->{'sth'} || (return '')
$repo->{'sth'}
Truth table0%0/2
A
A= $repo->{'sth'}
Aresult
11
00
931 # A DB::Object::Statement object
932 0 my $qo = $sth->query_object;
933 0 ▶ return( '' ) if( !CORE::length( $def->{file} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $def->{"file"} 0 0 0
934 0 ▶ return( '' ) if( !-e( $def->{file} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless -e $def->{"file"} 0 0 0
935 0 ▶ return( '' ) if( ( CORE::stat( $def->{file} ) )[9] != $ts );
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::stat $def->{"file"})[9] != $ts 0 0 0
936 0 ▶ return( $self->error( "Query object retrieved from constant query cache is void!" ) ) if( !$qo );
Branch: 1 branch
BranchTrueFalseTotal
unless $qo 0 0 0
937 0 ▶ return( $self->error( "Query object retrieved from constant query cache is not a DB::Object::Query object or one of its sub classes." ) ) if( !$self->_is_object( $qo ) || !$qo->isa( 'DB::Object::Query' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($qo) and $qo->isa("DB::Object::Query") 0 0 0
Condition0%0/3
$self->_is_object($qo) and $qo->isa("DB::Object::Query")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($qo) and $qo->isa("DB::Object::Query")
$self->_is_object($qo) $qo->isa("DB::Object::Query")
Truth table0%0/3
A and B
A= $self->_is_object($qo)B= $qo->isa("DB::Object::Query")
ABresult
0X0
100
111
938 0 ▶ return if( $self->database ne $qo->database_object->database );
Branch: 1 branch
BranchTrueFalseTotal
if $self->database ne $qo->database_object->database 0 0 0
939  
940 0 return( $sth );
941 }
942  
943 sub constant_queries_cache_set
944 0 ▶{
Subroutine constant_queries_cache_set: not called CC=18 SCAR=58.3
Pod documented
945 0 my( $self, $def ) = @_;
946 0 my $base_class = $self->base_class;
947  
948 # Because we need the database object to revive the statement handler after having thawed it.
949 0 ▶ if( ref( $self ) ne $base_class )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $base_class) 0 0 0
950 {
951 0 return( $self->error( "This method must be called by the database object itself." ) );
952 }
953  
954  
955 0 ▶ if( !defined( $def ) || ref( $def // '' ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $def or ref($def // "") ne "HASH") 0 0 0
Condition0%0/5
not defined $def or ref($def // "") ne "HASH"
l!l&&r!l&&!r
000
$def // ""
l!l
00
MC/DC0%0/2
not defined $def or ref($def // "") ne "HASH"
not defined $def $def
Truth table0%0/3
not(A) or B
A= not defined $defB= $def
ABresult
1X1
011
000
956 {
957 0 ▶ return( $self->error( "Parameter provided must be a hash, but I got '", $self->_str_val( $def // 'undef' ), "'." ) );
Condition0%0/2
$def // "undef"
l!l
00
MC/DC0%0/1
$def // "undef"
$def
Truth table0%0/2
A
A= $def
Aresult
11
00
958 }
959  
960 0 foreach my $k ( qw( pack file line ) )
961 {
962 0 ▶ if( !defined( $def->{ $k } ) || !CORE::length( $def->{ $k } // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $def->{$k} and length($def->{$k} // "")) 0 0 0
Condition0%0/5
defined $def->{$k} and length($def->{$k} // "")
!ll&&!rl&&r
000
$def->{$k} // ""
l!l
00
MC/DC0%0/2
defined $def->{$k} and length($def->{$k} // "")
defined $def->{$k} $def->{$k}
Truth table0%0/3
A and B
A= defined $def->{$k}B= $def->{$k}
ABresult
0X0
100
111
963 {
964 0 return( $self->error( "Parameter \"$k\" is missing from the hash." ) );
965 }
966 }
967  
968 0 my $dbo = $self;
969 0 ▶ my $cache_size = $dbo->cache_size // 0;
Condition0%0/2
$dbo->cache_size // 0
l!l
00
MC/DC0%0/1
$dbo->cache_size // 0
$dbo->cache_size
Truth table0%0/2
A
A= $dbo->cache_size
Aresult
11
00
970  
971 return( $self->error( "Parameter \"query_object\" is missing from the hash." ) )
972 0 ▶ if( !defined( $def->{query_object} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{"query_object"} 0 0 0
973  
974 0 ▶ if( !$self->_is_object( $def->{query_object} ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_object($def->{"query_object"}) and $def->{"query_object"}->isa("DB::Object::Query")) 0 0 0
Condition0%0/3
$self->_is_object($def->{"query_object"}) and $def->{"query_object"}->isa("DB::Object::Query")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($def->{"query_object"}) and $def->{"query_object"}->isa("DB::Object::Query")
$self->_is_object($def->{"query_object"}) $def->{"query_object"}->isa("DB::Object::Query")
Truth table0%0/3
A and B
A= $self->_is_object($def->{"query_object"})B= $def->{"query_object"}->isa("DB::Object::Query")
ABresult
0X0
100
111
975 !$def->{query_object}->isa( 'DB::Object::Query' ) )
976 {
977 0 return( $self->error( "Provided query object is not a DB::Object::Query." ) );
978 }
979  
980 0 $def->{ts} = [CORE::stat( $def->{file} )]->[9];
981  
982 0 my $cache_key = CORE::join( '|', @$def{qw( pack file line )} );
983 0 ▶ my $serialiser = CORE::delete( $def->{serialiser} ) || $DB::Object::SERIALISER || 'Storable';
Condition0%0/5
delete $def->{'serialiser'} || $DB::Object::SERIALISER || 'Storable'
l!l
00
delete $def->{"serialiser"} or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $def->{'serialiser'} || $DB::Object::SERIALISER || 'Storable'
delete $def->{"serialiser"} $DB::Object::SERIALISER
Truth table0%0/3
A or B
A= delete $def->{"serialiser"}B= $DB::Object::SERIALISER
ABresult
1X1
011
000
984  
985 0 ▶ my $repo = Module::Generic::Global->new( queries_cache => $base_class,
Condition0%0/2
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Aresult
11
00
986 max_size => $cache_size,
987 serialiser => $serialiser,
988 key => $cache_key,
989 ) || return( $self->pass_error( Module::Generic::Global->error ) );
990 0 $repo->lock;
991 0 ▶ $repo->set( $def ) || return( $self->pass_error( $repo->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$repo->set($def) or return $self->pass_error($repo->error) 0 0 0
992  
993 0 return( $def );
994 }
995  
996 sub constant_queries_cache_del
997 0 ▶{
Subroutine constant_queries_cache_del: not called CC=14 SCAR=53.5
Pod documented
998 0 my( $self, $def ) = @_;
999 0 my $base_class = $self->base_class;
1000  
1001 # Because we need the database object to revive the statement handler after having thawed it.
1002 0 ▶ if( ref( $self ) ne $base_class )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $base_class) 0 0 0
1003 {
1004 0 return( $self->error( "This method must be called by the database object itself." ) );
1005 }
1006  
1007 0 ▶ if( !defined( $def ) || ref( $def // '' ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $def or ref($def // "") ne "HASH") 0 0 0
Condition0%0/5
not defined $def or ref($def // "") ne "HASH"
l!l&&r!l&&!r
000
$def // ""
l!l
00
MC/DC0%0/2
not defined $def or ref($def // "") ne "HASH"
not defined $def $def
Truth table0%0/3
not(A) or B
A= not defined $defB= $def
ABresult
1X1
011
000
1008 {
1009 0 ▶ return( $self->error( "Parameter provided must be a hash, but I got '", $self->_str_val( $def // 'undef' ), "'." ) );
Condition0%0/2
$def // "undef"
l!l
00
MC/DC0%0/1
$def // "undef"
$def
Truth table0%0/2
A
A= $def
Aresult
11
00
1010 }
1011  
1012 0 foreach my $k ( qw( pack file line ) )
1013 {
1014 return( $self->error( "Parameter \"$k\" is missing from the hash." ) )
1015 0 ▶ if( !defined( $def->{ $k } ) || !CORE::length( $def->{ $k } // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{$k} and length($def->{$k} // "") 0 0 0
Condition0%0/5
defined $def->{$k} and length($def->{$k} // "")
!ll&&!rl&&r
000
$def->{$k} // ""
l!l
00
MC/DC0%0/2
defined $def->{$k} and length($def->{$k} // "")
defined $def->{$k} $def->{$k}
Truth table0%0/3
A and B
A= defined $def->{$k}B= $def->{$k}
ABresult
0X0
100
111
1016 }
1017  
1018 0 my $dbo = $self;
1019 0 ▶ my $cache_size = $dbo->cache_size // 0;
Condition0%0/2
$dbo->cache_size // 0
l!l
00
MC/DC0%0/1
$dbo->cache_size // 0
$dbo->cache_size
Truth table0%0/2
A
A= $dbo->cache_size
Aresult
11
00
1020 0 my $cache_key = CORE::join( '|', @$def{qw( pack file line )} );
1021 0 ▶ my $serialiser = CORE::delete( $def->{serialiser} ) || $DB::Object::SERIALISER || 'Storable';
Condition0%0/5
delete $def->{'serialiser'} || $DB::Object::SERIALISER || 'Storable'
l!l
00
delete $def->{"serialiser"} or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $def->{'serialiser'} || $DB::Object::SERIALISER || 'Storable'
delete $def->{"serialiser"} $DB::Object::SERIALISER
Truth table0%0/3
A or B
A= delete $def->{"serialiser"}B= $DB::Object::SERIALISER
ABresult
1X1
011
000
1022  
1023 0 ▶ my $repo = Module::Generic::Global->new( queries_cache => $base_class,
Condition0%0/2
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('queries_cache', $base_class, 'max_size', $cache_size, 'serialiser', $serialiser, 'key', $cache_key)
Aresult
11
00
1024 max_size => $cache_size,
1025 serialiser => $serialiser,
1026 key => $cache_key,
1027 ) || return( $self->pass_error( Module::Generic::Global->error ) );
1028 0 $repo->lock;
1029 0 $repo->remove;
1030 0 $repo->unlock;
1031 0 return(1);
1032 }
1033  
1034 # See also datatype_to_constant()
1035 sub constant_to_datatype
1036 0 ▶{
Subroutine constant_to_datatype: not called CC=5 SCAR=34.0
Pod documented
1037 0 my $self = shift( @_ );
1038 0 ▶ return unless( scalar( @_ ) && defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ and defined $_[0] 0 0 0
Condition0%0/3
scalar @_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ and defined $_[0]
scalar @_ defined $_[0]
Truth table0%0/3
A and B
A= scalar @_B= defined $_[0]
ABresult
0X0
100
111
1039 0 my $this = shift( @_ );
1040 0 my $ref = $self->datatypes;
1041 0 foreach my $t ( keys( %$ref ) )
1042 {
1043 0 ▶ return( $t ) if( $ref->{ $t } eq $this );
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{$t} eq $this 0 0 0
1044 }
1045 0 return;
1046 }
1047  
1048 sub copy
1049 0 ▶{
Subroutine copy: not called CC=2 SCAR=17.9
Pod documented
1050 0 my $self = shift( @_ );
1051 0 my $opts = $self->_get_args_as_hash( @_ );
1052 0 my $ref = $self->select->fetchrow_hashref();
1053 0 my $keys = keys( %$opts );
1054 0 @$ref{ @$keys } = @$opts{ @$keys };
1055 0 ▶ return(0) if( !scalar( keys( %$ref ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$ref 0 0 0
1056 0 $self->insert( $ref );
1057 0 return(1);
1058 }
1059  
1060 0 ▶sub create_db { return( shift->error( "The driver has not implemented the create database method create_db." ) ); }
Subroutine create_db: not called CC=1 SCAR=6.9
Pod documented
1061  
1062 0 ▶sub create_table { return( shift->error( "The driver has not implemented the create table method create_table." ) ); }
Subroutine create_table: not called CC=1 SCAR=6.9
Pod documented
1063  
1064 sub data_sources($;\%)
1065 0 ▶{
Subroutine data_sources: not called CC=3 SCAR=24.8
Pod documented
1066 0 my $self = shift( @_ );
1067 0 my $opts = $self->_get_args_as_hash( @_ );
1068 0 ▶ my $driver = $self->{driver} || return( $self->error( "No driver to to use to check for data sources." ) );
Condition0%0/2
$self->{'driver'} || (return $self->error('No driver to to use to check for data sources.'))
l!l
00
MC/DC0%0/1
$self->{'driver'} || (return $self->error('No driver to to use to check for data sources.'))
$self->{'driver'}
Truth table0%0/2
A
A= $self->{'driver'}
Aresult
11
00
1069 0 ▶ return( DBI->data_sources( $driver, ( scalar( keys( %$opts ) ) ? $opts : () ) ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$opts ? : 0 0 0
1070 }
1071  
1072 sub data_type
1073 0 ▶{
Subroutine data_type: not called CC=13 SCAR=52.0
Pod documented
1074 0 my $self = shift( @_ );
1075 0 ▶ my $type = @_ == 1 ? shift( @_ ) : [ @_ ] if( @_ );
Branch: 2 branches
BranchTrueFalseTotal
if @_ 0 0 0
@_ == 1 ? : 0 0 0
1076 my $ref = eval
1077 0 {
1078 0 ▶ local $SIG{__DIE__} = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1079 0 ▶ local $SIG{__WARN__} = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1080 0 $self->{dbh}->type_info_all();
1081 };
1082 0 ▶ return( $self->error( "type_info_all() is unsupported by vendor '$self->{ 'driver' }'." ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1083 # First item is a reference to hash containing the order of the header
1084 0 my $header = shift( @$ref );
1085 0 my $hash = {};
1086 0 my $name_idx = $header->{TYPE_NAME};
1087 0 my @found = ();
1088 0 ▶ if( $type )
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
1089 {
1090 0 ▶ my @types = ref( $type ) ? @$type : ( $type );
Branch: 1 branch
BranchTrueFalseTotal
ref $type ? : 0 0 0
1091 0 foreach my $requested ( @types )
1092 {
1093 0 push( @found, grep{ uc( $requested ) eq $_->[ $name_idx ] } @$ref );
1094 }
1095 }
1096 else
1097 {
1098 0 @found = @$ref;
1099 }
1100 # Stop. No need to go further
1101 0 ▶ return( wantarray() ? () : undef() ) if( !@found );
Branch: 2 branches
BranchTrueFalseTotal
unless @found 0 0 0
wantarray ? : 0 0 0
1102 0 my @names = map{ lc( $_ ) } keys( %$header );
1103 0 my $len = scalar( keys( %$header ) );
1104 0 my @order = values( %$header );
1105 map
1106 {
1107 0 ▶ next if( @$_ != $len );
Branch: 1 branch
BranchTrueFalseTotal
if @$_ != $len 0 0 0
1108 0 my %data;
1109 0 @data{ @names } = @{ $_ }[ @order ];
1110 0 $hash->{ lc( $_->[ $name_idx ] ) } = \%data;
1111 } @found;
1112 0 ▶ return( wantarray() ? () : undef() ) if( !%$hash );
Branch: 2 branches
BranchTrueFalseTotal
unless %$hash 0 0 0
wantarray ? : 0 0 0
1113 0 ▶ return( wantarray() ? %$hash : $hash );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1114 }
1115  
1116 sub database
1117 3 ▶{
Subroutine database: called CC=1 SCAR=0.0
Pod documented
1118 # Read only
1119 3 return( shift->{database} );
1120 }
1121  
1122 0 ▶sub databases { return( shift->error( "Method databases() is not implemented by driver." ) ); }
Subroutine databases: not called CC=1 SCAR=6.9
Pod documented
1123  
1124 sub datatype_dict
1125 0 ▶{
Subroutine datatype_dict: not called CC=6 SCAR=34.2
Pod documented
1126 0 my $self = shift( @_ );
1127 0 ▶ my $class = ( ref( $self ) || $self );
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1128 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1129 0 my $sym = $self->_get_symbol( $class => '$DATATYPES_DICT' );
1130 0 ▶ if( !defined( $sym ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sym) 0 0 0
1131 {
1132 0 ▶ return( $self->pass_error ) if( $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if $self->error 0 0 0
1133 0 return( $self->error( "No global variable \$DATATYPES_DICT defined in class $class" ) );
1134 }
1135 0 my $dict = $$sym;
1136 0 ▶ return( $self->error( "Symbol found for \$DATATYPES_DICT in class $class did not resolve into an expecxted hash reference." ) ) if( ref( $dict ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $dict ne "HASH" 0 0 0
1137 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1138 {
1139 0 return( $dict->{ lc( shift( @_ ) ) } );
1140 }
1141 0 return( $dict );
1142 }
1143  
1144 # See also constant_to_datatype()
1145 sub datatype_to_constant
1146 0 ▶{
Subroutine datatype_to_constant: not called CC=4 SCAR=30.0
Pod documented
1147 0 my $self = shift( @_ );
1148 0 ▶ my $ref = $self->datatypes || return( $self->pass_error );
Condition0%0/2
$self->datatypes || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->datatypes || (return $self->pass_error)
$self->datatypes
Truth table0%0/2
A
A= $self->datatypes
Aresult
11
00
1149 0 ▶ return unless( scalar( @_ ) && defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ and defined $_[0] 0 0 0
Condition0%0/3
scalar @_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ and defined $_[0]
scalar @_ defined $_[0]
Truth table0%0/3
A and B
A= scalar @_B= defined $_[0]
ABresult
0X0
100
111
1150 0 return( $ref->{ lc( shift( @_ ) ) } );
1151 }
1152  
1153 # Returns an hash of SQL constant name to its value
1154 sub datatypes
1155 0 ▶{
Subroutine datatypes: not called CC=2 SCAR=17.9
Pod documented
1156 0 my $self = shift( @_ );
1157 0 ▶ my $dict = $self->datatype_dict || return( $self->pass_error );
Condition0%0/2
$self->datatype_dict || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->datatype_dict || (return $self->pass_error)
$self->datatype_dict
Truth table0%0/2
A
A= $self->datatype_dict
Aresult
11
00
1158 0 my $ref = +{ map{ $_ => $dict->{ $_ }->{constant} } keys( %$dict ) };
1159 0 return( $ref );
1160 }
1161  
1162 sub disconnect($)
1163 2 ▶{
Subroutine disconnect: called CC=1 SCAR=0.4
Pod documented
1164 2 my $self = shift( @_ );
1165 # my( $pack, $file, $line ) = caller();
1166 # print( STDERR "disconnect() called from package '$pack' in file '$file' at line '$line'.\n" );
1167 2 my $rc = $self->{dbh}->disconnect( @_ );
1168 0 return( $rc );
1169 }
1170  
1171 sub do($;$@)
1172 1 ▶{
Subroutine do: called CC=7 SCAR=21.0
Pod documented
1173 1 my $self = shift( @_ );
1174 # $rc = $dbh->do( $statement ) || die( $dbh->errstr );
1175 # $rc = $dbh->do( $statement, \%attr ) || die( $dbh->errstr );
1176 # $rv = $dbh->do( $statement, \%attr, @bind_values ) || ...
1177 # my( $rows_deleted ) = $dbh->do(
1178 # q{
1179 # DELETE FROM table WHERE status = ?
1180 # }, undef(), 'DONE' ) || die( $dbh->errstr );
1181 1 my $query = shift( @_ );
1182 1 ▶ my $opt_ref = shift( @_ ) || undef();
Condition50%1/2
shift @_ || undef()
l!l
01
MC/DC0%0/1
shift @_ || undef()
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1183 1 ▶ my $param_ref = shift( @_ ) || [];
Condition50%1/2
shift @_ || []
l!l
01
MC/DC0%0/1
shift @_ || []
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1184 1 ▶ my $dbh = $self->can( 'database_object' ) ? $self->database_object : $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->can('database_object') ? : 0 1 1
1185 1 ▶ $dbh or return( $self->error( "Could not find database handler." ) );
Branch: 1 branch
BranchTrueFalseTotal
$dbh or return $self->error("Could not find database handler.") 1 0 1
1186 1 ▶ my $sth = $dbh->prepare( $query, $opt_ref ) ||
Condition50%1/2
$dbh->prepare($query, $opt_ref) || (return $self->error("Error while preparing do query:\n$query", $dbh->errstr))
l!l
10
MC/DC0%0/1
$dbh->prepare($query, $opt_ref) || (return $self->error("Error while preparing do query:\n$query", $dbh->errstr))
$dbh->prepare($query, $opt_ref)
Truth table50%1/2
A
A= $dbh->prepare($query, $opt_ref)
Aresult
11
00
1187 return( $self->error( "Error while preparing do query:\n$query", $dbh->errstr() ) );
1188 1 ▶ $sth->execute( @$param_ref ) ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@$param_ref) or return $self->error("Error while executing do query:\n$query", $sth->errstr) 1 0 1
1189 return( $self->error( "Error while executing do query:\n$query", $sth->errstr() ) );
1190 # my $rows = $sth->rows();
1191 # return( ( $rows == 0 ) ? "0E0" : $rows );
1192 1 return( $sth );
1193 }
1194  
1195 6 ▶sub driver { return( shift->_set_get( 'driver' ) ); }
Subroutine driver: called CC=1 SCAR=0.0
Pod documented
1196  
1197 sub enhance
1198 1 ▶{
Subroutine enhance: called CC=2 SCAR=7.0
Pod documented
1199 1 my $self = shift( @_ );
1200 1 my $prev = $self->{enhance};
1201 1 ▶ $self->{enhance} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
1202 1 return( $prev );
1203 }
1204  
1205 sub err(@)
1206 0 ▶{
Subroutine err: not called CC=3 SCAR=24.8
Pod documented
1207 0 my $self = shift( @_ );
1208 # $rv = $h->err;
1209 0 ▶ if( defined( $self->{sth} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'sth'}) { } 0 0 0
elsif ($self->{'dbh'}) { } 0 0 0
1210 {
1211 0 return( $self->{sth}->err() );
1212 }
1213 elsif( $self->{dbh} )
1214 {
1215 0 return( $self->{dbh}->err() );
1216 }
1217 #else
1218 #{
1219 # return( $self->{ 'drh' }->err() );
1220 # return( DBI::err();
1221 #}
1222 }
1223  
1224 sub errno
1225 0 ▶{
Subroutine errno: not called CC=1 SCAR=6.9
Pod documented
1226 0 goto( &err );
1227 }
1228  
1229 sub errmesg
1230 0 ▶{
Subroutine errmesg: not called CC=1 SCAR=6.9
Pod documented
1231 0 goto( &errstr );
1232 }
1233  
1234 sub errstr(@)
1235 0 ▶{
Subroutine errstr: not called CC=6 SCAR=37.4
Pod documented
1236 0 my $self = shift( @_ );
1237 0 ▶ if( !ref( $self ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $self) { } 0 0 0
elsif (defined $self->{'sth'} and $self->{'sth'}->errstr) { } 0 0 0
elsif (defined $self->{'dbh'} and $self->{'dbh'}->errstr) { } 0 0 0
1238 {
1239 0 return( $DBI::errstr );
1240 }
1241 ▶ elsif( defined( $self->{sth} ) && $self->{sth}->errstr() )
Condition0%0/3
defined $self->{"sth"} and $self->{"sth"}->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"sth"} and $self->{"sth"}->errstr
defined $self->{"sth"} $self->{"sth"}->errstr
Truth table0%0/3
A and B
A= defined $self->{"sth"}B= $self->{"sth"}->errstr
ABresult
0X0
100
111
1242 {
1243 0 return( $self->{sth}->errstr() );
1244 }
1245 ▶ elsif( defined( $self->{dbh} ) && $self->{dbh}->errstr() )
Condition0%0/3
defined $self->{"dbh"} and $self->{"dbh"}->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"dbh"} and $self->{"dbh"}->errstr
defined $self->{"dbh"} $self->{"dbh"}->errstr
Truth table0%0/3
A and B
A= defined $self->{"dbh"}B= $self->{"dbh"}->errstr
ABresult
0X0
100
111
1246 {
1247 0 return( $self->{dbh}->errstr() );
1248 }
1249 else
1250 {
1251 0 return( $self->{errstr} );
1252 }
1253 }
1254  
1255 0 ▶sub FALSE { return( 'FALSE' ); }
Subroutine FALSE: not called CC=1 SCAR=6.9
Pod documented
1256  
1257 sub fatal
1258 0 ▶{
Subroutine fatal: not called CC=2 SCAR=17.9
Pod documented
1259 0 my $self = shift( @_ );
1260 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1261 {
1262 0 $self->{fatal} = int( shift( @_ ) );
1263 }
1264 0 return( $self->{fatal} );
1265 }
1266  
1267 0 ▶sub get_sql_type { return( shift->error( "The driver has not provided support for this method get_sql_type()" ) ); }
Subroutine get_sql_type: not called CC=1 SCAR=6.9
Pod documented
1268  
1269 3 ▶sub host { return( shift->_set_get_scalar( 'host', @_ ) ); }
Subroutine host: called CC=1 SCAR=0.0
Pod documented
1270  
1271 10 ▶sub id { return( shift->_set_get_scalar( 'id', @_ ) ); }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
1272  
1273 0 ▶sub IN { return( shift->_operator_object_create( 'DB::Object::IN', @_ ) ); }
Subroutine IN: not called CC=1 SCAR=6.9
Pod documented
1274  
1275 # $rv = $dbh->last_insert_id($catalog, $schema, $table, $field, \%attr);
1276 sub last_insert_id
1277 0 ▶{
Subroutine last_insert_id: not called CC=1 SCAR=6.9
Pod documented
1278 0 my $self = shift( @_ );
1279 0 return( $self->error( "Method \"last_insert_id\" has not been implemented by driver $self->{driver} (object = $self)." ) );
1280 }
1281  
1282 0 ▶sub LIKE { return( shift->_operator_object_create( 'DB::Object::LIKE', @_ ) ); }
Subroutine LIKE: not called CC=1 SCAR=6.9
Pod documented
1283  
1284 sub lock
1285 0 ▶{
Subroutine lock: not called CC=1 SCAR=6.9
Pod documented
1286 0 my $self = shift( @_ );
1287 0 return( $self->error( "Method \"lock\" has not been implemented by driver $self->{driver} (object = $self)." ) );
1288 }
1289  
1290 0 ▶sub login { return( shift->_set_get_scalar( 'login', @_ ) ); }
Subroutine login: not called CC=1 SCAR=6.9
Pod documented
1291  
1292 # This value will be passed on to newly instantiated DB::Object::Tables objects
1293 0 ▶sub no_bind { return( shift->_set_get_boolean( 'no_bind', @_ ) ); }
Subroutine no_bind: not called CC=1 SCAR=6.9
Pod documented
1294  
1295 sub no_cache
1296 0 ▶{
Subroutine no_cache: not called CC=1 SCAR=6.9
Pod documented
1297 0 my $self = shift( @_ );
1298 0 $self->{cache} = 0;
1299 0 return( $self );
1300 }
1301  
1302 0 ▶sub NOT { return( shift->_operator_object_create( 'DB::Object::NOT', @_ ) ); }
Subroutine NOT: not called CC=1 SCAR=6.9
Pod documented
1303  
1304 0 ▶sub NULL { return( 'NULL' ); }
Subroutine NULL: not called CC=1 SCAR=6.9
Pod documented
1305  
1306 0 ▶sub OR { return( shift->_operator_object_create( 'DB::Object::OR', @_ ) ); }
Subroutine OR: not called CC=1 SCAR=6.9
Pod documented
1307  
1308 1 ▶sub P { return( shift->placeholder( @_ ) ); }
Subroutine P: called CC=1 SCAR=0.0
Pod documented
1309  
1310 sub param
1311 0 ▶{
Subroutine param: not called CC=15 SCAR=54.8
Pod documented
1312 0 my $self = shift( @_ );
1313 0 ▶ return if( !@_ );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1314 0 my @supported =
1315 qw(
1316 SQL_AUTO_IS_NULL AUTOCOMMIT SQL_BIG_TABLES SQL_BIG_SELECTS
1317 SQL_BUFFER_RESULT SQL_LOW_PRIORITY_UPDATES SQL_MAX_JOIN_SIZE
1318 SQL_SAFE_MODE SQL_SELECT_LIMIT SQL_LOG_OFF SQL_LOG_UPDATE
1319 TIMESTAMP INSERT_ID LAST_INSERT_ID
1320 );
1321 0 ▶ my $params = $self->{params} ||= {};
Condition0%0/2
$self->{"params"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"params"} ||= {}
$self->{"params"}
Truth table0%0/2
A
A= $self->{"params"}
Aresult
11
00
1322 0 ▶ if( @_ == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
1323 {
1324 0 my $type = shift( @_ );
1325 0 ▶ $type = uc( $type ) if( scalar( grep{ /^$type$/i } @supported ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({/^$type$/i;} @supported) 0 0 0
1326 0 return( $params->{ $type } );
1327 }
1328 else
1329 {
1330 0 my %arg = ( @_ );
1331 0 my( $type, $value );
1332 0 my @query = ();
1333 0 ▶ while( ( $type, $value ) = each( %arg ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %arg) 0 0 0
1334 {
1335 0 my @found = grep{ /^(SQL_)?$type$/i } @supported;
1336 # SQL parameter
1337 0 ▶ if( scalar( @found ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @found) { } 0 0 0
1338 {
1339 0 $type = uc( $type );
1340 0 ▶ $value = 0 if( !defined( $value ) || $value eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 0 0 0
Condition0%0/3
not defined $value or $value eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table0%0/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
1341 0 $params->{ $type } = $value;
1342 0 ▶ if( $type eq 'AUTOCOMMIT' && $self->{dbh} && $value =~ /^(?:1|0)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "AUTOCOMMIT" and $self->{"dbh"} and $value =~ /^(?:1|0)$/) 0 0 0
Condition0%0/6
$type eq "AUTOCOMMIT" and $self->{"dbh"} and $value =~ /^(?:1|0)$/
!ll&&!rl&&r
000
$type eq "AUTOCOMMIT" and $self->{"dbh"}
!ll&&!rl&&r
000
MC/DC0%0/3
$type eq "AUTOCOMMIT" and $self->{"dbh"} and $value =~ /^(?:1|0)$/
$type eq "AUTOCOMMIT" $self->{"dbh"} $value =~ /^(?:1|0)$/
Truth table0%0/4
A and B and C
A= $type eq "AUTOCOMMIT"B= $self->{"dbh"}C= $value =~ /^(?:1|0)$/
ABCresult
0XX0
10X0
1100
1111
1343 {
1344 0 $self->{dbh}->{AutoCommit} = $value;
1345 }
1346 0 push( @query, "$type = $value" );
1347 }
1348 # Private parameter - May be anything
1349 else
1350 {
1351 0 $params->{ $type } = $value;
1352 }
1353 }
1354 0 ▶ return( $self ) if( !scalar( @query ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @query 0 0 0
1355 0 ▶ my $dbh = $self->{dbh} || return( $self->error( "Could not find database handler." ) );
Condition0%0/2
$self->{'dbh'} || (return $self->error('Could not find database handler.'))
l!l
00
MC/DC0%0/1
$self->{'dbh'} || (return $self->error('Could not find database handler.'))
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
Aresult
11
00
1356 0 my $query = 'SET ' . CORE::join( ', ', @query );
1357 0 ▶ my $sth = $dbh->prepare( $query ) ||
Condition0%0/2
$dbh->prepare($query) || (return $self->error(q[Unable to set options '], join(', ', @query), q[']))
l!l
00
MC/DC0%0/1
$dbh->prepare($query) || (return $self->error(q[Unable to set options '], join(', ', @query), q[']))
$dbh->prepare($query)
Truth table0%0/2
A
A= $dbh->prepare($query)
Aresult
11
00
1358 return( $self->error( "Unable to set options '", CORE::join( ', ', @query ), "'" ) );
1359 0 $sth->execute();
1360 0 $sth->finish();
1361 0 return( $self );
1362 }
1363 }
1364  
1365 0 ▶sub passwd { return( shift->_set_get_scalar( 'passwd', @_ ) ); }
Subroutine passwd: not called CC=1 SCAR=6.9
Pod documented
1366  
1367 sub ping(@)
1368 1 ▶{
Subroutine ping: called CC=5 SCAR=16.9
Pod documented
1369 1 my $self = shift( @_ );
1370 1 my $dbh = $self->{dbh};
1371 1 ▶ return(0) if( !$dbh );
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh 0 1 1
1372  
1373 1 my $ok = 0;
1374 1 my $errstr;
1375 1 local $@;
1376 {
1377 1 $ok = eval
1378 1 {
1379 1 my $errstr;
1380 local $SIG{__WARN__} = sub
1381 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1382 # die( $_[0] );
1383 0 $errstr = join( '', @_ );
1384 1 };
1385 1 ▶ $dbh->ping ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->ping ? : 1 0 1
1386 };
1387 }
1388  
1389 1 ▶ return(0) if( !$ok || $@ );
Branch: 1 branch
BranchTrueFalseTotal
if not $ok or $@ 0 1 1
Condition33%1/3
not $ok or $@
l!l&&r!l&&!r
001
MC/DC0%0/2
not $ok or $@
not $ok $@
Truth table33%1/3
not(A) or B
A= not $okB= $@
ABresult
1X1
011
000
1390 1 return(1);
1391 }
1392  
1393 sub ping_select(@)
1394 0 ▶{
Subroutine ping_select: not called CC=3 SCAR=24.8
Pod documented
1395 0 my $self = shift( @_ );
1396 # $rc = $dbh->ping;
1397 # Some new ping method replacement.... See Apache::DBI
1398 # my( $dbh ) = @_;
1399 0 my $ret = 0;
1400 0 local $@;
1401 eval
1402 0 {
1403 0 ▶ local( $SIG{__DIE__} ) = sub{ return( 0 ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1404 0 ▶ local( $SIG{__WARN__} ) = sub{ return( 0 ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1405 # adapt the select statement to your database:
1406 0 my $sth = $self->prepare( "SELECT 1" );
1407 0 ▶ $ret = $sth && ( $sth->execute() );
Condition0%0/3
$sth && $sth->execute
!ll&&!rl&&r
000
MC/DC0%0/2
$sth && $sth->execute
$sth $sth->execute
Truth table0%0/3
A && B
A= $sthB= $sth->execute
ABresult
0X0
100
111
1408 0 $sth->finish();
1409 };
1410 0 ▶ return( ($@) ? 0 : $ret );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
1411 }
1412  
1413 sub placeholder
1414 39 ▶{
Subroutine placeholder: called CC=4 SCAR=14.5
Pod documented
1415 39 my $self = shift( @_ );
1416 39 ▶ $self->_load_class( 'DB::Object::Placeholder' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Placeholder") or return $self->pass_error 39 0 39
1417 39 my $opts = $self->_get_args_as_hash( @_ );
1418 39 ▶ $opts->{debug} = $self->debug if( !exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 39 0 39
1419 39 ▶ my $obj = DB::Object::Placeholder->new( %$opts ) ||
Condition50%1/2
'DB::Object::Placeholder'->new(%$opts) || (return $self->pass_error('DB::Object::Placeholder'->error))
l!l
390
MC/DC0%0/1
'DB::Object::Placeholder'->new(%$opts) || (return $self->pass_error('DB::Object::Placeholder'->error))
'DB::Object::Placeholder'->new(%$opts)
Truth table50%1/2
A
A= 'DB::Object::Placeholder'->new(%$opts)
Aresult
11
00
1420 return( $self->pass_error( DB::Object::Placeholder->error ) );
1421 39 return( $obj );
1422 }
1423  
1424 3 ▶sub port { return( shift->_set_get_number( 'port', @_ ) ); }
Subroutine port: called CC=1 SCAR=0.0
Pod documented
1425  
1426 # Gateway to DB::Object::Statement
1427 sub prepare($;$)
1428 1 ▶{
Subroutine prepare: called CC=16 SCAR=38.7
Pod documented
1429 1 my $self = shift( @_ );
1430 1 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1431 1 my $query = shift( @_ );
1432 1 ▶ my $opt_ref = shift( @_ ) || undef();
Condition50%1/2
shift @_ || undef()
l!l
01
MC/DC0%0/1
shift @_ || undef()
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1433 1 my $base_class = $self->base_class;
1434 1 my $q;
1435 1 ▶ if( $self->_is_a( $query => "${base_class}::Query" ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($query, "${base_class}::Query")) { } 0 1 1
elsif ($self->_is_a($self, "${base_class}::Tables")) { } 0 1 1
1436 {
1437 0 $q = $query;
1438 0 $query = $q->as_string;
1439 }
1440 elsif( $self->_is_a( $self => "${base_class}::Tables" ) )
1441 {
1442 0 $q = $self->query_object;
1443 }
1444 1 $self->_clean_statement( \$query );
1445 # Wether we are called from DB::Object or DB::Object::Tables object
1446 1 ▶ my $dbo = $self->{dbo} || $self->{database_object} || $self;
Condition33%2/6
$self->{'dbo'} || $self->{'database_object'} || $self
l!l&&r!l&&!r
010
$self->{"dbo"} or $self->{"database_object"}
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->{'dbo'} || $self->{'database_object'} || $self
$self->{"dbo"} $self->{"database_object"} $self
Truth table25%1/4
A or B || C
A= $self->{"dbo"}B= $self->{"database_object"}C= $self
ABCresult
1XX1
01X1
0011
0000
1447 1 ▶ if( !$dbo->ping )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbo->ping) 0 1 1
1448 {
1449 0 ▶ my $dbh = $dbo->_dbi_connect || return( $self->pass_error );
Condition0%0/2
$dbo->_dbi_connect || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$dbo->_dbi_connect || (return $self->pass_error)
$dbo->_dbi_connect
Truth table0%0/2
A
A= $dbo->_dbi_connect
Aresult
11
00
1450 0 $dbo->{dbh} = $dbh;
1451 }
1452 1 local $@;
1453 my $sth = eval
1454 1 {
1455 1 ▶ local( $SIG{__DIE__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=0.0
1456 1 ▶ local( $SIG{__WARN__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=0.0
1457 1 $dbo->{dbh}->prepare( $query, $opt_ref );
1458 };
1459 1 ▶ if( $sth )
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) { } 1 0 1
1460 {
1461 # my $data = { 'sth' => $sth, 'query' => $query };
1462 1 my( $query_values, $sel_fields );
1463 1 ▶ if( $q )
Branch: 1 branch
BranchTrueFalseTotal
if ($q) 0 1 1
1464 {
1465 0 $query_values = $q->query_values;
1466 0 $sel_fields = $q->selected_fields;
1467 }
1468 1 ▶ my $data =
Branch: 3 branches
BranchTrueFalseTotal
defined $query_values ? : 0 1 1
defined $sel_fields ? : 0 1 1
$q ? : 0 1 1
1469 {
1470 sth => $sth,
1471 query => $query,
1472 # query_values => $q->query_values,
1473 # selected_fields => $q->selected_fields,
1474 ( defined( $query_values ) ? ( query_values => $query_values ) : () ),
1475 ( defined( $sel_fields ) ? ( selected_fields => $sel_fields ) : () ),
1476 ( $q ? ( query_object => $q ) : () ),
1477 };
1478 1 return( $self->_make_sth( "${base_class}::Statement", $data ) );
1479 }
1480 else
1481 {
1482 0 ▶ my $err = $@ || $self->{dbh}->errstr() || 'Unknown error while cache preparing query.';
Condition0%0/5
$@ || $self->{'dbh'}->errstr || 'Unknown error while cache preparing query.'
l!l
00
$@ or $self->{"dbh"}->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $self->{'dbh'}->errstr || 'Unknown error while cache preparing query.'
$@ $self->{"dbh"}->errstr
Truth table0%0/3
A or B
A= $@B= $self->{"dbh"}->errstr
ABresult
1X1
011
000
1483 0 $self->{query} = $query;
1484 0 return( $self->error( $err ) );
1485 }
1486 }
1487  
1488 sub prepare_cached
1489 0 ▶{
Subroutine prepare_cached: not called CC=12 SCAR=50.5
Pod documented
1490 0 my $self = shift( @_ );
1491 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1492 0 my $query = shift( @_ );
1493 0 ▶ my $opt_ref = shift( @_ ) || undef();
Condition0%0/2
shift @_ || undef()
l!l
00
MC/DC0%0/1
shift @_ || undef()
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1494 0 my $base_class = $self->base_class;
1495 0 my $q;
1496 0 ▶ if( $self->_is_a( $q => "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($q, "${base_class}::Query")) 0 0 0
1497 {
1498 0 $q = $query;
1499 0 $query = $q->as_string;
1500 }
1501 0 $self->_clean_statement( \$query );
1502 # Wether we are called from DB::Object or DB::Object::Tables object
1503 0 ▶ my $dbo = $self->{dbo} || $self->{database_object} || $self;
Condition0%0/6
$self->{'dbo'} || $self->{'database_object'} || $self
l!l&&r!l&&!r
000
$self->{"dbo"} or $self->{"database_object"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{'dbo'} || $self->{'database_object'} || $self
$self->{"dbo"} $self->{"database_object"} $self
Truth table0%0/4
A or B || C
A= $self->{"dbo"}B= $self->{"database_object"}C= $self
ABCresult
1XX1
01X1
0011
0000
1504 0 ▶ if( !$dbo->ping )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbo->ping) 0 0 0
1505 {
1506 0 ▶ my $dbh = $dbo->_dbi_connect || return( $self->pass_error );
Condition0%0/2
$dbo->_dbi_connect || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$dbo->_dbi_connect || (return $self->pass_error)
$dbo->_dbi_connect
Truth table0%0/2
A
A= $dbo->_dbi_connect
Aresult
11
00
1507 0 $dbo->{dbh} = $dbh;
1508 }
1509 my $sth = eval
1510 0 {
1511 0 ▶ local( $SIG{__DIE__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1512 0 ▶ local( $SIG{__WARN__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1513 0 $dbo->{dbh}->prepare_cached( $query, $opt_ref );
1514 };
1515 0 ▶ if( $sth )
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) { } 0 0 0
1516 {
1517 # my $data = { %$self, 'sth' => $sth, 'query' => $query };
1518 # my $data = { 'sth' => $sth, 'query' => $query };
1519 my $data =
1520 {
1521 sth => $sth,
1522 query => $query,
1523 query_values => $self->{query_values},
1524 selected_fields => $self->{selected_fields},
1525 0 ▶ ( $q ? ( query_object => $q ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$q ? : 0 0 0
1526 };
1527 # CORE::delete( $data->{ 'executed' } );
1528 # This is an inner package
1529 # bless( $data, "DB::Object::Statement" );
1530 # return( $data );
1531 0 return( $self->_make_sth( "${base_class}::Statement", $data ) );
1532 }
1533 else
1534 {
1535 0 ▶ my $err = $@ || $self->{dbh}->errstr() || 'Unknown error while cache preparing query.';
Condition0%0/5
$@ || $self->{'dbh'}->errstr || 'Unknown error while cache preparing query.'
l!l
00
$@ or $self->{"dbh"}->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $self->{'dbh'}->errstr || 'Unknown error while cache preparing query.'
$@ $self->{"dbh"}->errstr
Truth table0%0/3
A or B
A= $@B= $self->{"dbh"}->errstr
ABresult
1X1
011
000
1536 0 $self->{query} = $query;
1537 0 return( $self->error( $err ) );
1538 }
1539 }
1540  
1541 sub query($$)
1542 0 ▶{
Subroutine query: not called CC=3 SCAR=24.8
Pod documented
1543 0 my $self = shift( @_ );
1544 0 my $sth = $self->prepare( @_ );
1545 0 my $result;
1546 0 ▶ if( $sth && !( $result = $sth->execute() ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($sth and not $result = $sth->execute) { } 0 0 0
Condition0%0/3
$sth and not $result = $sth->execute
!ll&&!rl&&r
000
MC/DC0%0/2
$sth and not $result = $sth->execute
$sth not $result = $sth->execute
Truth table0%0/3
A and not(B)
A= $sthB= not $result = $sth->execute
ABresult
0X0
100
111
1547 {
1548 0 return;
1549 }
1550 else
1551 {
1552 # bless( $sth, ref( $self ) );
1553 0 return( $sth );
1554 }
1555 }
1556  
1557 0 ▶sub query_object { return( shift->_set_get_object_without_init( 'query_object', 'DB::Object::Query', @_ ) ); }
Subroutine query_object: not called CC=1 SCAR=6.9
Pod documented
1558  
1559 sub quote
1560 16 ▶{
Subroutine quote: called CC=5 SCAR=19.3
Pod documented
1561 16 my $self = shift( @_ );
1562 # my $dbh = $self->{dbh} || return( $self->error( "No database handler was set." ) );
1563 16 my $dbh;
1564 16 ▶ unless( $dbh = $self->{dbh} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $self->{"dbh"}) 16 0 16
1565 {
1566 # This is a fallback in case we need to use quote, but do not have a database connection yet.
1567 16 my $str = shift( @_ );
1568 # print( STDERR ref( $self ), "::quote -> \$str is '$str' (without surrounding quote\n" );
1569 16 ▶ return( $self->NULL ) if( !defined( $str ) || uc( $str ) eq 'NULL' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $str or uc $str eq "NULL" 0 16 16
Condition33%1/3
not defined $str or uc $str eq "NULL"
l!l&&r!l&&!r
0016
MC/DC0%0/2
not defined $str or uc $str eq "NULL"
not defined $str uc $str eq "NULL"
Truth table33%1/3
not(A) or B
A= not defined $strB= uc $str eq "NULL"
ABresult
1X1
011
000
1570 16 ▶ if( $str =~ /^$RE{num}{real}$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^$DB::Object::RE{'num'}{'real'}$/) { } 16 0 16
1571 {
1572 16 return( $str );
1573 }
1574 else
1575 {
1576 0 $str =~ s/'/''/g; # iso SQL 2
1577 0 return( "'$str'" );
1578 }
1579 }
1580 0 return( $dbh->quote( @_ ) );
1581 }
1582  
1583 0 ▶sub serialiser { return( shift->_set_get_scalar( 'serialiser', @_ ) ); }
Subroutine serialiser: not called CC=1 SCAR=6.9
Pod documented
1584  
1585 0 ▶sub serializer { return( shift->serialiser( @_ ) ); }
Subroutine serializer: not called CC=1 SCAR=6.9
Pod documented
1586  
1587 sub set
1588 0 ▶{
Subroutine set: not called CC=5 SCAR=34.0
Pod documented
1589 0 my $self = shift( @_ );
1590 0 my $vars = '';
1591 0 $vars = shift( @_ );
1592 0 ▶ $vars ||= $self->local();
Condition0%0/3
$vars ||= $self->local
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars ||= $self->local
$vars $self->local
Truth table0%0/3
A ||= B
A= $varsB= $self->local
ABresult
1X1
011
000
1593 # Are there any variable declaration?
1594 0 ▶ if( $vars )
Branch: 1 branch
BranchTrueFalseTotal
if ($vars) 0 0 0
1595 {
1596 0 my $query = "SET $vars";
1597 eval
1598 0 {
1599 0 ▶ local( $SIG{__DIE__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1600 0 ▶ local( $SIG{__WARN__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1601 0 ▶ local( $SIG{ALRM} ) = sub{ die( "Timeout while processing query to set variables:\n$query\n" ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1602 0 $self->do( $query );
1603 };
1604 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1605 {
1606 0 my $err = '*** ' . join( "\n*** ", split( /\n/, $@ ) );
1607 0 ▶ if( $self->fatal() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 0 0
1608 {
1609 0 die( "Error occured while setting SQL variables before executing query:\n$self->{sth}->{Statement}\n$err\n" );
1610 }
1611 else
1612 {
1613 0 return( $self->error( $@ ) );
1614 }
1615 }
1616 }
1617 0 return(1);
1618 }
1619  
1620 # To also consider:
1621 # $sth = $dbh->statistics_info( undef, $schema, $table, $unique_only, $quick );
1622 sub stat
1623 0 ▶{
Subroutine stat: not called CC=7 SCAR=40.3
Pod documented
1624 0 my $self = shift( @_ );
1625 0 my $type = lc( shift( @_ ) );
1626 0 my $sth = $self->prepare( "SHOW STATUS" );
1627 0 $sth->execute();
1628 0 my @data = ();
1629 0 my $ref = {};
1630 0 ▶ while( @data = $sth->fetchrow() )
Branch: 1 branch
BranchTrueFalseTotal
if (@data = $sth->fetchrow) 0 0 0
1631 {
1632 0 $ref->{ lc( $data[ 0 ] ) } = $data[ 1 ];
1633 }
1634 0 $sth->finish();
1635 0 ▶ if( $type )
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
1636 {
1637 0 ▶ return( exists( $ref->{ $type } ) ? $ref->{ $type } : undef() );
Branch: 1 branch
BranchTrueFalseTotal
exists $ref->{$type} ? : 0 0 0
1638 }
1639 else
1640 {
1641 0 ▶ return( wantarray() ? () : undef() ) if( !%$ref );
Branch: 2 branches
BranchTrueFalseTotal
unless %$ref 0 0 0
wantarray ? : 0 0 0
1642 0 ▶ return( wantarray() ? %$ref : $ref );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1643 }
1644 }
1645  
1646 sub state(@)
1647 0 ▶{
Subroutine state: not called CC=4 SCAR=30.0
Pod documented
1648 0 my $self = shift( @_ );
1649 # $str = $h->state;
1650 0 ▶ if( !ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self) { } 0 0 0
1651 {
1652 0 return( $DBI::state );
1653 }
1654 else
1655 {
1656 0 ▶ my $dbh = $self->{dbh} || return( $self->error( "No database handle is available. You need to connect to a database before using state() or call it as a class function." ) );
Condition0%0/2
$self->{'dbh'} || (return $self->error('No database handle is available. You need to connect to a database before using state() or call it as a class function.'))
l!l
00
MC/DC0%0/1
$self->{'dbh'} || (return $self->error('No database handle is available. You need to connect to a database before using state() or call it as a class function.'))
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
Aresult
11
00
1657 0 local $@;
1658 my $rv = eval
1659 0 {
1660 0 $dbh->state();
1661 };
1662 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1663 {
1664 0 return( $self->error( $@ ) );
1665 }
1666 0 return( $rv );
1667 }
1668 }
1669  
1670 sub supported_class
1671 7 ▶{
Subroutine supported_class: called CC=1 SCAR=0.0
Pod documented
1672 7 my $self = shift( @_ );
1673 7 my @classes = values( %$DRIVER2PACK );
1674 7 return( @classes );
1675 }
1676  
1677 sub supported_drivers
1678 0 ▶{
Subroutine supported_drivers: not called CC=1 SCAR=6.9
Pod documented
1679 0 my $self = shift( @_ );
1680 0 my @drivers = keys( %$DRIVER2PACK );
1681 0 return( @drivers );
1682 }
1683  
1684 sub table
1685 0 ▶{
Subroutine table: not called CC=14 SCAR=53.5
Pod documented
1686 0 my $self = shift( @_ );
1687 0 my $base_class = $self->base_class;
1688 0 ▶ return( $self->error( "You must use the database object to access this method." ) ) if( ref( $self ) ne $base_class );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self ne $base_class 0 0 0
1689 0 ▶ my $table = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('You must provide a table name to access the table methods.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('You must provide a table name to access the table methods.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1690 return( $self->error( "You must provide a table name to access the table methods." ) );
1691 0 my $table_class = "${base_class}::Tables";
1692 0 ▶ $self->_load_class( $table_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($table_class) or return $self->pass_error 0 0 0
1693 0 ▶ my $host = $self->{server} // '';
Condition0%0/2
$self->{"server"} // ""
l!l
00
MC/DC0%0/1
$self->{"server"} // ""
$self->{"server"}
Truth table0%0/2
A
A= $self->{"server"}
Aresult
11
00
1694 0 ▶ my $db = $self->{database} // '';
Condition0%0/2
$self->{"database"} // ""
l!l
00
MC/DC0%0/1
$self->{"database"} // ""
$self->{"database"}
Truth table0%0/2
A
A= $self->{"database"}
Aresult
11
00
1695 0 my $tbl;
1696 0 ▶ if( my $medium = $self->cache_table )
Branch: 1 branch
BranchTrueFalseTotal
if (my $medium = $self->cache_table) { } 0 0 0
1697 {
1698 0 ▶ $tbl = $self->_cache_table(
Branch: 1 branch
BranchTrueFalseTotal
$medium eq 'file' ? : 0 0 0
1699 host => $self->host,
1700 database => $self->database,
1701 table => $table,
1702 ( $medium eq 'file' ? ( medium => $medium ) : () )
1703 );
1704 0 ▶ return( $self->pass_error ) if( !defined( $tbl ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tbl 0 0 0
1705 0 ▶ $tbl->reset if( $tbl );
Branch: 1 branch
BranchTrueFalseTotal
if $tbl 0 0 0
1706 }
1707 else
1708 {
1709 # cache_table is not enabled.
1710 }
1711  
1712 0 ▶ if( !$tbl )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tbl) 0 0 0
1713 {
1714 0 ▶ $tbl = $table_class->new( $table,
Condition0%0/2
$table_class->new($table, 'dbo', $self, 'debug', $self->debug) || (return $self->pass_error($table_class->error))
l!l
00
MC/DC0%0/1
$table_class->new($table, 'dbo', $self, 'debug', $self->debug) || (return $self->pass_error($table_class->error))
$table_class->new($table, 'dbo', $self, 'debug', $self->debug)
Truth table0%0/2
A
A= $table_class->new($table, 'dbo', $self, 'debug', $self->debug)
Aresult
11
00
1715 # Not necessary
1716 # dbh => $self->{dbh},
1717 dbo => $self,
1718 debug => $self->debug,
1719 ) || return( $self->pass_error( $table_class->error ) );
1720 0 $tbl->reset;
1721 0 ▶ if( $self->cache_table )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_table) 0 0 0
1722 {
1723 0 ▶ $self->_cache_table(
Branch: 1 branch
BranchTrueFalseTotal
$self->_cache_table("host", $self->host, "database", $self->database, "table", $tbl) or return $self->pass_error 0 0 0
1724 host => $self->host,
1725 database => $self->database,
1726 table => $tbl,
1727 ) || return( $self->pass_error );
1728 }
1729 }
1730 0 $tbl->no_bind( $self->no_bind );
1731 # We set debug and again here in case it changed since the table object was instantiated
1732 0 $tbl->debug( $self->debug );
1733 0 return( $tbl );
1734 }
1735  
1736 sub table_exists
1737 0 ▶{
Subroutine table_exists: not called CC=7 SCAR=40.3
Pod documented
1738 0 my $self = shift( @_ );
1739 0 ▶ my $table = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('You must provide a table name to access the table methods.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('You must provide a table name to access the table methods.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1740 return( $self->error( "You must provide a table name to access the table methods." ) );
1741 0 my $cache_tables = $self->cache_tables;
1742 0 my $tables_in_cache = [];
1743 0 ▶ if( defined( $cache_tables ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache_tables) 0 0 0
1744 {
1745 0 $tables_in_cache = $cache_tables->get({
1746 host => $self->host,
1747 driver => $self->driver,
1748 port => $self->port,
1749 database => $self->database,
1750 });
1751 }
1752 0 foreach my $ref ( @$tables_in_cache )
1753 {
1754 0 ▶ return( 1 ) if( $ref->{name} eq $table );
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"name"} eq $table 0 0 0
1755 }
1756 # We did not find it, so let's try by checking directly the database
1757 0 my $def = $self->table_info( $table );
1758 0 ▶ return( $self->pass_error ) if( !defined( $def ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def 0 0 0
1759 0 ▶ return(0) if( $self->_is_empty( $def ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($def) 0 0 0
1760 0 return(1);
1761 }
1762  
1763 sub table_info
1764 0 ▶{
Subroutine table_info: not called CC=1 SCAR=6.9
Pod documented
1765 0 my $self = shift( @_ );
1766 0 return( $self->error( "table_info() has not been implemented by driver \"$self->{driver}\" (object = $self)." ) );
1767 }
1768  
1769 sub table_push
1770 0 ▶{
Subroutine table_push: not called CC=4 SCAR=30.0
Pod documented
1771 0 my $self = shift( @_ );
1772 0 ▶ my $table = shift( @_ ) || return( $self->error( "No table provided to add to our cache." ) );
Condition0%0/2
shift @_ || (return $self->error('No table provided to add to our cache.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No table provided to add to our cache.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1773 0 ▶ my $def = $self->tables_info || return;
Condition0%0/2
$self->tables_info || (return)
l!l
00
MC/DC0%0/1
$self->tables_info || (return)
$self->tables_info
Truth table0%0/2
A
A= $self->tables_info
Aresult
11
00
1774 0 my $hash =
1775 {
1776 host => $self->host,
1777 driver => $self->driver,
1778 port => $self->port,
1779 database => $self->database,
1780 tables => $def,
1781 };
1782 0 my $cache_tables = $self->cache_tables;
1783 0 ▶ if( !defined( $cache_tables->set( $hash ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cache_tables->set($hash)) 0 0 0
1784 {
1785 0 return( $self->pass_error( $cache_tables->error ) );
1786 }
1787 0 return( $table );
1788 }
1789  
1790 sub tables
1791 0 ▶{
Subroutine tables: not called CC=12 SCAR=50.5
Pod documented
1792 0 my $self = shift( @_ );
1793 0 ▶ my $db = shift( @_ ) || $self->database;
Condition0%0/3
shift @_ || $self->database
l!l&&r!l&&!r
000
MC/DC0%0/2
shift @_ || $self->database
shift @_ $self->database
Truth table0%0/3
A || B
A= shift @_B= $self->database
ABresult
1X1
011
000
1794 0 my $opts = $self->_get_args_as_hash( @_ );
1795 0 ▶ $db = $opts->{database} if( $opts->{database} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"database"} 0 0 0
1796 0 my $all = [];
1797 0 ▶ if( !$opts->{no_cache} && !$opts->{live} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"no_cache"} or $opts->{"live"}) 0 0 0
Condition0%0/3
$opts->{"no_cache"} or $opts->{"live"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"no_cache"} or $opts->{"live"}
$opts->{"no_cache"} $opts->{"live"}
Truth table0%0/3
A or B
A= $opts->{"no_cache"}B= $opts->{"live"}
ABresult
1X1
011
000
1798 {
1799 0 ▶ if( my $cache_tables = $self->cache_tables )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache_tables = $self->cache_tables) { } 0 0 0
1800 {
1801 $all = $cache_tables->get({
1802 host => $self->host,
1803 driver => $self->driver,
1804 port => $self->port,
1805 database => $db,
1806 }) || do
1807 0 ▶ {
Condition0%0/3
$cache_tables->get({'host', $self->host, 'driver', $self->driver, 'port', $self->port, 'database', $db}) || do { $self->error(q[Warning only: an error occured while trying to fetch the tables cache for host '], $self->host, q[', driver '], $self->driver, q[', port '], $self->port, q[' and database '], $self->database, q[': ], $cache_tables->error, "\n") }
l!l&&r!l&&!r
000
MC/DC0%0/2
$cache_tables->get({'host', $self->host, 'driver', $self->driver, 'port', $self->port, 'database', $db}) || do { $self->error(q[Warning only: an error occured while trying to fetch the tables cache for host '], $self->host, q[', driver '], $self->driver, q[', port '], $self->port, q[' and database '], $self->database, q[': ], $cache_tables->error, "\n") }
$cache_tables->get({'host', $self->host, 'driver', $self->driver, 'port', $self->port, 'database', $db}) do { $self->error(q[Warning only: an error occured while trying to fetch the tables cache for host '], $self->host, q[', driver '], $self->driver, q[', port '], $self->port, q[' and database '], $self->database, q[': ], $cache_tables->error, "\n") }
Truth table0%0/3
A || B
A= $cache_tables->get({'host', $self->host, 'driver', $self->driver, 'port', $self->port, 'database', $db})B= do { $self->error(q[Warning only: an error occured while trying to fetch the tables cache for host '], $self->host, q[', driver '], $self->driver, q[', port '], $self->port, q[' and database '], $self->database, q[': ], $cache_tables->error, "\n") }
ABresult
1X1
011
000
1808 0 $self->error( "Warning only: an error occured while trying to fetch the tables cache for host '", $self->host, "', driver '", $self->driver, "', port '", $self->port, "' and database '", $self->database, "': ", $cache_tables->error, "\n" );
1809 };
1810 }
1811 else
1812 {
1813 0 $self->error( "Warning only: no cache tables object found in our self ($self)! Current keys are: '", join( "', '", sort( keys( %$self ) ) ), "'." );
1814 }
1815 }
1816 0 ▶ if( $opts->{no_cache} || $opts->{live} || !scalar( @$all ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"no_cache"} or $opts->{"live"} or not scalar @$all) 0 0 0
Condition0%0/6
$opts->{"no_cache"} or $opts->{"live"} or not scalar @$all
l!l&&r!l&&!r
000
$opts->{"no_cache"} or $opts->{"live"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"no_cache"} or $opts->{"live"} or not scalar @$all
$opts->{"no_cache"} $opts->{"live"} not scalar @$all
Truth table0%0/4
A or B or not(C)
A= $opts->{"no_cache"}B= $opts->{"live"}C= not scalar @$all
ABCresult
1XX1
01X1
0011
0000
1817 {
1818 0 ▶ $all = $self->tables_info || return;
Condition0%0/2
$self->tables_info || (return)
l!l
00
MC/DC0%0/1
$self->tables_info || (return)
$self->tables_info
Truth table0%0/2
A
A= $self->tables_info
Aresult
11
00
1819 }
1820 0 my @tables = ();
1821 0 ▶ @tables = map( $_->{name}, @$all ) if( scalar( @$all ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$all 0 0 0
1822 0 return( \@tables );
1823 }
1824  
1825 sub tables_cache
1826 0 ▶{
Subroutine tables_cache: not called CC=1 SCAR=6.9
Pod documented
1827 0 my $self = shift( @_ );
1828 0 my $opts = $self->_get_args_as_hash( @_ );
1829 0 my $cache_tables = $self->cache_tables;
1830 0 my $cache = $cache_tables->get({
1831 host => $self->host,
1832 driver => $self->driver,
1833 port => $self->port,
1834 database => $self->database,
1835 });
1836 0 return( $cache );
1837 }
1838  
1839 0 ▶sub tables_info { return( shift->error( "tables_info() has not been implemented by driver." ) ); }
Subroutine tables_info: not called CC=1 SCAR=6.9
Pod documented
1840  
1841 sub tables_refresh
1842 0 ▶{
Subroutine tables_refresh: not called CC=5 SCAR=34.0
Pod documented
1843 0 my $self = shift( @_ );
1844 0 ▶ my $db = shift( @_ ) || $self->database;
Condition0%0/3
shift @_ || $self->database
l!l&&r!l&&!r
000
MC/DC0%0/2
shift @_ || $self->database
shift @_ $self->database
Truth table0%0/3
A || B
A= shift @_B= $self->database
ABresult
1X1
011
000
1845 0 ▶ my $tables = $self->tables_info || return;
Condition0%0/2
$self->tables_info || (return)
l!l
00
MC/DC0%0/1
$self->tables_info || (return)
$self->tables_info
Truth table0%0/2
A
A= $self->tables_info
Aresult
11
00
1846 0 my $hash =
1847 {
1848 host => $self->host,
1849 driver => $self->driver,
1850 port => $self->port,
1851 database => $self->database,
1852 tables => $tables,
1853 };
1854 0 my $cache_tables = $self->cache_tables;
1855 0 ▶ if( !defined( $cache_tables->set( $hash ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cache_tables->set($hash)) 0 0 0
1856 {
1857 0 return( $self->pass_error( $cache_tables->error ) );
1858 }
1859 0 ▶ return( wantarray() ? @$tables : $tables );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1860 }
1861  
1862 # Used to flag this as a transaction when begin_work is triggered
1863 2 ▶sub transaction { return( shift->_set_get_boolean( 'transaction', @_ ) ); }
Subroutine transaction: called CC=1 SCAR=0.0
Pod documented
1864  
1865 sub transaction_state
1866 4 ▶{
Subroutine transaction_state: called CC=9 SCAR=23.5
Pod documented
1867 4 my $self = shift( @_ );
1868 4 my $candidate = shift( @_ );
1869  
1870 4 ▶ if( defined( $candidate ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $candidate and not builtin::blessed($candidate) && $candidate->isa("DB::Object")) 0 4 4
Condition33%2/6
defined $candidate and not builtin::blessed($candidate) && $candidate->isa("DB::Object")
!ll&&!rl&&r
040
builtin::blessed($candidate) && $candidate->isa('DB::Object')
!ll&&!rl&&r
004
MC/DC0%0/3
defined $candidate and not builtin::blessed($candidate) && $candidate->isa("DB::Object")
defined $candidate builtin::blessed($candidate) $candidate->isa('DB::Object')
Truth table25%1/4
A and not(B && C)
A= defined $candidateB= builtin::blessed($candidate)C= $candidate->isa('DB::Object')
ABCresult
0XX0
1110
10X1
1101
1871 !( blessed( $candidate ) && $candidate->isa( 'DB::Object' ) ) )
1872 {
1873 0 return( $self->error( "Candidate provided is not a DB::Object object." ) );
1874 }
1875  
1876 4 my $transactions = $self->active_transactions;
1877 4 ▶ return( $self->pass_error ) if( !defined( $transactions ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transactions 0 4 4
1878  
1879 4 my $count = scalar( @$transactions );
1880 my $state =
1881 {
1882 active => $count ? 1 : 0,
1883 count => $count,
1884 4 ▶ ids => [map( $_->{id}, @$transactions )],
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 2 2 4
1885 };
1886  
1887 4 ▶ if( $count == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 1) 2 2 4
1888 {
1889 2 $state->{id} = $transactions->[0]->{id};
1890 2 ▶ $state->{same} = $candidate->uses_handle( $transactions->[0]->{handle} ) ? 1 : 0 if( defined( $candidate ) );
Branch: 2 branches
BranchTrueFalseTotal
if defined $candidate 2 0 2
$candidate->uses_handle($transactions->[0]{'handle'}) ? : 1 1 2
1891 }
1892 4 return( $state );
1893 }
1894  
1895 0 ▶sub TRUE { return( 'TRUE' ); }
Subroutine TRUE: not called CC=1 SCAR=6.9
Pod documented
1896  
1897 0 ▶sub unknown_field { return( shift->_set_get_scalar( 'unknown_field', @_ ) ); }
Subroutine unknown_field: not called CC=1 SCAR=6.9
Pod documented
1898  
1899 sub unlock
1900 0 ▶{
Subroutine unlock: not called CC=1 SCAR=6.9
Pod documented
1901 0 my $self = shift( @_ );
1902 0 return( $self->error( "Method \"unlock\" has not been implemented by driver $self->{driver} (object $self)." ) );
1903 }
1904  
1905 sub use
1906 0 ▶{
Subroutine use: not called CC=8 SCAR=42.8
Pod documented
1907 0 my $self = shift( @_ );
1908 0 my $base_class = $self->base_class;
1909 0 ▶ return( $self->error( "You must use the the database object to switch database." ) ) if( ref( $self ) ne $base_class );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self ne $base_class 0 0 0
1910 0 my $db = shift( @_ );
1911 # No need to go further
1912 0 ▶ return( $self ) if( $db eq $self->{database} );
Branch: 1 branch
BranchTrueFalseTotal
if $db eq $self->{"database"} 0 0 0
1913 0 ▶ my $repo = Module::Generic::Global->new( 'available_databases' => CORE::ref( $self ), key => CORE::ref( $self ) ) ||
Condition0%0/2
'Module::Generic::Global'->new('available_databases', ref $self, 'key', ref $self) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('available_databases', ref $self, 'key', ref $self) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('available_databases', ref $self, 'key', ref $self)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('available_databases', ref $self, 'key', ref $self)
Aresult
11
00
1914 return( $self->pass_error( Module::Generic::Global->error ) );
1915 0 my $all_dbs = $repo->get;
1916 0 ▶ if( !defined( $all_dbs ) || !$self->_is_array( $all_dbs ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $all_dbs and $self->_is_array($all_dbs)) 0 0 0
Condition0%0/3
defined $all_dbs and $self->_is_array($all_dbs)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $all_dbs and $self->_is_array($all_dbs)
defined $all_dbs $self->_is_array($all_dbs)
Truth table0%0/3
A and B
A= defined $all_dbsB= $self->_is_array($all_dbs)
ABresult
0X0
100
111
1917 {
1918 0 $all_dbs = [];
1919 0 @$all_dbs = $self->databases();
1920 0 $repo->set( $all_dbs );
1921 }
1922 0 ▶ if( !scalar( grep{ /^$db$/ } @$all_dbs ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({/^$db$/;} @$all_dbs)) 0 0 0
1923 {
1924 0 return( $self->error( "The database '$db' does not exist." ) );
1925 }
1926 0 ▶ my $dbh = $base_class->connect( $db ) ||
Condition0%0/2
$base_class->connect($db) || (return $self->error("Unable to connect to database '${db}'."))
l!l
00
MC/DC0%0/1
$base_class->connect($db) || (return $self->error("Unable to connect to database '${db}'."))
$base_class->connect($db)
Truth table0%0/2
A
A= $base_class->connect($db)
Aresult
11
00
1927 return( $self->error( "Unable to connect to database '$db'." ) );
1928 0 $self->param( 'multi_db' => 1 );
1929 0 $dbh->param( 'multi_db' => 1 );
1930 0 return( $dbh );
1931 }
1932  
1933 0 ▶sub use_cache { return( shift->_set_get_boolean( 'cache', @_ ) ) }
Subroutine use_cache: not called CC=1 SCAR=6.9
Pod documented
1934  
1935 0 ▶sub use_bind { return( shift->_set_get_boolean( 'bind', @_ ) ) }
Subroutine use_bind: not called CC=1 SCAR=6.9
Pod documented
1936  
1937 sub uses_handle
1938 2 ▶{
Subroutine uses_handle: called CC=3 SCAR=11.3
Pod documented
1939 2 my $self = shift( @_ );
1940 2 ▶ my $dbh = shift( @_ ) || return;
Condition50%1/2
shift @_ || (return)
l!l
20
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1941  
1942 2 ▶ return if( !$self->{dbh} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dbh"} 0 2 2
1943  
1944 2 require Scalar::Util;
1945 2 return( $self->_refaddr( $self->{dbh} ) == $self->_refaddr( $dbh ) );
1946 }
1947  
1948 sub variables
1949 0 ▶{
Subroutine variables: not called CC=7 SCAR=40.3
Pod documented
1950 0 my $self = shift( @_ );
1951 0 my $type = shift( @_ );
1952 0 ▶ $self->error( "Variable '$type' is a read-only value." ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1953 0 ▶ my $vars = $self->{variables} ||= {};
Condition0%0/2
$self->{"variables"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"variables"} ||= {}
$self->{"variables"}
Truth table0%0/2
A
A= $self->{"variables"}
Aresult
11
00
1954 0 ▶ if( !%$vars )
Branch: 1 branch
BranchTrueFalseTotal
unless (%$vars) 0 0 0
1955 {
1956 0 ▶ my $sth = $self->prepare( "SHOW VARIABLES" ) ||
Condition0%0/2
$self->prepare('SHOW VARIABLES') || (return $self->error('SHOW VARIABLES is not supported.'))
l!l
00
MC/DC0%0/1
$self->prepare('SHOW VARIABLES') || (return $self->error('SHOW VARIABLES is not supported.'))
$self->prepare('SHOW VARIABLES')
Truth table0%0/2
A
A= $self->prepare('SHOW VARIABLES')
Aresult
11
00
1957 return( $self->error( "SHOW VARIABLES is not supported." ) );
1958 0 $sth->execute();
1959 0 my $ref = $self->fetchall_arrayref();
1960 0 my %vars = map{ lc( $_->[ 0 ] ) => $_->[ 1 ] } @$ref;
1961 0 ▶ $vars = \%vars if( %vars );
Branch: 1 branch
BranchTrueFalseTotal
if %vars 0 0 0
1962 0 $sth->finish();
1963 }
1964 0 my @found = grep{ /$type/i } keys( %$vars );
1965 0 ▶ return( '' ) if( !scalar( @found ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @found 0 0 0
1966 0 return( $vars->{ $found[ 0 ] } );
1967 }
1968  
1969 sub version
1970 0 ▶{
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
1971 0 return( shift->error( "This driver has not set the version() method." ) );
1972 }
1973  
1974 # When the table schema caching is enabled, we store the table field objects in an hash reference
1975 # database->table => table_object
1976 sub _cache_table
1977 0 ▶{
Subroutine _cache_table: not called CC=33 SCAR=70.2
1978 0 my $self = shift( @_ );
1979 0 my $opts = $self->_get_args_as_hash( @_ );
1980 0 ▶ my $class = ( ref( $self ) || $self );
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1981 0 my $base_class = $self->base_class;
1982 0 ▶ my $medium = $opts->{medium} // $self->cache_table;
Condition0%0/3
$opts->{"medium"} // $self->cache_table
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"medium"} // $self->cache_table
$opts->{"medium"} $self->cache_table
Truth table0%0/3
A // B
A= $opts->{"medium"}B= $self->cache_table
ABresult
1X1
011
000
1983 0 ▶ if( defined( $medium ) && "$medium" !~ /^0|1|file$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $medium and not "$medium" =~ /^0|1|file$/) 0 0 0
Condition0%0/3
defined $medium and not "$medium" =~ /^0|1|file$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $medium and not "$medium" =~ /^0|1|file$/
defined $medium not "$medium" =~ /^0|1|file$/
Truth table0%0/3
A and not(B)
A= defined $mediumB= not "$medium" =~ /^0|1|file$/
ABresult
0X0
100
111
1984 {
1985 0 return( $self->error( "medium argument or 'cache_table' method value has unsupported value. It can only be 0, 1 or 'file'." ) );
1986 }
1987 # Short-circuit if the preferred cache medium is file
1988 0 ▶ if( $medium eq 'file' )
Branch: 1 branch
BranchTrueFalseTotal
if ($medium eq "file") 0 0 0
1989 {
1990 0 return( $self->_cache_table_on_file( %$opts ) );
1991 }
1992 my $repo = Module::Generic::Global->new( table_cache => 'system',
1993 on_get => sub
1994 0 ▶ {
Subroutine __ANON__: not called CC=9 SCAR=45.0
1995 0 my $cache = shift( @_ );
1996 # my $repo = $_;
1997 # Structure of the cache is host->database->table_name
1998 0 ▶ if( ref( $cache ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cache eq "HASH") 0 0 0
1999 {
2000 0 foreach my $host ( keys( %$cache ) )
2001 {
2002 0 ▶ next unless( ref( $cache->{ $host } ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cache->{$host} eq "HASH" 0 0 0
2003 0 foreach my $db ( keys( %{$cache->{ $host }} ) )
2004 {
2005 0 ▶ next unless( ref( $cache->{ $host }->{ $db } ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cache->{$host}{$db} eq "HASH" 0 0 0
2006 0 foreach my $tbl_name ( keys( %{$cache->{ $host }->{ $db }} ) )
2007 {
2008 0 my $table = $cache->{ $host }->{ $db }->{ $tbl_name };
2009 0 ▶ next unless( $self->_is_a( $table => "${base_class}::Tables" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($table, "${base_class}::Tables") 0 0 0
2010 0 $table->database_object( $self );
2011 0 ▶ if( my $qo = $table->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $qo = $table->query_object) 0 0 0
2012 {
2013 0 $qo->database_object( $self );
2014 }
2015 }
2016 }
2017 }
2018 }
2019 0 return( $cache );
2020 }
2021 0 ▶ ) || return( $self->pass_error( Module::Generic::Global->error ) );
Condition0%0/2
'Module::Generic::Global'->new('table_cache', 'system', 'on_get', sub { my $cache = shift @_; if (ref $cache eq 'HASH') { foreach my $host (keys %$cache) { next unless ref $cache->{$host} eq 'HASH'; foreach my $db (keys %{$$cache{$host};}) { next unless ref $cache->{$host}{$db} eq 'HASH'; foreach my $tbl_name (keys %{$$cache{$host}{$db};}) { my $table = $cache->{$host}{$db}{$tbl_name}; next unless $self->_is_a($table, "${base_class}::Tables"); $table->database_object($self); if (my $qo = $table->query_object) { $qo->database_object($self); } ; } ; } ; } ; } ; return $cache; } ) || (return $self->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('table_cache', 'system', 'on_get', sub { my $cache = shift @_; if (ref $cache eq 'HASH') { foreach my $host (keys %$cache) { next unless ref $cache->{$host} eq 'HASH'; foreach my $db (keys %{$$cache{$host};}) { next unless ref $cache->{$host}{$db} eq 'HASH'; foreach my $tbl_name (keys %{$$cache{$host}{$db};}) { my $table = $cache->{$host}{$db}{$tbl_name}; next unless $self->_is_a($table, "${base_class}::Tables"); $table->database_object($self); if (my $qo = $table->query_object) { $qo->database_object($self); } ; } ; } ; } ; } ; return $cache; } ) || (return $self->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('table_cache', 'system', 'on_get', sub { my $cache = shift @_; if (ref $cache eq 'HASH') { foreach my $host (keys %$cache) { next unless ref $cache->{$host} eq 'HASH'; foreach my $db (keys %{$$cache{$host};}) { next unless ref $cache->{$host}{$db} eq 'HASH'; foreach my $tbl_name (keys %{$$cache{$host}{$db};}) { my $table = $cache->{$host}{$db}{$tbl_name}; next unless $self->_is_a($table, "${base_class}::Tables"); $table->database_object($self); if (my $qo = $table->query_object) { $qo->database_object($self); } ; } ; } ; } ; } ; return $cache; } )
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('table_cache', 'system', 'on_get', sub { my $cache = shift @_; if (ref $cache eq 'HASH') { foreach my $host (keys %$cache) { next unless ref $cache->{$host} eq 'HASH'; foreach my $db (keys %{$$cache{$host};}) { next unless ref $cache->{$host}{$db} eq 'HASH'; foreach my $tbl_name (keys %{$$cache{$host}{$db};}) { my $table = $cache->{$host}{$db}{$tbl_name}; next unless $self->_is_a($table, "${base_class}::Tables"); $table->database_object($self); if (my $qo = $table->query_object) { $qo->database_object($self); } ; } ; } ; } ; } ; return $cache; } )
Aresult
11
00
2022 0 $repo->lock;
2023 0 ▶ my $cache = $repo->get // {};
Condition0%0/2
$repo->get // {}
l!l
00
MC/DC0%0/1
$repo->get // {}
$repo->get
Truth table0%0/2
A
A= $repo->get
Aresult
11
00
2024 0 ▶ unless( CORE::exists( $opts->{host} ) && CORE::exists( $opts->{database} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"host"} and exists $opts->{"database"}) 0 0 0
Condition0%0/3
exists $opts->{"host"} and exists $opts->{"database"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"host"} and exists $opts->{"database"}
exists $opts->{"host"} exists $opts->{"database"}
Truth table0%0/3
A and B
A= exists $opts->{"host"}B= exists $opts->{"database"}
ABresult
0X0
100
111
2025 {
2026 0 return( $cache );
2027 }
2028 0 my( $host, $database, $table ) = @$opts{qw( host database table )};
2029 0 ▶ return( $self->error( "A host name was provided, but is undefined or empty." ) ) if( !defined( $host ) || !CORE::length( $host // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host and length($host // "") 0 0 0
Condition0%0/5
defined $host and length($host // "")
!ll&&!rl&&r
000
$host // ""
l!l
00
MC/DC0%0/2
defined $host and length($host // "")
defined $host $host
Truth table0%0/3
A and B
A= defined $hostB= $host
ABresult
0X0
100
111
2030 0 ▶ return( $self->error( "A database name was provided, but is undefined or empty." ) ) if( !defined( $database ) || !CORE::length( $database // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $database and length($database // "") 0 0 0
Condition0%0/5
defined $database and length($database // "")
!ll&&!rl&&r
000
$database // ""
l!l
00
MC/DC0%0/2
defined $database and length($database // "")
defined $database $database
Truth table0%0/3
A and B
A= defined $databaseB= $database
ABresult
0X0
100
111
2031 0 my $updated = 0;
2032 0 ▶ if( !defined( $cache->{ $host } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cache->{$host}) 0 0 0
2033 {
2034 0 ▶ if( !CORE::exists( $cache->{ $host } ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $cache->{$host} or ref $cache->{$host} ne "HASH") 0 0 0
Condition0%0/3
not exists $cache->{$host} or ref $cache->{$host} ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $cache->{$host} or ref $cache->{$host} ne "HASH"
not exists $cache->{$host} ref $cache->{$host} ne "HASH"
Truth table0%0/3
not(A) or B
A= not exists $cache->{$host}B= ref $cache->{$host} ne "HASH"
ABresult
1X1
011
000
2035 ref( $cache->{ $host } ) ne 'HASH' )
2036 {
2037 0 $cache->{ $host } = {};
2038 0 $updated++;
2039 }
2040 }
2041 0 ▶ if( !defined( $cache->{ $host }->{ $database } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cache->{$host}{$database}) 0 0 0
2042 {
2043 0 ▶ if( !CORE::exists( $cache->{ $host }->{ $database } ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $cache->{$host}{$database} or ref $cache->{$host}{$database} ne "HASH") 0 0 0
Condition0%0/3
not exists $cache->{$host}{$database} or ref $cache->{$host}{$database} ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $cache->{$host}{$database} or ref $cache->{$host}{$database} ne "HASH"
not exists $cache->{$host}{$database} ref $cache->{$host}{$database} ne "HASH"
Truth table0%0/3
not(A) or B
A= not exists $cache->{$host}{$database}B= ref $cache->{$host}{$database} ne "HASH"
ABresult
1X1
011
000
2044 ref( $cache->{ $host }->{ $database } ) ne 'HASH' )
2045 {
2046 0 $cache->{ $host }->{ $database } = {};
2047 0 $updated++;
2048 }
2049 }
2050 # The caller has not provided any table value, hinting it wants the entire hash repository for this database.
2051 0 ▶ if( !defined( $table ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table) 0 0 0
2052 {
2053 0 ▶ $repo->set( $cache ) if( $updated );
Branch: 1 branch
BranchTrueFalseTotal
if $updated 0 0 0
2054 0 return( $cache->{ $host }->{ $database } );
2055 }
2056 # We are given a table object, we store it in the repository. This is mutator mode
2057 0 ▶ if( $self->_is_a( $table => "${base_class}::Tables" ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($table, "${base_class}::Tables")) { } 0 0 0
elsif (not ref $table or ref $table and $self->_can_overload($table, '""')) { } 0 0 0
2058 {
2059 0 ▶ my $name = $table->name ||
Condition0%0/2
$table->name || (return $self->error('No table name associated with this table object.'))
l!l
00
MC/DC0%0/1
$table->name || (return $self->error('No table name associated with this table object.'))
$table->name
Truth table0%0/2
A
A= $table->name
Aresult
11
00
2060 return( $self->error( "No table name associated with this table object." ) );
2061 0 my $dbo = $table->database_object;
2062 0 $table->database_object( undef );
2063 0 my $clone = $table->clone;
2064 0 $table->database_object( $dbo );
2065 0 $cache->{ $host }->{ $database }->{ "$name" } = $clone;
2066 0 $repo->set( $cache );
2067 }
2068 # The user has provided a table name, and thus expects the related cloned table object from the cache table repository.
2069 # This is accessor mode.
2070 ▶ elsif( !ref( $table ) || ( ref( $table ) && $self->_can_overload( $table => '""' ) ) )
Condition0%0/6
not ref $table or ref $table and $self->_can_overload($table, "\"\"")
l!l&&r!l&&!r
000
ref $table and $self->_can_overload($table, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $table or ref $table and $self->_can_overload($table, "\"\"")
not ref $table ref $table $self->_can_overload($table, "\"\"")
Truth table0%0/4
not(A) or B and C
A= not ref $tableB= ref $tableC= $self->_can_overload($table, "\"\"")
ABCresult
1XX1
0111
00X0
0100
2071 {
2072 0 ▶ if( !CORE::exists( $cache->{ $host }->{ $database }->{ "$table" } ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $cache->{$host}{$database}{"$table"} and defined $cache->{$host}{$database}{"$table"}) 0 0 0
Condition0%0/3
exists $cache->{$host}{$database}{"$table"} and defined $cache->{$host}{$database}{"$table"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $cache->{$host}{$database}{"$table"} and defined $cache->{$host}{$database}{"$table"}
exists $cache->{$host}{$database}{"$table"} defined $cache->{$host}{$database}{"$table"}
Truth table0%0/3
A and B
A= exists $cache->{$host}{$database}{"$table"}B= defined $cache->{$host}{$database}{"$table"}
ABresult
0X0
100
111
2073 !defined( $cache->{ $host }->{ $database }->{ "$table" } ) )
2074 {
2075 0 return( '' );
2076 }
2077 0 my $tbl = $cache->{ $host }->{ $database }->{ "$table" };
2078 0 ▶ unless( $self->_is_a( $tbl => "${base_class}::Tables" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($tbl, "${base_class}::Tables")) 0 0 0
2079 {
2080 0 die( "Table object found (", $self->_str_val( $tbl ), ") in this statement object is actually not a table object (${base_class}::Tables) !" );
2081 }
2082 0 my $table_class = ref( $tbl );
2083 0 ▶ $self->_load_class( $table_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($table_class) or return $self->pass_error 0 0 0
2084 0 my $clone = $tbl->clone;
2085 # $clone->database_object( $self );
2086 0 $clone->attach( $self );
2087 0 return( $clone );
2088 }
2089 else
2090 {
2091 0 return( $self->error( "I do not understand the value provided for the 'table' option -> ", $self->_str_val( $table ) ) );
2092 }
2093 }
2094  
2095 # Set or get the table object serialised on file.
2096 sub _cache_table_on_file
2097 0 ▶{
Subroutine _cache_table_on_file: not called CC=37 SCAR=72.5
2098 0 my $self = shift( @_ );
2099 0 my $base_class = $self->base_class;
2100 0 my $dbo;
2101 0 ▶ if( $self->isa( $base_class ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa($base_class)) { } 0 0 0
elsif ($self->can('database_object')) { } 0 0 0
2102 {
2103 0 $dbo = $self;
2104 }
2105 elsif( $self->can( 'database_object' ) )
2106 {
2107 0 ▶ $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('There is no database object associated.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('There is no database object associated.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
2108 return( $self->error( "There is no database object associated." ) );
2109 }
2110 else
2111 {
2112 0 return( $self->error( "This object is neither a $base_class object, nor an object that supports the 'database_object' method." ) );
2113 }
2114 # new_file() is inherited from Module::Generic
2115 0 my $cache_dir = $self->cache_dir;
2116 0 ▶ if( $self->_is_empty( $cache_dir ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_empty($cache_dir)) 0 0 0
2117 {
2118 0 return( $self->error( "No cache directory is set." ) );
2119 }
2120 0 $cache_dir = $self->new_file( $cache_dir );
2121 # Ensure cache directory exists
2122 0 ▶ if( !$cache_dir->exists )
Branch: 2 branches
BranchTrueFalseTotal
if (not $cache_dir->exists) { } 0 0 0
elsif (not $cache_dir->is_dir) { } 0 0 0
2123 {
2124 0 ▶ $cache_dir->mkpath || return( $self->pass_error( $cache_dir->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->mkpath or return $self->pass_error($cache_dir->error) 0 0 0
2125 }
2126 elsif( !$cache_dir->is_dir )
2127 {
2128 0 return( $self->error( "Cache directory path '$cache_dir' exists but is not a directory." ) );
2129 }
2130  
2131 0 my $opts = $self->_get_args_as_hash( @_ );
2132 0 ▶ my $serialiser = $self->serialiser || $DB::Object::SERIALISER || 'Storable';
Condition0%0/5
$self->serialiser || $DB::Object::SERIALISER || 'Storable'
l!l
00
$self->serialiser or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->serialiser || $DB::Object::SERIALISER || 'Storable'
$self->serialiser $DB::Object::SERIALISER
Truth table0%0/3
A or B
A= $self->serialiserB= $DB::Object::SERIALISER
ABresult
1X1
011
000
2133 0 my( $host, $database, $table ) = @$opts{qw( host database table )};
2134 0 ▶ if( !defined( $host ) || !CORE::length( $host // '' ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $host && length($host // '')) { } 0 0 0
elsif (not defined $database && length($database // '')) { } 0 0 0
elsif (not $database =~ /^\w+$/) { } 0 0 0
Condition0%0/5
defined $host && length($host // '')
!ll&&!rl&&r
000
$host // ""
l!l
00
MC/DC0%0/2
defined $host && length($host // '')
defined $host $host
Truth table0%0/3
A && B
A= defined $hostB= $host
ABresult
0X0
100
111
2135 {
2136 0 return( $self->error( "A host name was provided, but is undefined or empty." ) );
2137 }
2138 ▶ elsif( !defined( $database ) || !CORE::length( $database // '' ) )
Condition0%0/5
defined $database && length($database // '')
!ll&&!rl&&r
000
$database // ""
l!l
00
MC/DC0%0/2
defined $database && length($database // '')
defined $database $database
Truth table0%0/3
A && B
A= defined $databaseB= $database
ABresult
0X0
100
111
2139 {
2140 0 return( $self->error( "A database name was provided, but is undefined or empty." ) );
2141 }
2142 elsif( $database !~ /^\w+$/ )
2143 {
2144 0 return( $self->error( "The database name '$database' contains illegal characters." ) );
2145 }
2146  
2147 0 ▶ if( !$self->ping )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ping) 0 0 0
2148 {
2149 0 ▶ my $dbh = $self->_dbi_connect || return( $self->pass_error );
Condition0%0/2
$self->_dbi_connect || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_dbi_connect || (return $self->pass_error)
$self->_dbi_connect
Truth table0%0/2
A
A= $self->_dbi_connect
Aresult
11
00
2150 0 $self->{dbh} = $dbh;
2151 }
2152  
2153 # Normalise host for filename usage: keep only [A-Za-z0-9_.-], percent-encode everything else.
2154 # This avoids collisions that would happen with s/\W//g and supports IPv6, ports, etc.
2155 0 my $host_key = "$host";
2156 0 $host_key =~ s/([^A-Za-z0-9_.-])/sprintf( '%%%02X', ord( $1 ) )/ge;
2157 0 my $prefix = "table-${host_key}-${database}-\L${serialiser}";
2158  
2159 my $deserialise_from_file = sub
2160 0 ▶ {
Subroutine __ANON__: not called CC=11 SCAR=48.8
2161 0 my $f = shift( @_ );
2162 0 my $name = $f->basename( '.bin' );
2163 0 ▶ if( index( $name, $prefix ) != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, $prefix) != 0) 0 0 0
2164 {
2165 # Unexpected file name format; ignore it
2166 0 ▶ warn( "Ignoring cache file with unexpected name format: '$f'" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
2167 0 return;
2168 }
2169  
2170 0 ▶ $self->_load_class( $base_class, { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($base_class, {"force", 1}) or return $self->pass_error 0 0 0
2171 0 ▶ $self->_load_class( 'DB::Object::Tables', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Tables", {"force", 1}) or return $self->pass_error 0 0 0
2172 0 ▶ $self->_load_class( 'DB::Object::Constraint::Foreign', { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Foreign", {"force", 1}) or return $self->pass_error 0 0 0
2173 0 ▶ $self->_load_class( "${base_class}::Tables", { force => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Tables", {"force", 1}) or return $self->pass_error 0 0 0
2174 0 ▶ my $tbl = $self->Module::Generic::deserialise(
Condition0%0/2
$self->Module::Generic::deserialise('file', $f, 'lock', 1, 'serialiser', $serialiser) || (return)
l!l
00
MC/DC0%0/1
$self->Module::Generic::deserialise('file', $f, 'lock', 1, 'serialiser', $serialiser) || (return)
$self->Module::Generic::deserialise('file', $f, 'lock', 1, 'serialiser', $serialiser)
Truth table0%0/2
A
A= $self->Module::Generic::deserialise('file', $f, 'lock', 1, 'serialiser', $serialiser)
Aresult
11
00
2175 file => $f,
2176 lock => 1,
2177 serialiser => $serialiser,
2178 ) || return;
2179 0 ▶ unless( $self->_is_a( $tbl => "${base_class}::Tables" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($tbl, "${base_class}::Tables")) 0 0 0
2180 {
2181 0 ▶ warn( "Deserialised object from file '$f' is not a ${base_class}::Tables object, but a '", ref( $tbl ), " object." ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
2182 0 return;
2183 }
2184  
2185 # bless( $tbl => $table_class );
2186 0 ▶ $tbl->attach( $dbo ) || return( $self->pass_error( $tbl->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$tbl->attach($dbo) or return $self->pass_error($tbl->error) 0 0 0
2187 0 return( $tbl );
2188 0 };
2189  
2190 # The caller wants the whole shebang
2191 0 ▶ if( !defined( $table ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $table) { } 0 0 0
elsif ($self->_is_a($table, "${base_class}::Tables")) { } 0 0 0
elsif (not ref $table or ref $table and $self->_can_overload($table, '""')) { } 0 0 0
2192 {
2193 # The caller wants all the table objects for that host and database
2194 0 my @files = $cache_dir->glob( "${prefix}-[a-zA-Z0-9_][a-zA-Z0-9_\\-\\.]*.bin" );
2195 0 my $cache = {};
2196 0 foreach my $f ( @files )
2197 {
2198 0 ▶ my $table = $deserialise_from_file->( $f ) || next;
Condition0%0/2
&$deserialise_from_file($f) || (next)
l!l
00
MC/DC0%0/1
&$deserialise_from_file($f) || (next)
&$deserialise_from_file($f)
Truth table0%0/2
A
A= &$deserialise_from_file($f)
Aresult
11
00
2199 0 my $name = $f->basename( '.bin' );
2200 0 ▶ if( index( $name, $prefix ) != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, $prefix) != 0) 0 0 0
2201 {
2202 # Unexpected file name format; ignore it
2203 0 ▶ warn( "Ignoring cache file with unexpected name format: '$f'" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
2204 0 next;
2205 }
2206 0 $name = [split( /-/, $name )]->[-1];
2207 0 $cache->{ $name } = $table;
2208 }
2209 0 return( $cache );
2210 }
2211 # We are given a table object, we store it in the repository. This is mutator mode
2212 elsif( $self->_is_a( $table => "${base_class}::Tables" ) )
2213 {
2214 0 ▶ my $name = $table->name ||
Condition0%0/2
$table->name || (return $self->error('No table name associated with this table object.'))
l!l
00
MC/DC0%0/1
$table->name || (return $self->error('No table name associated with this table object.'))
$table->name
Truth table0%0/2
A
A= $table->name
Aresult
11
00
2215 return( $self->error( "No table name associated with this table object." ) );
2216 0 ▶ if( $name !~ /^\w+[\w\-\.]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^\w+[\w\-\.]*$/) 0 0 0
2217 {
2218 0 return( $self->error( "The table name '$name' contains illegal characters." ) );
2219 }
2220 0 my $file = $cache_dir->child( "${prefix}-${name}.bin" );
2221 0 ▶ my $tbl = $self->Module::Generic::serialise( $table,
Branch: 1 branch
BranchTrueFalseTotal
$serialiser eq 'Sereal' ? : 0 0 0
Condition0%0/2
$self->Module::Generic::serialise($table, 'file', $file, 'lock', 1, 'serialiser', $serialiser, $serialiser eq 'Sereal' ? ('freeze_callbacks', 1) : ()) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->Module::Generic::serialise($table, 'file', $file, 'lock', 1, 'serialiser', $serialiser, $serialiser eq 'Sereal' ? ('freeze_callbacks', 1) : ()) || (return $self->pass_error)
$self->Module::Generic::serialise($table, 'file', $file, 'lock', 1, 'serialiser', $serialiser, $serialiser eq 'Sereal' ? ('freeze_callbacks', 1) : ())
Truth table0%0/2
A
A= $self->Module::Generic::serialise($table, 'file', $file, 'lock', 1, 'serialiser', $serialiser, $serialiser eq 'Sereal' ? ('freeze_callbacks', 1) : ())
Aresult
11
00
2222 file => $file,
2223 lock => 1,
2224 serialiser => $serialiser,
2225 ( $serialiser eq 'Sereal' ? ( freeze_callbacks => 1 ) : () ),
2226 ) || return( $self->pass_error );
2227 0 return(1);
2228 }
2229 # The user has provided a table name, and thus expects the related cloned table object from the cache table repository.
2230 # This is accessor mode.
2231 ▶ elsif( !ref( $table ) || ( ref( $table ) && $self->_can_overload( $table => '""' ) ) )
Condition0%0/6
not ref $table or ref $table and $self->_can_overload($table, "\"\"")
l!l&&r!l&&!r
000
ref $table and $self->_can_overload($table, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $table or ref $table and $self->_can_overload($table, "\"\"")
not ref $table ref $table $self->_can_overload($table, "\"\"")
Truth table0%0/4
not(A) or B and C
A= not ref $tableB= ref $tableC= $self->_can_overload($table, "\"\"")
ABCresult
1XX1
0111
00X0
0100
2232 {
2233 0 $table = "$table";
2234 0 ▶ if( $table !~ /^\w+[\w\-\.]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($table =~ /^\w+[\w\-\.]*$/) 0 0 0
2235 {
2236 0 return( $self->error( "The table name '$table' contains illegal characters." ) );
2237 }
2238 0 my $cache_file = $cache_dir->child( "${prefix}-${table}.bin" );
2239 0 ▶ if( !$cache_file->exists || $cache_file->is_empty || !$cache_file->is_file )
Branch: 1 branch
BranchTrueFalseTotal
if (not $cache_file->exists or $cache_file->is_empty or not $cache_file->is_file) 0 0 0
Condition0%0/6
not $cache_file->exists or $cache_file->is_empty or not $cache_file->is_file
l!l&&r!l&&!r
000
not $cache_file->exists or $cache_file->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/3
not $cache_file->exists or $cache_file->is_empty or not $cache_file->is_file
not $cache_file->exists $cache_file->is_empty not $cache_file->is_file
Truth table0%0/4
not(A) or B or not(C)
A= not $cache_file->existsB= $cache_file->is_emptyC= not $cache_file->is_file
ABCresult
1XX1
01X1
0011
0000
2240 {
2241 0 return( '' );
2242 }
2243 0 ▶ my $tbl = $deserialise_from_file->( $cache_file ) || return( '' );
Condition0%0/2
&$deserialise_from_file($cache_file) || (return '')
l!l
00
MC/DC0%0/1
&$deserialise_from_file($cache_file) || (return '')
&$deserialise_from_file($cache_file)
Truth table0%0/2
A
A= &$deserialise_from_file($cache_file)
Aresult
11
00
2244 0 return( $tbl );
2245 }
2246 else
2247 {
2248 0 return( $self->error( "I do not understand the value provided for the 'table' option -> ", $self->_str_val( $table ) ) );
2249 }
2250 }
2251  
2252 sub _cache_this
2253 0 ▶{
Subroutine _cache_this: not called CC=75 SCAR=86.5
2254 0 my $self = shift( @_ );
2255 # When this method is accessed by method from package DB::Object::Statement, they CAN NOT
2256 # implicitly pass the statement string or they would risk to modify the previous stored
2257 # query object they represent.
2258 # For instance:
2259 # $obj->select->join( 'some_table', { 'parameter', 'list' } )->fetchrow_hashref()
2260 # here the first query is prepared and cached and its resulting object is passed on to join
2261 # here join will rebuild the query, but will search first if there was one already cached
2262 # if join passes implictly the statement string, this means it will modify the cached query select()
2263 # has just previously stored... This is why method such as join must pass explicitly the query string
2264 0 my $q = shift( @_ );
2265 0 ▶ my $query = ( ref( $q ) && $q->isa( 'DB::Object::Query' ) ) ? $q->as_string : $q;
Branch: 1 branch
BranchTrueFalseTotal
ref $q && $q->isa('DB::Object::Query') ? : 0 0 0
Condition0%0/3
ref $q and $q->isa("DB::Object::Query")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $q and $q->isa("DB::Object::Query")
ref $q $q->isa("DB::Object::Query")
Truth table0%0/3
A and B
A= ref $qB= $q->isa("DB::Object::Query")
ABresult
0X0
100
111
2266 0 ▶ my $dbo = $self->{dbo} || $self->{database_object} || $self;
Condition0%0/6
$self->{'dbo'} || $self->{'database_object'} || $self
l!l&&r!l&&!r
000
$self->{"dbo"} or $self->{"database_object"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{'dbo'} || $self->{'database_object'} || $self
$self->{"dbo"} $self->{"database_object"} $self
Truth table0%0/4
A or B || C
A= $self->{"dbo"}B= $self->{"database_object"}C= $self
ABCresult
1XX1
01X1
0011
0000
2267 0 my $base_class = $self->base_class;
2268 0 my $cache = $dbo->{cache};
2269 0 my $bind = $dbo->{bind};
2270 0 ▶ my $cache_dir = $dbo->cache_dir // $self->new_tempdir;
Condition0%0/3
$dbo->cache_dir // $self->new_tempdir
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbo->cache_dir // $self->new_tempdir
$dbo->cache_dir $self->new_tempdir
Truth table0%0/3
A // B
A= $dbo->cache_dirB= $self->new_tempdir
ABresult
1X1
011
000
2271 0 my $cache_query = $dbo->cache_query;
2272 0 ▶ my $cache_size = $dbo->cache_size // 0;
Condition0%0/2
$dbo->cache_size // 0
l!l
00
MC/DC0%0/1
$dbo->cache_size // 0
$dbo->cache_size
Truth table0%0/2
A
A= $dbo->cache_size
Aresult
11
00
2273 0 ▶ my $serialiser = $dbo->serialiser || $DB::Object::SERIALISER || 'Storable';
Condition0%0/5
$dbo->serialiser || $DB::Object::SERIALISER || 'Storable'
l!l
00
$dbo->serialiser or $DB::Object::SERIALISER
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbo->serialiser || $DB::Object::SERIALISER || 'Storable'
$dbo->serialiser $DB::Object::SERIALISER
Truth table0%0/3
A or B
A= $dbo->serialiserB= $DB::Object::SERIALISER
ABresult
1X1
011
000
2274  
2275 0 ▶ my $use_file_cache = ( defined( $cache_query ) && $cache_query eq 'file' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_query && $cache_query eq 'file' ? : 0 0 0
Condition0%0/3
defined $cache_query and $cache_query eq "file"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cache_query and $cache_query eq "file"
defined $cache_query $cache_query eq "file"
Truth table0%0/3
A and B
A= defined $cache_queryB= $cache_query eq "file"
ABresult
0X0
100
111
2276  
2277 0 my( $repo, $sth, $cache_file, $checksum, $cache_key );
2278 0 my $cached_sth = '';
2279 0 my $host = $dbo->host;
2280 0 my $database = $dbo->database;
2281 0 ▶ my $table = ( ref( $q ) && $dbo->_is_a( $q => "${base_class}::Query" ) && $q->table_object ) ? $q->table_object->name : '';
Branch: 1 branch
BranchTrueFalseTotal
ref $q && $dbo->_is_a($q, "${base_class}::Query") && $q->table_object ? : 0 0 0
Condition0%0/6
ref $q and $dbo->_is_a($q, "${base_class}::Query") and $q->table_object
!ll&&!rl&&r
000
ref $q and $dbo->_is_a($q, "${base_class}::Query")
!ll&&!rl&&r
000
MC/DC0%0/3
ref $q and $dbo->_is_a($q, "${base_class}::Query") and $q->table_object
ref $q $dbo->_is_a($q, "${base_class}::Query") $q->table_object
Truth table0%0/4
A and B and C
A= ref $qB= $dbo->_is_a($q, "${base_class}::Query")C= $q->table_object
ABCresult
0XX0
10X0
1100
1111
2282  
2283 # Compute cache_file (and cache key) early when caching is enabled and cache_dir exists.
2284 # Even if cache_query is "file", we also want a small hot cache in memory.
2285 0 ▶ if( $cache )
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 0 0 0
2286 {
2287 0 local $@;
2288 0 ▶ if( $dbo->_load_class( 'Crypt::Digest::MD5' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($dbo->_load_class("Crypt::Digest::MD5")) 0 0 0
2289 {
2290 $checksum = eval
2291 0 {
2292 0 return( Crypt::Digest::MD5::md5_hex( $query ) );
2293 };
2294 }
2295  
2296 0 ▶ if( !defined( $checksum ) && $dbo->_load_class( 'Digest::MD5' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $checksum and $dbo->_load_class("Digest::MD5")) 0 0 0
Condition0%0/3
not defined $checksum and $dbo->_load_class("Digest::MD5")
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $checksum and $dbo->_load_class("Digest::MD5")
not defined $checksum $dbo->_load_class("Digest::MD5")
Truth table0%0/3
not(A) and B
A= not defined $checksumB= $dbo->_load_class("Digest::MD5")
ABresult
0X0
100
111
2297 {
2298 $checksum = eval
2299 0 {
2300 0 return( Digest::MD5::md5_hex( $query ) );
2301 };
2302 }
2303  
2304 0 ▶ if( !defined( $checksum ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $checksum) 0 0 0
2305 {
2306 0 return( $self->error( "Caching query object is requested, but I could not find either Crypt::Digest::MD5 or Digest::MD5" ) );
2307 }
2308  
2309 0 ▶ my $file = $self->_get_cache_filepath(
Branch: 1 branch
BranchTrueFalseTotal
$table ? : 0 0 0
Condition0%0/2
$self->_get_cache_filepath('cache_dir', $cache_dir, 'extension', 'bin', 'name', $checksum, 'host', $host, 'database', $database, $table ? ('table', $table) : (), 'prefix', 'query') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_cache_filepath('cache_dir', $cache_dir, 'extension', 'bin', 'name', $checksum, 'host', $host, 'database', $database, $table ? ('table', $table) : (), 'prefix', 'query') || (return $self->pass_error)
$self->_get_cache_filepath('cache_dir', $cache_dir, 'extension', 'bin', 'name', $checksum, 'host', $host, 'database', $database, $table ? ('table', $table) : (), 'prefix', 'query')
Truth table0%0/2
A
A= $self->_get_cache_filepath('cache_dir', $cache_dir, 'extension', 'bin', 'name', $checksum, 'host', $host, 'database', $database, $table ? ('table', $table) : (), 'prefix', 'query')
Aresult
11
00
2310 cache_dir => $cache_dir,
2311 extension => 'bin',
2312 name => $checksum,
2313 host => $host,
2314 database => $database,
2315 ( $table ? ( table => $table ) : () ),
2316 prefix => 'query',
2317 ) || return( $self->pass_error );
2318 0 ▶ if( $cache_dir )
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_dir) 0 0 0
2319 {
2320 0 $cache_file = $file;
2321 }
2322 # User requested identifier: basename of cache_file
2323 0 $cache_key = $cache_file->basename( '.bin' );
2324 }
2325  
2326 # Instead of storing statement object in an hash which would mean they would ALL be serialised and deserialised EVRY TIME, we store them by their unique index key, and access them DIRECTLY
2327 0 my $lock;
2328 0 ▶ if( $cache_key )
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_key) 0 0 0
2329 {
2330 0 ▶ $repo = Module::Generic::Global->new( queries_cache => $base_class,
Condition0%0/2
'Module::Generic::Global'->new('queries_cache', $base_class, 'key', $cache_key, 'max_size', $cache_size) || (return $dbo->pass_error('Module::Generic::Global'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Global'->new('queries_cache', $base_class, 'key', $cache_key, 'max_size', $cache_size) || (return $dbo->pass_error('Module::Generic::Global'->error))
'Module::Generic::Global'->new('queries_cache', $base_class, 'key', $cache_key, 'max_size', $cache_size)
Truth table0%0/2
A
A= 'Module::Generic::Global'->new('queries_cache', $base_class, 'key', $cache_key, 'max_size', $cache_size)
Aresult
11
00
2331 key => $cache_key,
2332 max_size => $cache_size,
2333 ) || return( $dbo->pass_error( Module::Generic::Global->error ) );
2334 0 $lock = $repo->lock;
2335 0 $cached_sth = $repo->get;
2336 # Nothing, so we remove that repo. We do not leave it. This saves memory, although not much.
2337 0 ▶ $repo->remove if( !defined( $cached_sth ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cached_sth 0 0 0
2338 # The lock gets removed automatically when it gets out of scope, so we store it in $lock
2339 0 $repo->unlock;
2340 }
2341  
2342 # If found in-memory cache, we revive it
2343 0 ▶ if( $cached_sth )
Branch: 1 branch
BranchTrueFalseTotal
if ($cached_sth) 0 0 0
2344 {
2345 # Thanks to Module::Generic::Global, this is an thawed statement object.
2346 # We just need to attach it to our current database object
2347 0 $sth = $cached_sth;
2348 0 ▶ if( !$sth->attach( $dbo ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->attach($dbo)) 0 0 0
2349 {
2350 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2351 0 return( $self->pass_error( $sth->error ) );
2352 }
2353  
2354 0 my $prepare_options = {};
2355 0 ▶ if( $q && $self->_is_a( $q, "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $self->_is_a($q, "${base_class}::Query")) 0 0 0
Condition0%0/3
$q and $self->_is_a($q, "${base_class}::Query")
!ll&&!rl&&r
000
MC/DC0%0/2
$q and $self->_is_a($q, "${base_class}::Query")
$q $self->_is_a($q, "${base_class}::Query")
Truth table0%0/3
A and B
A= $qB= $self->_is_a($q, "${base_class}::Query")
ABresult
0X0
100
111
2356 {
2357 0 $prepare_options = $q->prepare_options->as_hash;
2358 }
2359  
2360  
2361 0 local $@;
2362 my $sth_dbi = eval
2363 0 {
2364 0 ▶ local( $SIG{__DIE__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2365 0 ▶ local( $SIG{__WARN__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2366 0 ▶ $dbo->{dbh}->prepare_cached( $query, ( scalar( keys( %$prepare_options ) ) ? $prepare_options : () ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$prepare_options ? : 0 0 0
2367 };
2368  
2369 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2370 {
2371 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2372 0 return( $self->error( "Error preparing cached SQL query: $@\nQuery was:\n$query" ) );
2373 }
2374  
2375 0 $sth->{sth} = $sth_dbi;
2376  
2377 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2378 }
2379  
2380 # If no in-memory was found yet, we try the file cache (explicit mode only)
2381 0 ▶ if( !defined( $sth ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sth and $cache and $use_file_cache and $cache_file and $cache_file->exists and not $cache_file->is_empty and $cache_file->is_file) 0 0 0
Condition0%0/18
not defined $sth and $cache and $use_file_cache and $cache_file and $cache_file->exists and not $cache_file->is_empty and $cache_file->is_file
!ll&&!rl&&r
000
not defined $sth and $cache and $use_file_cache and $cache_file and $cache_file->exists and not $cache_file->is_empty
!ll&&!rl&&r
000
not defined $sth and $cache and $use_file_cache and $cache_file and $cache_file->exists
!ll&&!rl&&r
000
not defined $sth and $cache and $use_file_cache and $cache_file
!ll&&!rl&&r
000
not defined $sth and $cache and $use_file_cache
!ll&&!rl&&r
000
not defined $sth and $cache
!ll&&!rl&&r
000
MC/DC0%0/7
not defined $sth and $cache and $use_file_cache and $cache_file and $cache_file->exists and not $cache_file->is_empty and $cache_file->is_file
not defined $sth $cache $use_file_cache $cache_file $cache_file->exists not $cache_file->is_empty $cache_file->is_file
Truth table0%0/8
not(A) and B and C and D and E and not(F) and G
A= not defined $sthB= $cacheC= $use_file_cacheD= $cache_fileE= $cache_file->existsF= not $cache_file->is_emptyG= $cache_file->is_file
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
2382 $cache &&
2383 $use_file_cache &&
2384 $cache_file &&
2385 $cache_file->exists &&
2386 !$cache_file->is_empty &&
2387 $cache_file->is_file )
2388 {
2389 0 $sth = $self->Module::Generic::deserialise(
2390 file => $cache_file,
2391 lock => 1,
2392 serialiser => $serialiser,
2393 );
2394 0 ▶ if( !$sth )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth) 0 0 0
2395 {
2396 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2397 0 return( $self->pass_error );
2398 }
2399  
2400 0 ▶ if( !$sth->attach( $dbo ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->attach($dbo)) 0 0 0
2401 {
2402 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2403 0 return( $self->pass_error( $sth->error ) );
2404 }
2405  
2406 0 my $prepare_options = {};
2407 0 ▶ if( $q && $dbo->_is_a( $q, "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $dbo->_is_a($q, "${base_class}::Query")) 0 0 0
Condition0%0/3
$q and $dbo->_is_a($q, "${base_class}::Query")
!ll&&!rl&&r
000
MC/DC0%0/2
$q and $dbo->_is_a($q, "${base_class}::Query")
$q $dbo->_is_a($q, "${base_class}::Query")
Truth table0%0/3
A and B
A= $qB= $dbo->_is_a($q, "${base_class}::Query")
ABresult
0X0
100
111
2408 {
2409 0 $prepare_options = $q->prepare_options->as_hash;
2410 }
2411  
2412  
2413 0 local $@;
2414 my $sth_dbi = eval
2415 0 {
2416 0 ▶ local( $SIG{__DIE__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2417 0 ▶ local( $SIG{__WARN__} ) = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2418 0 ▶ $dbo->{dbh}->prepare_cached( $query, ( scalar( keys( %$prepare_options ) ) ? $prepare_options : () ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$prepare_options ? : 0 0 0
2419 };
2420  
2421 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2422 {
2423 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2424 0 return( $self->error( "Error preparing cached SQL query: $@\nQuery was:\n$query" ) );
2425 }
2426  
2427 0 $sth->{sth} = $sth_dbi;
2428 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2429 }
2430  
2431 # The statement is not cached anywhere, so we prepare it now
2432 0 ▶ if( !defined( $sth ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sth) { } 0 0 0
2433 {
2434 0 my $prepare_options = {};
2435 0 ▶ if( $q && $self->_is_a( $q, "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $self->_is_a($q, "${base_class}::Query")) 0 0 0
Condition0%0/3
$q and $self->_is_a($q, "${base_class}::Query")
!ll&&!rl&&r
000
MC/DC0%0/2
$q and $self->_is_a($q, "${base_class}::Query")
$q $self->_is_a($q, "${base_class}::Query")
Truth table0%0/3
A and B
A= $qB= $self->_is_a($q, "${base_class}::Query")
ABresult
0X0
100
111
2436 {
2437 0 $prepare_options = $q->prepare_options->as_hash;
2438 }
2439  
2440 0 ▶ if( !( $sth = $dbo->prepare( $query, ( scalar( keys( %$prepare_options ) ) ? $prepare_options : () ) ) ) )
Branch: 2 branches
BranchTrueFalseTotal
unless ($sth = $dbo->prepare($query, scalar keys %$prepare_options ? $prepare_options : ())) 0 0 0
scalar keys %$prepare_options ? : 0 0 0
2441 {
2442 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2443 0 return( $self->pass_error( $dbo->error ) );
2444 }
2445  
2446 # File cache (explicit mode only)
2447 0 ▶ if( $cache && $use_file_cache && $cache_file )
Branch: 2 branches
BranchTrueFalseTotal
if ($cache and $use_file_cache and $cache_file) { } 0 0 0
elsif ($bind) { } 0 0 0
Condition0%0/6
$cache and $use_file_cache and $cache_file
!ll&&!rl&&r
000
$cache and $use_file_cache
!ll&&!rl&&r
000
MC/DC0%0/3
$cache and $use_file_cache and $cache_file
$cache $use_file_cache $cache_file
Truth table0%0/4
A and B and C
A= $cacheB= $use_file_cacheC= $cache_file
ABCresult
0XX0
10X0
1100
1111
2448 {
2449 0 ▶ if( !$dbo->Module::Generic::serialise( $sth,
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbo->Module::Generic::serialise($sth, "file", $cache_file, "lock", 1, "serialiser", $serialiser)) 0 0 0
2450 file => $cache_file,
2451 lock => 1,
2452 serialiser => $serialiser,
2453 ) )
2454 {
2455 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2456 0 return( $self->pass_error( $dbo->error ) );
2457 }
2458 }
2459 # If caching is off, but the query is a binded parameters' one,
2460 # make the current object hold the statement object
2461 elsif( $bind )
2462 {
2463 0 $self->{sth} = $sth;
2464 }
2465 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2466 }
2467 else
2468 {
2469 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2470 }
2471  
2472 # Ensure we unlock even if sth came from mem cache path where we unlocked earlier
2473 0 ▶ $repo->unlock if( $repo );
Branch: 1 branch
BranchTrueFalseTotal
if $repo 0 0 0
2474  
2475 # Attach query object to statement (this can be dangerous if the statement is long-lived;
2476 # keep your query object small / reset/dirty it aggressively)
2477 0 ▶ $sth->query_object( $q ) if( $dbo->_is_a( $q, "${base_class}::Query" ) );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->_is_a($q, "${base_class}::Query") 0 0 0
2478 0 ▶ $sth->table_object( $self ) if( $self->isa( "${base_class}::Tables" ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa("${base_class}::Tables") 0 0 0
2479  
2480 # Caching the query as a constant
2481 0 ▶ if( $q && $dbo->_is_object( $q ) && $q->isa( "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $dbo->_is_object($q) and $q->isa("${base_class}::Query")) 0 0 0
Condition0%0/6
$q and $dbo->_is_object($q) and $q->isa("${base_class}::Query")
!ll&&!rl&&r
000
$q and $dbo->_is_object($q)
!ll&&!rl&&r
000
MC/DC0%0/3
$q and $dbo->_is_object($q) and $q->isa("${base_class}::Query")
$q $dbo->_is_object($q) $q->isa("${base_class}::Query")
Truth table0%0/4
A and B and C
A= $qB= $dbo->_is_object($q)C= $q->isa("${base_class}::Query")
ABCresult
0XX0
10X0
1100
1111
2482 {
2483 0 my $constant = $q->constant;
2484 0 ▶ if( $constant && scalar( keys( %$constant ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($constant and scalar keys %$constant) 0 0 0
Condition0%0/2
$constant and scalar keys %$constant
!ll
00
MC/DC0%0/1
$constant and scalar keys %$constant
$constant
Truth table0%0/2
A
A= $constant
Aresult
00
11
2485 {
2486 0 foreach my $k (qw( pack file line ))
2487 {
2488 0 ▶ return( $self->error( "Could not find the parameter \"$k\" in the constant query hash reference." ) ) if( !$constant->{ $k } );
Branch: 1 branch
BranchTrueFalseTotal
unless $constant->{$k} 0 0 0
2489 }
2490  
2491 # We temporarily not store the query object, and see if this affects positively the memory consumption.
2492 # $constant->{query_object} = $q;
2493 # $dbo->constant_queries_cache_set( $constant );
2494 }
2495 }
2496  
2497 0 return( $sth );
2498 }
2499  
2500 sub _check_connect_param
2501 3 ▶{
Subroutine _check_connect_param: called CC=8 SCAR=23.4
2502 3 my $self = shift( @_ );
2503 3 my $param = shift( @_ );
2504 3 my $valid = $self->_connection_parameters( $param );
2505 3 my $opts = $self->_connection_options( $param );
2506 3 foreach my $k ( keys( %$param ) )
2507 {
2508 # If it is not in the list and it does not start with an upper case; those are like RaiseError, AutoCommit, etc
2509 8 ▶ if( CORE::length( $param->{ $k } ) && !grep( /^$k$/, @$valid ) && !CORE::exists( $opts->{ $k } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $param->{$k} and not grep(/^$k$/, @$valid) and not exists $opts->{$k}) 0 8 8
Condition33%2/6
length $param->{$k} and not grep(/^$k$/, @$valid) and not exists $opts->{$k}
!ll&&!rl&&r
800
length $param->{$k} and not grep(/^$k$/, @$valid)
!ll&&!rl&&r
080
MC/DC0%0/3
length $param->{$k} and not grep(/^$k$/, @$valid) and not exists $opts->{$k}
length $param->{$k} not grep(/^$k$/, @$valid) not exists $opts->{$k}
Truth table25%1/4
A and not(B) and not(C)
A= length $param->{$k}B= not grep(/^$k$/, @$valid)C= not exists $opts->{$k}
ABCresult
0XX0
10X0
1100
1111
2510 {
2511 0 return( $self->error( "Invalid parameter '$k'." ) );
2512 }
2513 }
2514 3 my @opts_to_remove = keys( %$opts );
2515 3 ▶ CORE::delete( @$param{ @opts_to_remove } ) if( scalar( @opts_to_remove ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts_to_remove 1 2 3
2516 3 $param->{opt} = $opts;
2517 3 ▶ $param->{database} = CORE::delete( $param->{db} ) if( !length( $param->{database} ) && $param->{db} );
Branch: 1 branch
BranchTrueFalseTotal
if not length $param->{"database"} and $param->{"db"} 0 3 3
Condition33%1/3
not length $param->{"database"} and $param->{"db"}
!ll&&!rl&&r
300
MC/DC0%0/2
not length $param->{"database"} and $param->{"db"}
not length $param->{"database"} $param->{"db"}
Truth table33%1/3
not(A) and B
A= not length $param->{"database"}B= $param->{"db"}
ABresult
0X0
100
111
2518 3 return( $param );
2519 }
2520  
2521 sub _check_default_option
2522 0 ▶{
Subroutine _check_default_option: not called CC=1 SCAR=6.9
2523 0 my $self = shift( @_ );
2524 0 my $opts = $self->_get_args_as_hash( @_ );
2525 # return( $self->error( "Provided option is not a hash reference." ) ) if( !$self->_is_hash( $opts ) );
2526 # This method should be superseded by an inherited class
2527 0 return( $opts );
2528 }
2529  
2530 # Simplistic clone by design. We do not want a recursive clone like Clone::clone()
2531 sub _clone
2532 0 ▶{
Subroutine _clone: not called CC=3 SCAR=24.8
2533 0 my( $self, $this ) = @_;
2534 0 ▶ if( $self->_is_array( $this ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($this)) { } 0 0 0
elsif (ref $this eq 'HASH') { } 0 0 0
2535 {
2536 0 my @clone = @$this;
2537 0 return( \@clone );
2538 }
2539 elsif( ref( $this ) eq 'HASH' )
2540 {
2541 0 my @keys = keys( %$this );
2542 0 my $clone = {};
2543 0 @$clone{ @keys } = @$this{ @keys };
2544 0 return( $clone );
2545 }
2546 else
2547 {
2548 0 return( $self->error( "Unsupported data type to clone. This method only support hash or array reference." ) );
2549 }
2550 }
2551  
2552 sub _connection_options
2553 3 ▶{
Subroutine _connection_options: called CC=3 SCAR=11.4
2554 3 my $self = shift( @_ );
2555 3 my $param = shift( @_ );
2556 3 my @dbi_opts = grep( /^[A-Z][a-zA-Z]+/, keys( %$param ) );
2557 3 my $opt = {};
2558 3 ▶ $opt = CORE::delete( $param->{opt} ) if( $param->{opt} && $self->_is_hash( $param->{opt} => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"opt"} and $self->_is_hash($param->{"opt"}, "strict") 0 3 3
Condition33%1/3
$param->{"opt"} and $self->_is_hash($param->{"opt"}, "strict")
!ll&&!rl&&r
300
MC/DC0%0/2
$param->{"opt"} and $self->_is_hash($param->{"opt"}, "strict")
$param->{"opt"} $self->_is_hash($param->{"opt"}, "strict")
Truth table33%1/3
A and B
A= $param->{"opt"}B= $self->_is_hash($param->{"opt"}, "strict")
ABresult
0X0
100
111
2559 3 @$opt{ @dbi_opts } = @$param{ @dbi_opts };
2560 3 return( $opt );
2561 }
2562  
2563 sub _connection_parameters
2564 0 ▶{
Subroutine _connection_parameters: not called CC=2 SCAR=17.9
2565 0 my $self = shift( @_ );
2566 0 my $param = shift( @_ );
2567 0 my $params = $self->new_array( [qw(
2568 db login passwd host port driver database server opt uri debug cache_connections
2569 cache_dir cache_table connect_via serialiser unknown_field id
2570 )] );
2571 0 ▶ my $core = $self->{_core_fields} || [];
Condition0%0/2
$self->{'_core_fields'} || []
l!l
00
MC/DC0%0/1
$self->{'_core_fields'} || []
$self->{'_core_fields'}
Truth table0%0/2
A
A= $self->{'_core_fields'}
Aresult
11
00
2572 0 $params->push( @$core );
2573 0 return( $params->unique(1) );
2574 }
2575  
2576 sub _connection_params2hash
2577 3 ▶{
Subroutine _connection_params2hash: called CC=74 SCAR=77.6
2578 3 my $self = shift( @_ );
2579 3 my $argv = [@_];
2580 3 my $param = {};
2581 3 ▶ if( !( @_ % 2 ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not @_ % 2) { } 0 3 3
elsif (@_ == 1 and (ref $_[0] // '') eq 'HASH') { } 3 0 3
2582 {
2583 0 $param = { @_ };
2584 }
2585 ▶ elsif( @_ == 1 && ( ref( $_[0] ) // '' ) eq 'HASH' )
Condition40%2/5
@_ == 1 and (ref $_[0] // "") eq "HASH"
!ll&&!rl&&r
003
ref $_[0] // ""
l!l
30
MC/DC0%0/2
@_ == 1 and (ref $_[0] // "") eq "HASH"
@_ == 1 ref $_[0]
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
2586 {
2587 3 $param = shift( @_ );
2588 }
2589 else
2590 {
2591 0 my @keys = qw( database login passwd host driver schema );
2592 # Only add in the $param hash the keys value we were given, so we don't create keys entry when not needed
2593 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
2594 {
2595 0 $param->{ $keys[ $i ] } = $_[ $i ];
2596 }
2597 }
2598  
2599 3 my $equi =
2600 {
2601 database => 'DB_NAME',
2602 login => 'DB_LOGIN',
2603 passwd => 'DB_PASSWD',
2604 host => 'DB_HOST',
2605 port => 'DB_PORT',
2606 driver => 'DB_DRIVER',
2607 schema => 'DB_SCHEMA',
2608 };
2609 3 foreach my $prop ( keys( %$equi ) )
2610 {
2611 21 ▶ $param->{ $prop } = $ENV{ $equi->{ $prop } } if( $ENV{ $equi->{ $prop } } && !length( $param->{ $prop } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{$equi->{$prop}} and not length $param->{$prop} 0 21 21
Condition33%1/3
$ENV{$equi->{$prop}} and not length $param->{$prop}
!ll&&!rl&&r
2100
MC/DC0%0/2
$ENV{$equi->{$prop}} and not length $param->{$prop}
$ENV{$equi->{$prop}} not length $param->{$prop}
Truth table33%1/3
A and not(B)
A= $ENV{$equi->{$prop}}B= not length $param->{$prop}
ABresult
0X0
100
111
2612 }
2613  
2614 # A simple json file
2615 # An URI could be http://localhost:5432?database=somedb etc...
2616 # or it could also be file:/foo/bar?opt={"RaiseError":true}
2617 3 ▶ if( $param->{uri} || $ENV{DB_CON_URI} )
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"uri"} or $ENV{"DB_CON_URI"}) 1 2 3
Condition66%2/3
$param->{"uri"} or $ENV{"DB_CON_URI"}
l!l&&r!l&&!r
012
MC/DC50%1/2
$param->{"uri"} or $ENV{"DB_CON_URI"}
$param->{"uri"} $ENV{"DB_CON_URI"}
Truth table66%2/3
A or B
A= $param->{"uri"}B= $ENV{"DB_CON_URI"}
ABresult
1X1
011
000
2618 {
2619 1 my $uri;
2620 eval
2621 1 {
2622 1 require URI;
2623 1 ▶ $uri = URI->new( $param->{uri} || $ENV{DB_CON_URI} );
Condition33%1/3
$param->{'uri'} || $ENV{'DB_CON_URI'}
l!l&&r!l&&!r
010
MC/DC0%0/2
$param->{'uri'} || $ENV{'DB_CON_URI'}
$param->{'uri'} $ENV{'DB_CON_URI'}
Truth table33%1/3
A || B
A= $param->{'uri'}B= $ENV{'DB_CON_URI'}
ABresult
1X1
011
000
2624 };
2625 1 ▶ if( !$@ && $uri )
Branch: 1 branch
BranchTrueFalseTotal
if (not $@ and $uri) 1 0 1
Condition33%1/3
not $@ and $uri
!ll&&!rl&&r
001
MC/DC0%0/2
not $@ and $uri
not $@ $uri
Truth table33%1/3
not(A) and B
A= not $@B= $uri
ABresult
0X0
100
111
2626 {
2627 # Make sure our parameter is a valid URI object
2628 1 $param->{uri} = $uri;
2629 1 ▶ if( $uri->can( 'port' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($uri->can('port')) { } 0 1 1
elsif (length $uri->path) { } 1 0 1
2630 {
2631 0 $param->{host} = $uri->host;
2632 0 ▶ $param->{port} = $uri->port if( $uri->port );
Branch: 1 branch
BranchTrueFalseTotal
if $uri->port 0 0 0
2633 }
2634 # file:/
2635 elsif( length( $uri->path ) )
2636 {
2637 1 $param->{database} = ( $uri->path_segments )[-1];
2638 }
2639 1 my( %q ) = $uri->query_form;
2640 1 ▶ $param->{host} = $q{host} if( $q{host} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"host"} 0 1 1
2641 1 ▶ $param->{port} = $q{port} if( $q{port} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"port"} 0 1 1
2642 1 ▶ $param->{database} = $q{database} if( $q{database} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"database"} 0 1 1
2643 1 ▶ $param->{schema} = $q{schema} if( $q{schema} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"schema"} 0 1 1
2644 1 ▶ $param->{user} = $q{user} if( $q{user} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"user"} 0 1 1
2645 1 ▶ $param->{login} = $q{login} if( $q{login} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"login"} 0 1 1
2646 1 ▶ $param->{password} = $q{password} if( $q{password} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"password"} 0 1 1
2647 1 ▶ $param->{opt} = $q{opt} if( $q{opt} );
Branch: 1 branch
BranchTrueFalseTotal
if $q{"opt"} 0 1 1
2648 1 ▶ $param->{login} = CORE::delete( $param->{user} ) if( !$param->{login} && $param->{user} );
Branch: 1 branch
BranchTrueFalseTotal
if not $param->{"login"} and $param->{"user"} 0 1 1
Condition33%1/3
not $param->{"login"} and $param->{"user"}
!ll&&!rl&&r
010
MC/DC0%0/2
not $param->{"login"} and $param->{"user"}
not $param->{"login"} $param->{"user"}
Truth table33%1/3
not(A) and B
A= not $param->{"login"}B= $param->{"user"}
ABresult
0X0
100
111
2649 1 ▶ if( $q{opt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($q{"opt"}) 0 1 1
2650 {
2651 0 my $jdata = {};
2652 eval
2653 0 {
2654 0 require JSON;
2655 0 ▶ if( defined( *{ "JSON::" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"JSON::";}) 0 0 0
2656 {
2657 0 my $j = JSON->new->allow_nonref;
2658 0 $jdata = $j->decode( $q{opt} );
2659 }
2660 };
2661 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2662 {
2663 0 warn( "Found the database connection opt parameter provided in the connection uri \"$uri\", but could not decode its json value: $@\n" );
2664 }
2665 0 ▶ $param->{opt} = $jdata if( scalar( keys( %$jdata ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$jdata 0 0 0
2666 }
2667 }
2668 }
2669  
2670 3 ▶ if( $param->{conf_file} || $param->{config_file} || $ENV{DB_CON_FILE} )
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"conf_file"} or $param->{"config_file"} or $ENV{"DB_CON_FILE"}) 0 3 3
Condition33%2/6
$param->{"conf_file"} or $param->{"config_file"} or $ENV{"DB_CON_FILE"}
l!l&&r!l&&!r
003
$param->{"conf_file"} or $param->{"config_file"}
l!l&&r!l&&!r
003
MC/DC0%0/3
$param->{"conf_file"} or $param->{"config_file"} or $ENV{"DB_CON_FILE"}
$param->{"conf_file"} $param->{"config_file"} $ENV{"DB_CON_FILE"}
Truth table25%1/4
A or B or C
A= $param->{"conf_file"}B= $param->{"config_file"}C= $ENV{"DB_CON_FILE"}
ABCresult
1XX1
01X1
0011
0000
2671 {
2672 0 ▶ my $db_con_file = $self->new_file( CORE::delete( $param->{conf_file} ) || CORE::delete( $param->{config_file} ) || $ENV{DB_CON_FILE} );
Condition0%0/6
delete $param->{'conf_file'} || delete $param->{'config_file'} || $ENV{'DB_CON_FILE'}
l!l&&r!l&&!r
000
delete $param->{"conf_file"} or delete $param->{"config_file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
delete $param->{'conf_file'} || delete $param->{'config_file'} || $ENV{'DB_CON_FILE'}
delete $param->{"conf_file"} delete $param->{"config_file"} $ENV{'DB_CON_FILE'}
Truth table0%0/4
A or B || C
A= delete $param->{"conf_file"}B= delete $param->{"config_file"}C= $ENV{'DB_CON_FILE'}
ABCresult
1XX1
01X1
0011
0000
2673 0 my $db_con_file_ok = 0;
2674 0 ▶ if( !$db_con_file->exists )
Branch: 3 branches
BranchTrueFalseTotal
if (not $db_con_file->exists) { } 0 0 0
elsif ($db_con_file->is_empty) { } 0 0 0
elsif (not $db_con_file->can_read) { } 0 0 0
2675 {
2676 0 warn( "Database connection parameter file \"$db_con_file\" was provided but does not exist.\n" );
2677 }
2678 elsif( $db_con_file->is_empty )
2679 {
2680 0 warn( "Database connection parameter file \"$db_con_file\" was provided but the file is empty.\n" );
2681 }
2682 elsif( !$db_con_file->can_read )
2683 {
2684 0 warn( "Database connection parameter file \"$db_con_file\" was provided but the file lacks privileges to be read.\n" );
2685 }
2686 else
2687 {
2688 0 $db_con_file_ok++;
2689 }
2690  
2691 0 my $json = $db_con_file->load_json;
2692 # If the configuration file has some issue, we warn about it, but we move on.
2693 0 ▶ if( !$json )
Branch: 1 branch
BranchTrueFalseTotal
unless ($json) 0 0 0
2694 {
2695 0 warn( "Database connection parameter file \"$db_con_file\" was provided, but I encountered the following error while trying to read its json data: ", $db_con_file->error );
2696 }
2697 0 ▶ $json = {} if( !$self->_is_hash( $json => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($json, "strict") 0 0 0
2698 0 my $ref = {};
2699 0 ▶ if( exists( $json->{databases} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $json->{'databases'}) { } 0 0 0
2700 {
2701 0 ▶ return( $self->error( "Found a property 'databases' in the connections configuration file \"$db_con_file\". I was expecting this property to be an array reference and instead I found this: '$json->{databases}'" ) ) if( !$self->_is_array( $json->{databases} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($json->{"databases"}) 0 0 0
2702 # When called from sub classes, this is set
2703 0 my $driver = $self->driver;
2704 # We take the first one matching our driver if any, or else we just take the first one
2705 0 foreach my $this ( @{$json->{databases}} )
2706 {
2707 0 ▶ if( !$param->{database} && ( !$driver || $this->{driver} eq $driver ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $param->{'database'} and !$driver || $this->{'driver'} eq $driver) { } 0 0 0
elsif ($param->{'database'} and $this->{'database'} and $this->{'database'} eq $param->{'database'} and !$param->{'host'} || $this->{'host'} && $param->{'host'} eq $this->{'host'} and !$param->{'port'} || $this->{'port'} && $param->{'port'} eq $this->{'port'} and !$param->{'login'} || $this->{'login'} && $param->{'login'} eq $this->{'login'}) { } 0 0 0
Condition0%0/6
not $param->{"database"} and !$driver || $this->{"driver"} eq $driver
!ll&&!rl&&r
000
not $driver or $this->{"driver"} eq $driver
l!l&&r!l&&!r
000
MC/DC0%0/3
not $param->{"database"} and !$driver || $this->{"driver"} eq $driver
not $param->{"database"} not $driver $this->{"driver"} eq $driver
Truth table0%0/4
not(A) and not(B) or C
A= not $param->{"database"}B= not $driverC= $this->{"driver"} eq $driver
ABCresult
0XX0
1000
11X1
1011
2708 {
2709 0 $ref = $this;
2710 0 last;
2711 }
2712 ▶ elsif( $param->{database} && $this->{database} && $this->{database} eq $param->{database} &&
Condition0%0/33
$param->{"database"} and $this->{"database"} and $this->{"database"} eq $param->{"database"} and !$param->{"host"} || $this->{"host"} && $param->{"host"} eq $this->{"host"} and !$param->{"port"} || $this->{"port"} && $param->{"port"} eq $this->{"port"} and !$param->{"login"} || $this->{"login"} && $param->{"login"} eq $this->{"login"}
!ll&&!rl&&r
000
$param->{"database"} and $this->{"database"} and $this->{"database"} eq $param->{"database"} and !$param->{"host"} || $this->{"host"} && $param->{"host"} eq $this->{"host"} and !$param->{"port"} || $this->{"port"} && $param->{"port"} eq $this->{"port"}
!ll&&!rl&&r
000
$param->{"database"} and $this->{"database"} and $this->{"database"} eq $param->{"database"} and !$param->{"host"} || $this->{"host"} && $param->{"host"} eq $this->{"host"}
!ll&&!rl&&r
000
$param->{"database"} and $this->{"database"} and $this->{"database"} eq $param->{"database"}
!ll&&!rl&&r
000
$param->{"database"} and $this->{"database"}
!ll&&!rl&&r
000
not $param->{"host"} or $this->{"host"} and $param->{"host"} eq $this->{"host"}
l!l&&r!l&&!r
000
$this->{"host"} and $param->{"host"} eq $this->{"host"}
!ll&&!rl&&r
000
not $param->{"port"} or $this->{"port"} and $param->{"port"} eq $this->{"port"}
l!l&&r!l&&!r
000
$this->{"port"} and $param->{"port"} eq $this->{"port"}
!ll&&!rl&&r
000
not $param->{"login"} or $this->{"login"} and $param->{"login"} eq $this->{"login"}
l!l&&r!l&&!r
000
$this->{"login"} and $param->{"login"} eq $this->{"login"}
!ll&&!rl&&r
000
MC/DC0%0/12
$param->{"database"} and $this->{"database"} and $this->{"database"} eq $param->{"database"} and !$param->{"host"} || $this->{"host"} && $param->{"host"} eq $this->{"host"} and !$param->{"port"} || $this->{"port"} && $param->{"port"} eq $this->{"port"} and !$param->{"login"} || $this->{"login"} && $param->{"login"} eq $this->{"login"}
$param->{"database"} $this->{"database"} $this->{"database"} eq $param->{"database"} not $param->{"host"} $this->{"host"} $param->{"host"} eq $this->{"host"} not $param->{"port"} $this->{"port"} $param->{"port"} eq $this->{"port"} not $param->{"login"} $this->{"login"} $param->{"login"} eq $this->{"login"}
Truth table0%0/25
A and B and C and not(D) or E and F and not(G) or H and I and not(J) or K and L
A= $param->{"database"}B= $this->{"database"}C= $this->{"database"} eq $param->{"database"}D= not $param->{"host"}E= $this->{"host"}F= $param->{"host"} eq $this->{"host"}G= not $param->{"port"}H= $this->{"port"}I= $param->{"port"} eq $this->{"port"}J= not $param->{"login"}K= $this->{"login"}L= $param->{"login"} eq $this->{"login"}
ABCDEFGHIJKLresult
0XXXXXXXXXXX0
10XXXXXXXXXX0
110XXXXXXXXX0
11100XXXXXXX0
111010XXXXXX0
1111XX00XXXX0
1111XX010XXX0
11101100XXXX0
111011010XXX0
1111XX1XX00X0
1111XX1XX0100
1111XX01100X0
1111XX0110100
1110111XX00X0
1110111XX0100
11101101100X0
1110110110100
1111XX1XX1XX1
1111XX1XX0111
1111XX0111XX1
1111XX0110111
1110111XX1XX1
1110111XX0111
1110110111XX1
1110110110111
2713 ( !$param->{host} || ( $this->{host} && $param->{host} eq $this->{host} ) ) &&
2714 ( !$param->{port} || ( $this->{port} && $param->{port} eq $this->{port} ) ) &&
2715 ( !$param->{login} || ( $this->{login} && $param->{login} eq $this->{login} ) ) )
2716 {
2717 0 $ref = $this;
2718 0 last;
2719 }
2720 }
2721 }
2722 else
2723 {
2724 0 $ref = $json;
2725 }
2726  
2727 0 ▶ if( scalar( keys( %$ref ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$ref) 0 0 0
2728 {
2729 0 foreach my $k ( qw( database login passwd host port driver schema opt ) )
2730 {
2731 0 ▶ $param->{ $k } = $ref->{ $k } if( !length( $param->{ $k } ) && length( $ref->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
if not length $param->{$k} and length $ref->{$k} 0 0 0
Condition0%0/3
not length $param->{$k} and length $ref->{$k}
!ll&&!rl&&r
000
MC/DC0%0/2
not length $param->{$k} and length $ref->{$k}
not length $param->{$k} length $ref->{$k}
Truth table0%0/3
not(A) and B
A= not length $param->{$k}B= length $ref->{$k}
ABresult
0X0
100
111
2732 }
2733 }
2734  
2735 # Grab any cache_* configuration property in the file
2736 0 foreach my $prop ( grep{ /^(cache_|cache\z|use_cache\z)/ } keys( %$json ) )
2737 {
2738 0 ▶ $param->{ $prop } = $json->{ $prop } if( CORE::exists( $json->{ $prop } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $json->{$prop} 0 0 0
2739 }
2740 0 ▶ if( CORE::exists( $json->{serialiser} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $json->{'serialiser'}) { } 0 0 0
elsif (exists $json->{'serializer'}) { } 0 0 0
2741 {
2742 0 $param->{serialiser} = $json->{serialiser};
2743 }
2744 elsif( CORE::exists( $json->{serializer} ) )
2745 {
2746 0 $param->{serialiser} = $json->{serializer};
2747 }
2748 }
2749  
2750 3 ▶ if( CORE::exists( $param->{host} ) && index( $param->{host}, ':' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param->{"host"} and index($param->{"host"}, ":") != -1) 0 3 3
Condition33%1/3
exists $param->{"host"} and index($param->{"host"}, ":") != -1
!ll&&!rl&&r
300
MC/DC0%0/2
exists $param->{"host"} and index($param->{"host"}, ":") != -1
exists $param->{"host"} index($param->{"host"}, ":") != -1
Truth table33%1/3
A and B
A= exists $param->{"host"}B= index($param->{"host"}, ":") != -1
ABresult
0X0
100
111
2751 {
2752 0 @$param{ qw( host port ) } = split( /:/, $param->{host}, 2 );
2753 }
2754  
2755 3 ▶ if( !$param->{opt} && $ENV{DB_OPT} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $param->{"opt"} and $ENV{"DB_OPT"}) 0 3 3
Condition33%1/3
not $param->{"opt"} and $ENV{"DB_OPT"}
!ll&&!rl&&r
030
MC/DC0%0/2
not $param->{"opt"} and $ENV{"DB_OPT"}
not $param->{"opt"} $ENV{"DB_OPT"}
Truth table33%1/3
not(A) and B
A= not $param->{"opt"}B= $ENV{"DB_OPT"}
ABresult
0X0
100
111
2756 {
2757 0 my $jdata = {};
2758 eval
2759 0 {
2760 0 require JSON;
2761 0 ▶ if( defined( *{ "JSON::" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"JSON::";}) 0 0 0
2762 {
2763 0 my $j = JSON->new->allow_nonref;
2764 0 $jdata = $j->decode( $ENV{DB_OPT} );
2765 }
2766 };
2767 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2768 {
2769 0 warn( "Found the database connection opt parameter provided in the envionment variable DB_OPT, but could not decode its json value: $@\n" );
2770 }
2771 0 ▶ $param->{opt} = $jdata if( scalar( keys( %$jdata ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$jdata 0 0 0
2772 }
2773 3 return( $param );
2774 }
2775  
2776 sub _connection_params2hash_driver
2777 2 ▶{
Subroutine _connection_params2hash_driver: called CC=1 SCAR=0.0
2778 2 my $self = shift( @_ );
2779 2 my $opts = $self->_get_args_as_hash( @_ );
2780 2 return( $opts );
2781 }
2782  
2783 sub _clean_statement
2784 1 ▶{
Subroutine _clean_statement: called CC=3 SCAR=11.2
2785 1 my $self = shift( @_ );
2786 1 my $data = shift( @_ );
2787 1 ▶ my $query = ref( $data ) ? $data : \$data;
Branch: 1 branch
BranchTrueFalseTotal
ref $data ? : 1 0 1
2788 1 $$query = CORE::join( "\n", map{ s/^\s+|\s+$//gs; $_ } split( /\n/, $$query ) );
2789 1 ▶ return( $$query ) if( !ref( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $data 0 1 1
2790 }
2791  
2792 sub _dbi_connect
2793 3 ▶{
Subroutine _dbi_connect: called CC=16 SCAR=36.1
2794 3 my $self = shift( @_ );
2795 3 my $dbh;
2796 3 my $dsn = $self->_dsn;
2797 # print( STDERR ref( $self ) . "::_dbi_connect() Options are: ", $self->dumper( $self->{opt} ), "\n" );
2798 3 my $connect_via = $self->connect_via;
2799 # See: <https://metacpan.org/pod/DBI#Timeout>
2800 # signals to mask in the handler
2801 3 my $mask = POSIX::SigSet->new( POSIX::SIGALRM );
2802 my $action = POSIX::SigAction->new(
2803 # the handler code ref
2804 0 ▶ sub{ die( "connect timeout\n" ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2805 3 $mask,
2806 # not using (perl 5.8.2 and later) 'safe' switch or sa_flags
2807 );
2808 3 my $oldaction = POSIX::SigAction->new();
2809 3 POSIX::sigaction( POSIX::SIGALRM, $action, $oldaction );
2810 3 my $failed;
2811 3 local $@;
2812 eval
2813 3 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { eval { do { alarm 5; if ($self->{"cache_connections"}) { $dbh = "DBI"->connect_cached($dsn, $self->{"login"}, $self->{"passwd"}, $self->{"opt"}, undef(), $connect_via ? $connect_via : ()); } else { $dbh = "DBI"->connect($dsn, $self->{"login"}, $self->{"passwd"}, $self->{"opt"}, undef(), $connect_via ? $connect_via : ()); } ; 1 } } or $failed = 1; alarm 0; die "$@\n" if $failed; 1 } } or $failed = 1 3 0 3
2814 eval
2815 3 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { alarm 5; if ($self->{"cache_connections"}) { $dbh = "DBI"->connect_cached($dsn, $self->{"login"}, $self->{"passwd"}, $self->{"opt"}, undef(), $connect_via ? $connect_via : ()); } else { $dbh = "DBI"->connect($dsn, $self->{"login"}, $self->{"passwd"}, $self->{"opt"}, undef(), $connect_via ? $connect_via : ()); } ; 1 } } or $failed = 1 3 0 3
2816 # seconds before time out
2817 3 alarm(5);
2818 3 ▶ if( $self->{cache_connections} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cache_connections'}) { } 1 2 3
2819 {
2820 $dbh = DBI->connect_cached(
2821 $dsn,
2822 $self->{login},
2823 $self->{passwd},
2824 $self->{opt},
2825 1 ▶ undef(),
Branch: 1 branch
BranchTrueFalseTotal
$connect_via ? : 0 1 1
2826 ( $connect_via ? $connect_via : () ),
2827 );
2828 }
2829 else
2830 {
2831 $dbh = DBI->connect(
2832 $dsn,
2833 $self->{login},
2834 $self->{passwd},
2835 $self->{opt},
2836 2 ▶ undef(),
Branch: 1 branch
BranchTrueFalseTotal
$connect_via ? : 0 2 2
2837 ( $connect_via ? $connect_via : () ),
2838 );
2839 }
2840 3 1;
2841 } or $failed = 1;
2842 # cancel alarm (if connect worked fast)
2843 3 alarm(0);
2844 # connect died
2845 3 ▶ die( "$@\n" ) if( $failed );
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 3 3
2846 3 1;
2847 } or $failed = 1;
2848 # restore original signal handler
2849 3 POSIX::sigaction( POSIX::SIGALRM, $oldaction );
2850 3 ▶ if( defined( $failed ) && $failed )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $failed and $failed) 0 3 3
Condition33%1/3
defined $failed and $failed
!ll&&!rl&&r
300
MC/DC0%0/2
defined $failed and $failed
defined $failed $failed
Truth table33%1/3
A and B
A= defined $failedB= $failed
ABresult
0X0
100
111
2851 {
2852 0 ▶ if( defined( $@ ) && $@ =~ /^connect timeout/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and $@ =~ /^connect timeout/) { } 0 0 0
Condition0%0/3
defined $@ and $@ =~ /^connect timeout/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $@ and $@ =~ /^connect timeout/
defined $@ $@ =~ /^connect timeout/
Truth table0%0/3
A and B
A= defined $@B= $@ =~ /^connect timeout/
ABresult
0X0
100
111
2853 {
2854 0 ▶ return( $self->error( "Connection timed out for dsn '", ( $dsn // 'undef' ), " and login '", ( $self->{login} // 'undef' ), "'" ) );
Condition0%0/4
$dsn // "undef"
l!l
00
$self->{"login"} // "undef"
l!l
00
MC/DC0%0/1
$dsn // "undef"
$dsn
MC/DC0%0/1
$self->{"login"} // "undef"
$self->{"login"}
Truth table0%0/2
A
A= $dsn
Aresult
11
00
Truth table0%0/2
A
A= $self->{"login"}
Aresult
11
00
2855 }
2856 else
2857 {
2858 0 ▶ return( $self->error( "Error connecting with dsn '", ( $dsn // 'undef' ), " and login '", ( $self->{login} // 'undef' ), "': $@" ) );
Condition0%0/4
$dsn // "undef"
l!l
00
$self->{"login"} // "undef"
l!l
00
MC/DC0%0/1
$dsn // "undef"
$dsn
MC/DC0%0/1
$self->{"login"} // "undef"
$self->{"login"}
Truth table0%0/2
A
A= $dsn
Aresult
11
00
Truth table0%0/2
A
A= $self->{"login"}
Aresult
11
00
2859 }
2860 }
2861  
2862 3 ▶ return( $self->error( $DBI::errstr ) ) if( !$dbh );
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh 0 3 3
2863 3 return( $dbh );
2864 }
2865  
2866 sub _decode_json
2867 0 ▶{
Subroutine _decode_json: not called CC=3 SCAR=24.8
2868 0 my $self = shift( @_ );
2869 0 my $json = shift( @_ );
2870 0 ▶ return if( !CORE::length( $json ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $json 0 0 0
2871 0 my $j = JSON->new->allow_nonref;
2872 my $hash = eval
2873 0 {
2874 0 $j->decode( $json );
2875 };
2876 0 ▶ return if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
2877 0 return( $hash );
2878 }
2879  
2880 sub _dsn
2881 0 ▶{
Subroutine _dsn: not called CC=2 SCAR=17.9
2882 0 my $self = shift( @_ );
2883 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
2884 0 die( "Method _dsn is not implemented in class $class\n" );
2885 }
2886  
2887 sub _encode_json
2888 0 ▶{
Subroutine _encode_json: not called CC=6 SCAR=37.4
2889 0 my $self = shift( @_ );
2890 0 ▶ return if( !scalar( @_ ) || ( scalar( @_ ) == 1 && !defined( $_[0] ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not scalar @_ or scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/6
not scalar @_ or scalar @_ == 1 and not defined $_[0]
l!l&&r!l&&!r
000
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/3
not scalar @_ or scalar @_ == 1 and not defined $_[0]
not scalar @_ scalar @_ == 1 not defined $_[0]
Truth table0%0/4
not(A) or B and not(C)
A= not scalar @_B= scalar @_ == 1C= not defined $_[0]
ABCresult
1XX1
0111
00X0
0100
2891 0 my $this = shift( @_ );
2892 0 ▶ return( $self->error( "Value provided is not a hash reference. I was expecting a hash reference to encode data into json." ) ) if( !$self->_is_hash( $this => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($this, "strict") 0 0 0
2893 0 my $j = JSON->new;
2894 my $json = eval
2895 0 {
2896 0 $j->encode( $this );
2897 };
2898 0 ▶ return( $self->error( "An error occurred while trying to encode hash reference provided: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
2899 0 return( $json );
2900 }
2901  
2902 sub _get_cache_filepath
2903 0 ▶{
Subroutine _get_cache_filepath: not called CC=24 SCAR=64.0
2904 0 my $self = shift( @_ );
2905 0 my $opts = $self->_get_args_as_hash( @_ );
2906 0 my $name = $opts->{name};
2907 0 ▶ my $ext = $opts->{extension} // 'bin';
Condition0%0/2
$opts->{"extension"} // "bin"
l!l
00
MC/DC0%0/1
$opts->{"extension"} // "bin"
$opts->{"extension"}
Truth table0%0/2
A
A= $opts->{"extension"}
Aresult
11
00
2908 0 ▶ if( $name !~ /^[\w\-]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^[\w\-]+$/) 0 0 0
2909 {
2910 0 return( $self->error( "The name for this cache file contains illegal characters '$name'. Only alphabetical, numeric characters, underscore, and dash are allowed" ) );
2911 }
2912 0 ▶ my $host = $opts->{host} || $self->host;
Condition0%0/3
$opts->{'host'} || $self->host
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'host'} || $self->host
$opts->{'host'} $self->host
Truth table0%0/3
A || B
A= $opts->{'host'}B= $self->host
ABresult
1X1
011
000
2913 0 ▶ my $database = $opts->{database} || $self->database;
Condition0%0/3
$opts->{'database'} || $self->database
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'database'} || $self->database
$opts->{'database'} $self->database
Truth table0%0/3
A || B
A= $opts->{'database'}B= $self->database
ABresult
1X1
011
000
2914 # May not be specified, and thus empty.
2915 0 my $table = $opts->{table};
2916 0 ▶ if( defined( $host ) && !CORE::length( $host // '' ) )
Branch: 4 branches
BranchTrueFalseTotal
if (defined $host and not length($host // '')) { } 0 0 0
elsif (not defined $database && length($database // '')) { } 0 0 0
elsif (not $database =~ /^\w+$/) { } 0 0 0
elsif ($table and not $table =~ /^\w+[\w\-\.]*$/) { } 0 0 0
Condition0%0/5
defined $host and not length($host // "")
!ll&&!rl&&r
000
$host // ""
l!l
00
MC/DC0%0/2
defined $host and not length($host // "")
defined $host $host
Truth table0%0/3
A and not(B)
A= defined $hostB= $host
ABresult
0X0
110
101
2917 {
2918 0 return( $self->error( "A host name was provided, but is undefined or empty." ) );
2919 }
2920 ▶ elsif( !defined( $database ) || !CORE::length( $database // '' ) )
Condition0%0/5
defined $database && length($database // '')
!ll&&!rl&&r
000
$database // ""
l!l
00
MC/DC0%0/2
defined $database && length($database // '')
defined $database $database
Truth table0%0/3
A && B
A= defined $databaseB= $database
ABresult
0X0
100
111
2921 {
2922 0 return( $self->error( "The database name is undefined or empty." ) );
2923 }
2924 elsif( $database !~ /^\w+$/ )
2925 {
2926 0 return( $self->error( "The database name '$database' contains illegal characters." ) );
2927 }
2928 ▶ elsif( $table && $table !~ /^\w+[\w\-\.]*$/ )
Condition0%0/3
$table and not $table =~ /^\w+[\w\-\.]*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$table and not $table =~ /^\w+[\w\-\.]*$/
$table not $table =~ /^\w+[\w\-\.]*$/
Truth table0%0/3
A and not(B)
A= $tableB= not $table =~ /^\w+[\w\-\.]*$/
ABresult
0X0
100
111
2929 {
2930 0 return( $self->error( "The table name '$table' contains illegal characters." ) );
2931 }
2932  
2933 0 ▶ $host //= '_unknown_';
Condition0%0/2
$host //= "_unknown_"
l!l
00
MC/DC0%0/1
$host //= "_unknown_"
$host
Truth table0%0/2
A
A= $host
Aresult
11
00
2934 # Normalise host for filename usage: keep only [A-Za-z0-9_.-], percent-encode everything else.
2935 # This avoids collisions that would happen with s/\W//g and supports IPv6, ports, etc.
2936 0 my $host_key = "$host";
2937 0 $host_key =~ s/([^A-Za-z0-9_.-])/sprintf( '%%%02X', ord( $1 ) )/ge;
2938  
2939 0 ▶ my $cache_dir = $opts->{cache_dir} || $self->cache_dir ||
Condition0%0/5
$opts->{'cache_dir'} || $self->cache_dir || (return $self->error('No cache directory was provided.'))
l!l
00
$opts->{"cache_dir"} or $self->cache_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'cache_dir'} || $self->cache_dir || (return $self->error('No cache directory was provided.'))
$opts->{"cache_dir"} $self->cache_dir
Truth table0%0/3
A or B
A= $opts->{"cache_dir"}B= $self->cache_dir
ABresult
1X1
011
000
2940 return( $self->error( "No cache directory was provided." ) );
2941 0 ▶ $cache_dir = $self->new_file( $cache_dir ) ||
Condition0%0/2
$self->new_file($cache_dir) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($cache_dir) || (return $self->pass_error)
$self->new_file($cache_dir)
Truth table0%0/2
A
A= $self->new_file($cache_dir)
Aresult
11
00
2942 return( $self->pass_error );
2943 # Ensure cache directory exists
2944 0 ▶ if( !$cache_dir->exists )
Branch: 2 branches
BranchTrueFalseTotal
if (not $cache_dir->exists) { } 0 0 0
elsif (not $cache_dir->is_dir) { } 0 0 0
2945 {
2946 0 ▶ $cache_dir->mkpath || return( $self->pass_error( $cache_dir->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->mkpath or return $self->pass_error($cache_dir->error) 0 0 0
2947 }
2948 elsif( !$cache_dir->is_dir )
2949 {
2950 0 return( $self->error( "Cache directory path '$cache_dir' exists but is not a directory." ) );
2951 }
2952 0 ▶ my @parts = ( ( $opts->{prefix} ? $opts->{prefix} : () ), $host_key, $database );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'prefix'} ? : 0 0 0
2953 0 ▶ push( @parts, $table ) if( $table );
Branch: 1 branch
BranchTrueFalseTotal
if $table 0 0 0
2954 0 push( @parts, "${name}.${ext}" );
2955 0 ▶ my $cache_file = $cache_dir->child( join( '-', @parts ) ) ||
Condition0%0/2
$cache_dir->child(join('-', @parts)) || (return $self->pass_error($cache_dir->error))
l!l
00
MC/DC0%0/1
$cache_dir->child(join('-', @parts)) || (return $self->pass_error($cache_dir->error))
$cache_dir->child(join('-', @parts))
Truth table0%0/2
A
A= $cache_dir->child(join('-', @parts))
Aresult
11
00
2956 return( $self->pass_error( $cache_dir->error ) );
2957 0 return( $cache_file );
2958 }
2959  
2960 sub _make_sth
2961 1 ▶{
Subroutine _make_sth: called CC=8 SCAR=21.5
2962 1 my $self = shift( @_ );
2963 1 my $pkg = shift( @_ );
2964 1 ▶ my $data = shift( @_ ) || {};
Condition50%1/2
shift @_ || {}
l!l
10
MC/DC0%0/1
shift @_ || {}
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
2965 1 my $base_class = $self->base_class;
2966 1 ▶ $self->_load_class( $pkg ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($pkg) or return $self->pass_error 1 0 1
2967 1 foreach my $prop ( qw( table debug bind cache params from_table left_join ) )
2968 {
2969 7 $data->{ $prop } = $self->{ $prop };
2970 }
2971 1 $data->{dbh} = $self->{dbh};
2972 1 ▶ $data->{dbo} = $self->{dbo} ? $self->{dbo} : ref( $self ) eq $self->base_class ? $self : '';
Branch: 2 branches
BranchTrueFalseTotal
$self->{'dbo'} ? : 0 1 1
ref $self eq $self->base_class ? : 1 0 1
2973 # $data->{ 'binded' } = $self->{ 'binded' } if( $self->{ 'binded' } && ref( $self ) ne $base_class );
2974 # In any case suppress the binded parameter from our parent object to avoid polluting the next queries
2975 # If needed, the binded parameter will be rebuilt using the data stored in 'where', 'group', 'order' and 'limit'
2976 # CORE::delete( $self->{ 'binded' } );
2977 # Binded parameters are now either in the DB::Object::Query package or one of its descendant OR passed as arguments to execute
2978 1 $data->{errstr} = '';
2979 1 CORE::delete( $data->{executed} );
2980 1 $data->{query_time} = time();
2981 1 ▶ $data->{selected_fields} = '' if( !exists( $data->{selected_fields} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{"selected_fields"} 1 0 1
2982 1 ▶ $data->{table_object} = $self if( $self->_is_a( $self => "${base_class}::Tables" ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_a($self, "${base_class}::Tables") 0 1 1
2983 1 my $this = bless( $data, $pkg );
2984 1 $this->debug( $self->debug );
2985 1 return( $this );
2986 }
2987  
2988 sub _new_connection_id
2989 2 ▶{
Subroutine _new_connection_id: called CC=2 SCAR=7.1
2990 2 my $self = shift( @_ );
2991 2 ▶ $self->_load_class( 'Time::HiRes' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Time::HiRes") or return $self->pass_error 2 0 2
2992 2 return( sprintf( '%x-%x-%x', $$, int( Time::HiRes::time() * 1_000_000 ), ++$CONNECTION_ID_SEQUENCE ) );
2993 }
2994  
2995 sub _operator_object_create
2996 0 ▶{
Subroutine _operator_object_create: not called CC=4 SCAR=30.0
2997 0 my $self = shift( @_ );
2998 0 ▶ my $class = shift( @_ ) || return( $self->error( "No operator class was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No operator class was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No operator class was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2999 0 my $q = $self->_reset_query;
3000 0 ▶ my $args = ( scalar( @_ ) == 1 && ref( $_[0] ) eq 'ARRAY' ) ? [ @{$_[0]} ] : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && ref $_[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "ARRAY"
scalar @_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
3001 0 return( $class->new(
3002 debug => $self->debug,
3003 query_object => $q,
3004 value => $args,
3005 ) );
3006 }
3007  
3008 sub _param2hash
3009 0 ▶{
Subroutine _param2hash: not called CC=4 SCAR=30.0
3010 0 my $self = shift( @_ );
3011 0 my $opts = {};
3012 0 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 0 0
3013 {
3014 0 ▶ if( $self->_is_hash( $_[0] => 'strict' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_hash($_[0], 'strict')) { } 0 0 0
elsif (not scalar(@_) % 2) { } 0 0 0
3015 {
3016 0 $opts = shift( @_ );
3017 }
3018 elsif( !( scalar( @_ ) % 2 ) )
3019 {
3020 0 $opts = { @_ };
3021 }
3022 else
3023 {
3024 0 return( $self->error( "Uneven number of parameters. I was expecting a hash or a hash reference." ) );
3025 }
3026 }
3027 0 return( $opts );
3028 }
3029  
3030 21 ▶sub _placeholder_regexp { return( $PLACEHOLDER_REGEXP ) }
Subroutine _placeholder_regexp: called CC=1 SCAR=0.0
3031  
3032 # NOTE: _query_object_add needs to reside in DB::Object (called indirectly by no_bind)
3033 sub _query_object_add
3034 0 ▶{
Subroutine _query_object_add: not called CC=3 SCAR=24.8
3035 0 my $self = shift( @_ );
3036 0 ▶ my $obj = shift( @_ ) || return( $self->error( "No query object was provided" ) );
Condition0%0/2
shift @_ || (return $self->error('No query object was provided'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No query object was provided'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
3037 0 my $base = $self->base_class;
3038 0 ▶ return( $self->error( "Object provided is not a query object class" ) ) if( ref( $obj ) !~ /^${base}\::Query$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless ref($obj) =~ /^$base\::Query$/ 0 0 0
3039 0 $self->query_object( $obj );
3040 0 return( $obj );
3041 }
3042  
3043 # NOTE: _query_object_create needs to reside in DB::Object (called indirectly by no_bind)
3044 sub _query_object_create
3045 1 ▶{
Subroutine _query_object_create: called CC=9 SCAR=27.2
3046 1 my $self = shift( @_ );
3047 1 my $base = $self->base_class;
3048 1 my $query_class = "${base}::Query";
3049 1 ▶ $self->_load_class( $query_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($query_class) or return $self->error("Unable to load Query builder module ${query_class}: ", $self->error->message) 1 0 1
3050 return( $self->error( "Unable to load Query builder module $query_class: ", $self->error->message ) );
3051 1 my $o = $query_class->new;
3052 1 $o->debug( $self->debug );
3053 1 ▶ if( $self->isa( "${base}::Tables" ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa("${base}::Tables")) { } 1 0 1
elsif ($self->isa($base)) { } 0 0 0
3054 {
3055 1 ▶ $o->table_object( $self ) || return( $self->pass_error( $o->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$o->table_object($self) or return $self->pass_error($o->error) 1 0 1
3056 # Weaken the back-reference from the Query object to its owning Table to break
3057 # the circular reference cycle (Table -> query_object -> Query -> table_object -> Table)
3058 # that prevents Perl's garbage collector from reclaiming old Query objects.
3059 1 weaken( $o->{table_object} );
3060 1 $o->enhance( $self->database_object->enhance );
3061 1 ▶ $o->database_object( $self->database_object ) || return( $self->pass_error( $o->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$o->database_object($self->database_object) or return $self->pass_error($o->error) 1 0 1
3062 # Also weaken the database_object reference - the dbo is a long-lived singleton
3063 # and does not own Query objects, so a weak reference is safe here.
3064 1 weaken( $o->{database_object} );
3065 # Set the table alias if any has been set
3066 1 ▶ if( my $table_alias = $self->as )
Branch: 1 branch
BranchTrueFalseTotal
if (my $table_alias = $self->as) 0 1 1
3067 {
3068 0 ▶ $o->table_alias( $table_alias ) if( defined( $table_alias ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $table_alias 0 0 0
3069 }
3070 }
3071 elsif( $self->isa( $base ) )
3072 {
3073 0 $o->enhance( $self->enhance );
3074 0 ▶ $o->database_object( $self ) || return( $self->pass_error( $o->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$o->database_object($self) or return $self->pass_error($o->error) 0 0 0
3075 }
3076 1 return( $o );
3077 }
3078  
3079 # NOTE: _query_object_current needs to reside in DB::Object (called indirectly by no_bind)
3080 1 ▶sub _query_object_current { return( shift->{query_object} ); }
Subroutine _query_object_current: called CC=1 SCAR=0.0
3081  
3082 # NOTE: _query_object_get_or_create needs to reside in DB::Object (called indirectly by no_bind)
3083 # If the stack is empty, we create an object, add it and resend it
3084 sub _query_object_get_or_create
3085 1 ▶{
Subroutine _query_object_get_or_create: called CC=5 SCAR=18.7
3086 1 my $self = shift( @_ );
3087 1 my $obj = $self->query_object;
3088 1 ▶ if( $obj && $obj->dirty )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and $obj->dirty) 0 1 1
Condition33%1/3
$obj and $obj->dirty
!ll&&!rl&&r
100
MC/DC0%0/2
$obj and $obj->dirty
$obj $obj->dirty
Truth table33%1/3
A and B
A= $objB= $obj->dirty
ABresult
0X0
100
111
3089 {
3090 0 $self->_query_object_remove( $obj );
3091 0 undef( $obj );
3092 }
3093 1 ▶ if( !$obj )
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 1 0 1
3094 {
3095 1 ▶ $obj = $self->_query_object_create || return( $self->pass_error );
Condition50%1/2
$self->_query_object_create || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->_query_object_create || (return $self->pass_error)
$self->_query_object_create
Truth table50%1/2
A
A= $self->_query_object_create
Aresult
11
00
3096 1 $self->query_object( $obj );
3097 }
3098 1 return( $obj );
3099 }
3100  
3101 # NOTE: _query_object_remove needs to reside in DB::Object (called indirectly by no_bind)
3102 sub _query_object_remove
3103 0 ▶{
Subroutine _query_object_remove: not called CC=3 SCAR=24.8
3104 0 my $self = shift( @_ );
3105 0 ▶ my $obj = shift( @_ ) || return( $self->error( "No query object was provided" ) );
Condition0%0/2
shift @_ || (return $self->error('No query object was provided'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No query object was provided'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
3106 0 my $base = $self->base_class;
3107 # return( $self->error( "Object provided is not a query object class" ) ) if( ref( $obj ) !~ /^${base}\::Query$/ );
3108 0 ▶ return( $self->error( "Object provided is not a query object class" ) ) if( !$obj->isa( "DB::Object::Query" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->isa("DB::Object::Query") 0 0 0
3109 0 $self->query_object( undef );
3110 0 return( $obj );
3111 }
3112  
3113 # NOTE: A query object can be owned by a table object, but also by a database object, such as when instantiating operators like ALL, AND, OR
3114 sub _reset_query
3115 2 ▶{
Subroutine _reset_query: called CC=12 SCAR=36.8
3116 2 my $self = shift( @_ );
3117 2 ▶ if( !$self->{query_reset} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"query_reset"}) 1 1 2
3118 {
3119 1 $self->{query_reset} = 1;
3120 # $self->{enhance} = 1;
3121 1 my $obj = $self->query_object;
3122 # If current query object is dirty, detach it right away.
3123 1 ▶ if( $obj && $obj->dirty )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and $obj->dirty) 0 1 1
Condition33%1/3
$obj and $obj->dirty
!ll&&!rl&&r
100
MC/DC0%0/2
$obj and $obj->dirty
$obj $obj->dirty
Truth table33%1/3
A and B
A= $objB= $obj->dirty
ABresult
0X0
100
111
3124 {
3125 0 $self->_query_object_remove( $obj );
3126 0 undef( $obj );
3127 }
3128  
3129 # Capture join tables BEFORE we detach the query object
3130 1 my $join_tables;
3131 1 ▶ if( $obj )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) 0 1 1
3132 {
3133 0 $join_tables = $obj->join_tables;
3134 }
3135  
3136 1 ▶ $self->_query_object_remove( $obj ) if( $obj );
Branch: 1 branch
BranchTrueFalseTotal
if $obj 0 1 1
3137 1 ▶ if( $join_tables && $join_tables->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($join_tables and $join_tables->length > 0) 0 1 1
Condition33%1/3
$join_tables and $join_tables->length > 0
!ll&&!rl&&r
100
MC/DC0%0/2
$join_tables and $join_tables->length > 0
$join_tables $join_tables->length > 0
Truth table33%1/3
A and B
A= $join_tablesB= $join_tables->length > 0
ABresult
0X0
100
111
3138 {
3139 0 ▶ $join_tables->foreach(sub{
Subroutine __ANON__: not called CC=5 SCAR=34.0
3140 0 my $tbl = shift( @_ );
3141  
3142 0 ▶ return if( $tbl->name eq $self->name );
Branch: 1 branch
BranchTrueFalseTotal
if $tbl->name eq $self->name 0 0 0
3143  
3144 0 my $this_query_object = $tbl->query_object;
3145 0 ▶ $tbl->_query_object_remove( $this_query_object ) if( $this_query_object );
Branch: 1 branch
BranchTrueFalseTotal
if $this_query_object 0 0 0
3146  
3147 0 ▶ $tbl->use_bind(0) unless( $tbl->use_bind > 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless $tbl->use_bind > 1 0 0 0
3148 0 ▶ $tbl->use_cache(0) unless( $tbl->use_cache > 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless $tbl->use_cache > 1 0 0 0
3149  
3150 # Important: do NOT force query_reset to 1 here.
3151 # We want the next use to rebuild a fresh query object lazily.
3152 0 CORE::delete( $tbl->{query_reset} );
3153 0 return;
3154 0 });
3155 }
3156  
3157 1 ▶ $self->{bind} = 0 unless( defined( $self->{bind} ) && $self->{bind} > 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"bind"} and $self->{"bind"} > 1 1 0 1
Condition33%1/3
defined $self->{"bind"} and $self->{"bind"} > 1
!ll&&!rl&&r
100
MC/DC0%0/2
defined $self->{"bind"} and $self->{"bind"} > 1
defined $self->{"bind"} $self->{"bind"} > 1
Truth table33%1/3
A and B
A= defined $self->{"bind"}B= $self->{"bind"} > 1
ABresult
0X0
100
111
3158 1 ▶ $self->{cache} = 0 unless( defined( $self->{cache} ) && $self->{cache} > 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cache"} and $self->{"cache"} > 1 1 0 1
Condition33%1/3
defined $self->{"cache"} and $self->{"cache"} > 1
!ll&&!rl&&r
100
MC/DC0%0/2
defined $self->{"cache"} and $self->{"cache"} > 1
defined $self->{"cache"} $self->{"cache"} > 1
Truth table33%1/3
A and B
A= defined $self->{"cache"}B= $self->{"cache"} > 1
ABresult
0X0
100
111
3159 1 return( $self->_query_object_get_or_create );
3160 }
3161 1 return( $self->_query_object_current );
3162 }
3163  
3164 sub _transaction_finished
3165 1 ▶{
Subroutine _transaction_finished: called CC=3 SCAR=11.2
3166 1 my $self = shift( @_ );
3167 1 $self->{transaction} = 0;
3168 1 ▶ if( $self->{dbh} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dbh"}) 1 0 1
3169 {
3170 1 ▶ $self->{dbh}->{private_db_object} //= {};
Condition50%1/2
$self->{"dbh"}{"private_db_object"} //= {}
l!l
10
MC/DC0%0/1
$self->{"dbh"}{"private_db_object"} //= {}
$self->{"dbh"}{"private_db_object"}
Truth table50%1/2
A
A= $self->{"dbh"}{"private_db_object"}
Aresult
11
00
3171 1 $self->{dbh}->{private_db_object}->{id} = $self->id;
3172 1 $self->{dbh}->{private_db_object}->{transaction} = 0;
3173 }
3174 1 return( $self );
3175 }
3176  
3177 sub _transaction_started
3178 1 ▶{
Subroutine _transaction_started: called CC=3 SCAR=11.2
3179 1 my $self = shift( @_ );
3180 1 $self->{transaction} = 1;
3181 1 ▶ if( $self->{dbh} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dbh"}) 1 0 1
3182 {
3183 1 ▶ $self->{dbh}->{private_db_object} //= {};
Condition50%1/2
$self->{"dbh"}{"private_db_object"} //= {}
l!l
01
MC/DC0%0/1
$self->{"dbh"}{"private_db_object"} //= {}
$self->{"dbh"}{"private_db_object"}
Truth table50%1/2
A
A= $self->{"dbh"}{"private_db_object"}
Aresult
11
00
3184 1 $self->{dbh}->{private_db_object}->{id} = $self->id;
3185 1 $self->{dbh}->{private_db_object}->{transaction} = 1;
3186 }
3187 1 return( $self );
3188 }
3189  
3190 # NOTE: AUTOLOAD
3191 AUTOLOAD
3192 0 ▶{
Subroutine AUTOLOAD: not called CC=51 SCAR=78.0
3193 0 my $self;
3194 0 ▶ $self = shift( @_ ) if( blessed( $_[ 0 ] ) || index( $_[0], '::' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) or index($_[0], "::") != -1 0 0 0
Condition0%0/3
builtin::blessed($_[0]) or index($_[0], "::") != -1
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($_[0]) or index($_[0], "::") != -1
builtin::blessed($_[0]) index($_[0], "::") != -1
Truth table0%0/3
A or B
A= builtin::blessed($_[0])B= index($_[0], "::") != -1
ABresult
1X1
011
000
3195 0 my( $class, $meth );
3196 0 ▶ if( $self )
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 0 0 0
3197 {
3198 0 ▶ $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3199 }
3200 0 $meth = $AUTOLOAD;
3201 0 ▶ if( CORE::index( $meth, '::' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($meth, "::") != -1) 0 0 0
3202 {
3203 0 my $idx = rindex( $meth, '::' );
3204 0 $class = substr( $meth, 0, $idx );
3205 0 $meth = substr( $meth, $idx + 2 );
3206 }
3207 0 my @supported_class = DB::Object->supported_class;
3208 0 push( @supported_class, 'DB::Object' );
3209 0 my $ok_classes = join( '|', @supported_class );
3210 0 my $base_class = ( $class =~ /^($ok_classes)/ )[0];
3211  
3212 # Is it a table object that is being requested?
3213 # if( $self && scalar( grep{ /^$meth$/ } @$tables ) )
3214 # Getting table object take NO argument.
3215 # If the user wants to access a method, and somehow the table name is identical to one of our methods,
3216 # it is likely it will take an argument
3217 0 ▶ if( $class eq $base_class && !scalar( @_ ) && $self->table_exists( $meth ) )
Branch: 4 branches
BranchTrueFalseTotal
if ($class eq $base_class and not scalar @_ and $self->table_exists($meth)) { } 0 0 0
elsif ($self and $self->can($meth) and defined &{"${class}::$meth";}) { } 0 0 0
elsif (defined &$meth) { } 0 0 0
elsif ($class =~ /^(?:$ok_classes)$/) { } 0 0 0
Condition0%0/6
$class eq $base_class and not scalar @_ and $self->table_exists($meth)
!ll&&!rl&&r
000
$class eq $base_class and not scalar @_
!ll&&!rl&&r
000
MC/DC0%0/3
$class eq $base_class and not scalar @_ and $self->table_exists($meth)
$class eq $base_class not scalar @_ $self->table_exists($meth)
Truth table0%0/4
A and not(B) and C
A= $class eq $base_classB= not scalar @_C= $self->table_exists($meth)
ABCresult
0XX0
10X0
1100
1111
3218 {
3219 0 return( $self->table( $meth ) );
3220 }
3221 0 ▶ elsif( $self && $self->can( $meth ) && defined( &{ "$class\::$meth" } ) )
Condition0%0/6
$self and $self->can($meth) and defined &{"${class}::$meth";}
!ll&&!rl&&r
000
$self and $self->can($meth)
!ll&&!rl&&r
000
MC/DC0%0/3
$self and $self->can($meth) and defined &{"${class}::$meth";}
$self $self->can($meth) defined &{"${class}::$meth";}
Truth table0%0/4
A and B and C
A= $selfB= $self->can($meth)C= defined &{"${class}::$meth";}
ABCresult
0XX0
10X0
1100
1111
3222 {
3223 0 return( $self->$meth( @_ ) );
3224 }
3225 # For imported subs
3226 elsif( defined( &$meth ) )
3227 {
3228 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3229 0 *{"${class}\::${meth}"} = \&$meth;
3230 0 ▶ unshift( @_, $self ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
3231 0 return( &$meth( @_ ) );
3232 }
3233 # Taken from AutoLoader.pm
3234 elsif( $class =~ /^(?:$ok_classes)$/ )
3235 {
3236 0 my $filename;
3237 0 my $pkg = $class;
3238 0 $pkg =~ s/::/\//g;
3239 0 ▶ if( defined( $filename = $INC{ "$pkg.pm" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($filename = $INC{"$pkg.pm"})) 0 0 0
3240 {
3241 0 $filename =~ s%^(.*)$pkg\.pm\z%$1auto/${pkg}/${meth}.al%s;
3242 0 ▶ if( -r( $filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-r $filename) { } 0 0 0
3243 {
3244 0 ▶ unless( $filename =~ m|^/|s )
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ m[^/]s) 0 0 0
3245 {
3246 0 $filename = "./$filename";
3247 }
3248 }
3249 else
3250 {
3251 0 $filename = undef();
3252 }
3253 }
3254 0 ▶ if( !defined( $filename ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
3255 {
3256 0 $filename = "auto/${meth}.al";
3257 0 $filename =~ s/::/\//g;
3258 }
3259 0 my $save = $@;
3260 eval
3261 0 {
3262 0 ▶ local $SIG{__DIE__} = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3263 0 ▶ local $SIG{__WARN__} = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3264 0 require $filename;
3265 };
3266 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3267 {
3268 0 ▶ if( substr( $AUTOLOAD, -9 ) eq '::DESTROY' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($DB::Object::AUTOLOAD, -9) eq '::DESTROY') { } 0 0 0
3269 {
3270 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3271 0 ▶ *$meth = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
3272 }
3273 else
3274 {
3275 # The load might just have failed because the filename was too
3276 # long for some old SVR3 systems which treat long names as errors.
3277 # If we can succesfully truncate a long name then it's worth a go.
3278 # There is a slight risk that we could pick up the wrong file here
3279 # but autosplit should have warned about that when splitting.
3280 0 ▶ if( $filename =~ s/(\w{12,})\.al$/substr( $1, 0, 11 ) . ".al"/e )
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ s/(\w{12,})\.al$/substr($1, 0, 11) . '.al';/e) 0 0 0
3281 {
3282 eval
3283 0 {
3284 0 ▶ local $SIG{__DIE__} = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3285 0 ▶ local $SIG{__WARN__} = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3286 0 require $filename
3287 };
3288 }
3289 }
3290 }
3291 0 ▶ unless( $@ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
3292 {
3293 0 $@ = $save;
3294 0 ▶ unshift( @_, $self ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
3295 0 goto &$meth;
3296 }
3297 0 $@ = $save;
3298 }
3299  
3300 0 ▶ if( $self && exists( $self->{sth} ) )
Branch: 4 branches
BranchTrueFalseTotal
if ($self and exists $self->{'sth'}) { } 0 0 0
elsif ($self and $self->{'dbh'} && $self->{'dbh'}->can($meth) || defined &{'DBI::db::' . $meth;}) { } 0 0 0
elsif ($self and $self->{'dbh'} and exists $self->{'dbh'}{$meth}) { } 0 0 0
elsif (defined &{'DBI::' . $meth;}) { } 0 0 0
Condition0%0/3
$self and exists $self->{"sth"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self and exists $self->{"sth"}
$self exists $self->{"sth"}
Truth table0%0/3
A and B
A= $selfB= exists $self->{"sth"}
ABresult
0X0
100
111
3301 {
3302 # e.g. $sth->pg_server_prepare => $self->{sth}->{pg_server_prepare}
3303 0 ▶ if( CORE::exists( $self->{sth}->{ $meth } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"sth"}{$meth}) 0 0 0
3304 {
3305 0 ▶ $self->{sth}->{ $meth } = shift( @_ ) if( scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
3306 0 return( $self->{sth}->{ $meth } );
3307 }
3308 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
3309 {
3310 0 ▶ $self->execute() || return( $self->error( $self->{sth}->errstr() ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->error($self->{"sth"}->errstr) 0 0 0
3311 }
3312 # $self->_cleanup();
3313 # print( STDERR "Calling DBI method $meth with sth '$self->{sth}' arguments: '", join( "', '", @_ ), "'\n" ) if( $DEBUG );
3314 # *{ "${class}\::$meth" } = sub{ return( shift->{ 'sth' }->$meth( @_ ) ); };
3315 # return( $self->{sth}->$meth( @_ ) );
3316 0 my $ctx = Wanted::context();
3317 0 ▶ if( $ctx eq 'LIST' )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx eq 'LIST') { } 0 0 0
3318 {
3319 0 local $@;
3320 0 my @rv = eval{ $self->{sth}->$meth( @_ ); };
3321 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not scalar @rv and $self->{'sth'}->err) { } 0 0 0
3322 {
3323 # We set the error
3324 0 $self->error( "Error calling $meth: $@" );
3325 }
3326 # From DBI documentation:
3327 # "If there are no more rows or if an error occurs, then fetchrow_array returns an empty list. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the empty list returned was due to an error."
3328 # Also: <https://metacpan.org/pod/DBI#errstr>
3329 ▶ elsif( !scalar( @rv ) && $self->{sth}->err )
Condition0%0/3
not scalar @rv and $self->{"sth"}->err
!ll&&!rl&&r
000
MC/DC0%0/2
not scalar @rv and $self->{"sth"}->err
not scalar @rv $self->{"sth"}->err
Truth table0%0/3
not(A) and B
A= not scalar @rvB= $self->{"sth"}->err
ABresult
0X0
100
111
3330 {
3331 0 $self->error({ code => $self->{sth}->err, message => $self->{sth}->errstr });
3332 }
3333 # We still return whatever was retrieved
3334 0 return( @rv );
3335 }
3336 else
3337 {
3338 0 local $@;
3339 0 my $rv = eval{ $self->{sth}->$meth( @_ ); };
3340 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->{'sth'}->err) { } 0 0 0
3341 {
3342 # We set the error
3343 0 $self->error( "Error calling $meth: $@" );
3344 }
3345 # From DBI documentation:
3346 # "If there are no more rows or if an error occurs, then fetchrow_array returns an empty list. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the empty list returned was due to an error."
3347 # Also: <https://metacpan.org/pod/DBI#errstr>
3348 ▶ elsif( !defined( $rv ) && $self->{sth}->err )
Condition0%0/3
not defined $rv and $self->{"sth"}->err
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $rv and $self->{"sth"}->err
not defined $rv $self->{"sth"}->err
Truth table0%0/3
not(A) and B
A= not defined $rvB= $self->{"sth"}->err
ABresult
0X0
100
111
3349 {
3350 0 $self->error({ code => $self->{sth}->err, message => $self->{sth}->errstr });
3351 }
3352  
3353 # We check if the user is asking for chaining, but the returned value is undef.
3354 # We want to avoid the famous Perl error: "Can't call method "%s" on an undefined value"
3355 # See perldiag man page.
3356 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rv) 0 0 0
3357 {
3358 # $ctx returns also CODE, HASH, ARRAY, GLOB, SCALAR or OBJECT
3359 0 ▶ if( $ctx eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx eq 'HASH') { } 0 0 0
elsif ($ctx eq 'ARRAY') { } 0 0 0
3360 {
3361 0 return( {} );
3362 }
3363 elsif( $ctx eq 'ARRAY' )
3364 {
3365 0 return( [] );
3366 }
3367 }
3368 0 return( $rv );
3369 }
3370 }
3371 # e.g. $dbh->pg_notifies
3372 0 ▶ elsif( $self && ( ( $self->{dbh} && $self->{dbh}->can( $meth ) ) || defined( &{ "DBI::db::" . $meth } ) ) )
Condition0%0/9
$self and $self->{"dbh"} && $self->{"dbh"}->can($meth) || defined &{'DBI::db::' . $meth;}
!ll&&!rl&&r
000
$self->{"dbh"} and $self->{"dbh"}->can($meth) or defined &{'DBI::db::' . $meth;}
l!l&&r!l&&!r
000
$self->{"dbh"} and $self->{"dbh"}->can($meth)
!ll&&!rl&&r
000
MC/DC0%0/4
$self and $self->{"dbh"} && $self->{"dbh"}->can($meth) || defined &{'DBI::db::' . $meth;}
$self $self->{"dbh"} $self->{"dbh"}->can($meth) defined &{'DBI::db::' . $meth;}
Truth table0%0/6
A and B and C or D
A= $selfB= $self->{"dbh"}C= $self->{"dbh"}->can($meth)D= defined &{'DBI::db::' . $meth;}
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
3373 {
3374 0 return( $self->{dbh}->$meth( @_ ) );
3375 }
3376 # e.g. $dbh->pg_enable_utf8 becomes $self->{dbh}->{pg_enable_utf8]
3377 ▶ elsif( $self && $self->{dbh} && CORE::exists( $self->{dbh}->{ $meth } ) )
Condition0%0/6
$self and $self->{"dbh"} and exists $self->{"dbh"}{$meth}
!ll&&!rl&&r
000
$self and $self->{"dbh"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self and $self->{"dbh"} and exists $self->{"dbh"}{$meth}
$self $self->{"dbh"} exists $self->{"dbh"}{$meth}
Truth table0%0/4
A and B and C
A= $selfB= $self->{"dbh"}C= exists $self->{"dbh"}{$meth}
ABCresult
0XX0
10X0
1100
1111
3378 {
3379 0 ▶ $self->{dbh}->{ $meth } = shift( @_ ) if( scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
3380 0 return( $self->{dbh}->{ $meth } );
3381 }
3382 0 elsif( defined( &{ "DBI::" . $meth } ) )
3383 {
3384 0 my $h = &{ "DBI::" . $meth }( @_ );
3385 0 ▶ if( defined( $h ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h) { } 0 0 0
3386 {
3387 0 bless( $h, $class );
3388 0 return( $h );
3389 }
3390 else
3391 {
3392 0 return;
3393 }
3394 }
3395 0 ▶ my $what = $self ? $self : $class;
Branch: 1 branch
BranchTrueFalseTotal
$self ? : 0 0 0
3396 0 return( $what->error( "${class}::AUTOLOAD: Not defined in $class and not autoloadable (last try $meth)" ) );
3397 }
3398  
3399 # NOTE: DESTROY
3400 sub DESTROY
3401 24 ▶{
Subroutine DESTROY: called CC=12 SCAR=34.9
3402 # <https://perldoc.perl.org/perlobj#Destructors>
3403 24 CORE::local( $., $@, $!, $^E, $? );
3404 24 ▶ CORE::return if( ${^GLOBAL_PHASE} eq 'DESTRUCT' );
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 24 24
3405 24 my $self = CORE::shift( @_ );
3406 24 ▶ CORE::return if( !CORE::defined( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 24 24
3407 24 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
2400
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3408 24 ▶ if( $self->{sth} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'sth'}) { } 0 24 24
elsif ($self->{'dbh'} and $class =~ /^DB\:\:Object(?:\:\:(?:Postgres|Mysql|SQLite))?$/) { } 0 48 48
3409 {
3410 0 ▶ print( STDERR "DESTROY(): Terminating sth '$self' for query:\n$self->{query}\n" ) if( $DEBUG || $self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $DB::Object::DEBUG or $self->{"debug"} 0 0 0
Condition0%0/3
$DB::Object::DEBUG or $self->{"debug"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$DB::Object::DEBUG or $self->{"debug"}
$DB::Object::DEBUG $self->{"debug"}
Truth table0%0/3
A or B
A= $DB::Object::DEBUGB= $self->{"debug"}
ABresult
1X1
011
000
3411 0 $self->{sth}->finish();
3412 }
3413 ▶ elsif( $self->{dbh} && $class =~ /^DB\:\:Object(?:\:\:(?:Postgres|Mysql|SQLite))?$/ )
Condition33%1/3
$self->{"dbh"} and $class =~ /^DB\:\:Object(?:\:\:(?:Postgres|Mysql|SQLite))?$/
!ll&&!rl&&r
2400
MC/DC0%0/2
$self->{"dbh"} and $class =~ /^DB\:\:Object(?:\:\:(?:Postgres|Mysql|SQLite))?$/
$self->{"dbh"} $class =~ /^DB\:\:Object(?:\:\:(?:Postgres|Mysql|SQLite))?$/
Truth table33%1/3
A and B
A= $self->{"dbh"}B= $class =~ /^DB\:\:Object(?:\:\:(?:Postgres|Mysql|SQLite))?$/
ABresult
0X0
100
111
3414 {
3415 0 ▶ local( $SIG{__WARN__} ) = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
3416 # $self->{ 'dbh' }->disconnect();
3417 0 $self->disconnect();
3418 }
3419 24 my $locks = $self->{_locks};
3420 24 ▶ if( $locks && $self->_is_array( $locks ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($locks and $self->_is_array($locks)) 0 24 24
Condition33%1/3
$locks and $self->_is_array($locks)
!ll&&!rl&&r
2400
MC/DC0%0/2
$locks and $self->_is_array($locks)
$locks $self->_is_array($locks)
Truth table33%1/3
A and B
A= $locksB= $self->_is_array($locks)
ABresult
0X0
100
111
3421 {
3422 0 foreach my $name ( @$locks )
3423 {
3424 0 $self->unlock( $name );
3425 }
3426 }
3427  
3428 24 my $repo = Module::Generic::Global->new( 'available_databases' => $class, key => $class );
3429 24 $repo->cleanup;
3430 24 my $table_repo = Module::Generic::Global->new( table_cache => 'system' );
3431 24 $table_repo->cleanup;
3432 # NOTE: We cannot cleanup here the 'queries_cache, because we need the $cache_key used to build the key, and we do not have it at this very moment.
3433 }
3434  
3435 # NOTE: package DB::Object::Operator
3436 package DB::Object::Operator;
3437 BEGIN
3438 {
3439 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3440 8 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
3441 };
3442  
3443 sub init
3444 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
3445 0 my $self = shift( @_ );
3446 0 $self->{operator} = undef;
3447 0 $self->{query_object} = undef;
3448 0 $self->{value} = [];
3449 0 $self->{_init_strict_use_sub} = 1;
3450 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
3451 0 return( $self );
3452 }
3453  
3454 0 ▶sub operator { return( '' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3455  
3456 0 ▶sub query_object { return( shift->_set_get_object_without_init( 'query_object', 'DB::Object::Query', @_ ) ); }
Subroutine query_object: not called CC=1 SCAR=6.9
3457  
3458 # sub value { return( wantarray() ? @{$_[0]->{value}} : $_[0]->{value} ); }
3459 # wantlist option instructs this method to return a list in list context instead of the default array object
3460 0 ▶sub value { return( shift->_set_get_array_as_object( { field => 'value', wantlist => 1 }, @_ ) ); }
Subroutine value: not called CC=1 SCAR=6.9
3461  
3462 # For arguments that have a query object like statements, we coy their binded_types and binded_values to our current query object.
3463 # This is used by ALL, ANY and IN
3464 sub _copy_binded_elements
3465 0 ▶{
Subroutine _copy_binded_elements: not called CC=2 SCAR=17.9
3466 0 my $self = shift( @_ );
3467 0 my $base_class = $self->base_class;
3468 0 ▶ if( my $qo = $self->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $qo = $self->query_object) 0 0 0
3469 {
3470 $self->value->foreach(sub
3471 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3472 0 my $this = shift( @_ );
3473 0 my $q;
3474 0 ▶ if( $self->_is_a( $this => "${base_class}::Statement" ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($this, "${base_class}::Statement") and $q = $this->query_object) 0 0 0
Condition0%0/3
$self->_is_a($this, "${base_class}::Statement") and $q = $this->query_object
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_a($this, "${base_class}::Statement") and $q = $this->query_object
$self->_is_a($this, "${base_class}::Statement") $q = $this->query_object
Truth table0%0/3
A and B
A= $self->_is_a($this, "${base_class}::Statement")B= $q = $this->query_object
ABresult
0X0
100
111
3475 ( $q = $this->query_object ) )
3476 {
3477 0 $qo->binded_types->push( $q->binded_types->list );
3478 0 $qo->binded_values->push( $q->binded_values->list );
3479 }
3480 0 });
3481 }
3482 0 return( $self );
3483 }
3484  
3485 # Ref:
3486 # <https://www.postgresql.org/docs/12/arrays.html#ARRAYS-SEARCHING>
3487 # NOTE: package DB::Object::ALL
3488 package DB::Object::ALL;
3489 BEGIN
3490 {
3491 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3492 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3493 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
3494 8 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3495 8 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=1.2
3496 '""' => 'as_string',
3497 0 ▶ 'bool' => sub{1},
Subroutine __ANON__: not called CC=1 SCAR=6.9
3498 0 ▶ '==' => sub{ &_opt_overload( @_, '==' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3499 0 ▶ '!=' => sub{ &_opt_overload( @_, '!=' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3500 8 ▶ fallback => 1,
Subroutine BEGIN: not called CC=1 SCAR=0.0
3501 8 );
3502 };
3503  
3504 sub init
3505 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
3506 0 my $self = shift( @_ );
3507 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
3508 # $self->_copy_binded_elements || return( $self->pass_error );
3509 0 return( $self );
3510 }
3511  
3512 sub as_string
3513 0 ▶{
Subroutine as_string: not called CC=5 SCAR=34.0
3514 0 my $self = shift( @_ );
3515 0 my $vals = $self->value;
3516 0 my @list = ();
3517 0 foreach my $elem ( @$vals )
3518 {
3519 0 ▶ next unless( defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
3520 0 ▶ if( Scalar::Util::blessed( $elem ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($elem) and $elem->isa('DB::Object::Statement')) { } 0 0 0
Condition0%0/3
builtin::blessed($elem) and $elem->isa("DB::Object::Statement")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($elem) and $elem->isa("DB::Object::Statement")
builtin::blessed($elem) $elem->isa("DB::Object::Statement")
Truth table0%0/3
A and B
A= builtin::blessed($elem)B= $elem->isa("DB::Object::Statement")
ABresult
0X0
100
111
3521 $elem->isa( 'DB::Object::Statement' ) )
3522 {
3523 0 push( @list, $elem->as_string );
3524 }
3525 else
3526 {
3527 0 push( @list, $elem );
3528 }
3529 }
3530 0 local $" = ',';
3531 0 my $sql = "ALL (@list)";
3532 0 return( $sql );
3533 }
3534  
3535 0 ▶sub operator { return( 'ALL' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3536  
3537 sub _opt_overload
3538 0 ▶{
Subroutine _opt_overload: not called CC=6 SCAR=37.4
3539 0 my( $self, $val, $swap, $op ) = @_;
3540 0 my $map =
3541 {
3542 '!=' => '!= ',
3543 '<>' => '!= ',
3544 '==' => '= ',
3545 };
3546 0 my $not = $map->{ $op };
3547 0 ▶ if( !defined( $not ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $not) 0 0 0
3548 {
3549 0 warn( "Unknown operator '${op}'. Falling back to '='." );
3550 0 $not = $map->{ '==' };
3551 }
3552 0 my $in = $self->as_string;
3553 0 my $placeholder_re = $self->query_object->database_object->_placeholder_regexp;
3554 0 ▶ my $lval = ( Scalar::Util::blessed( $val ) && $val->isa( 'DB::Object::Fields::Field' ) )
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($val) && $val->isa('DB::Object::Fields::Field') ? : 0 0 0
$val =~ /$placeholder_re/ || $self->_is_number($val) ? : 0 0 0
Condition0%0/6
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
!ll&&!rl&&r
000
$val =~ /$placeholder_re/ or $self->_is_number($val)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
builtin::blessed($val) $val->isa("DB::Object::Fields::Field")
MC/DC0%0/2
$val =~ /$placeholder_re/ or $self->_is_number($val)
$val =~ /$placeholder_re/ $self->_is_number($val)
Truth table0%0/3
A and B
A= builtin::blessed($val)B= $val->isa("DB::Object::Fields::Field")
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $val =~ /$placeholder_re/B= $self->_is_number($val)
ABresult
1X1
011
000
3555 ? $val->name
3556 : ( $val =~ $placeholder_re || $self->_is_number( $val ) )
3557 ? $val
3558 : qq{'${val}'};
3559 0 return( DB::Object::Expression->new( "${lval} ${not}${in}" ) );
3560 }
3561  
3562 # NOTE: package DB::Object::AND
3563 package DB::Object::AND;
3564 BEGIN
3565 {
3566 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3567 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
3568 };
3569  
3570 0 ▶sub operator { return( 'AND' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3571  
3572 # Ref:
3573 # <https://www.postgresql.org/docs/12/arrays.html#ARRAYS-SEARCHING>
3574 # NOTE: package DB::Object::ANY
3575 package DB::Object::ANY;
3576 BEGIN
3577 {
3578 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3579 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3580 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
3581 8 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3582 8 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=1.2
3583 '""' => 'as_string',
3584 0 ▶ 'bool' => sub{1},
Subroutine __ANON__: not called CC=1 SCAR=6.9
3585 0 ▶ '==' => sub{ &_opt_overload( @_, '==' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3586 0 ▶ '!=' => sub{ &_opt_overload( @_, '!=' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3587 8 ▶ fallback => 1,
Subroutine BEGIN: not called CC=1 SCAR=0.0
3588 8 );
3589 };
3590  
3591 sub init
3592 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
3593 0 my $self = shift( @_ );
3594 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
3595 # $self->_copy_binded_elements || return( $self->pass_error );
3596 0 return( $self );
3597 }
3598  
3599 sub as_string
3600 0 ▶{
Subroutine as_string: not called CC=5 SCAR=34.0
3601 0 my $self = shift( @_ );
3602 0 my $vals = $self->value;
3603 0 my @list = ();
3604 0 foreach my $elem ( @$vals )
3605 {
3606 0 ▶ next unless( defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
3607 0 ▶ if( Scalar::Util::blessed( $elem ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($elem) and $elem->isa('DB::Object::Statement')) { } 0 0 0
Condition0%0/3
builtin::blessed($elem) and $elem->isa("DB::Object::Statement")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($elem) and $elem->isa("DB::Object::Statement")
builtin::blessed($elem) $elem->isa("DB::Object::Statement")
Truth table0%0/3
A and B
A= builtin::blessed($elem)B= $elem->isa("DB::Object::Statement")
ABresult
0X0
100
111
3608 $elem->isa( 'DB::Object::Statement' ) )
3609 {
3610 0 push( @list, $elem->as_string );
3611 }
3612 else
3613 {
3614 0 push( @list, $elem );
3615 }
3616 }
3617 0 local $" = ',';
3618 0 my $sql = "ANY (@list)";
3619 0 return( $sql );
3620 }
3621  
3622 0 ▶sub operator { return( 'ANY' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3623  
3624 sub _opt_overload
3625 0 ▶{
Subroutine _opt_overload: not called CC=6 SCAR=37.4
3626 0 my( $self, $val, $swap, $op ) = @_;
3627 0 my $map =
3628 {
3629 '!=' => '!= ',
3630 '==' => '= ',
3631 };
3632 0 my $not = $map->{ $op };
3633 0 ▶ if( !defined( $not ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $not) 0 0 0
3634 {
3635 0 warn( "Unknown operator '${op}'. Falling back to '='." );
3636 0 $not = $map->{ '==' };
3637 }
3638 0 my $in = $self->as_string;
3639 0 my $placeholder_re = $self->query_object->database_object->_placeholder_regexp;
3640 0 ▶ my $lval = ( Scalar::Util::blessed( $val ) && $val->isa( 'DB::Object::Fields::Field' ) )
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($val) && $val->isa('DB::Object::Fields::Field') ? : 0 0 0
$val =~ /$placeholder_re/ || $self->_is_number($val) ? : 0 0 0
Condition0%0/6
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
!ll&&!rl&&r
000
$val =~ /$placeholder_re/ or $self->_is_number($val)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
builtin::blessed($val) $val->isa("DB::Object::Fields::Field")
MC/DC0%0/2
$val =~ /$placeholder_re/ or $self->_is_number($val)
$val =~ /$placeholder_re/ $self->_is_number($val)
Truth table0%0/3
A and B
A= builtin::blessed($val)B= $val->isa("DB::Object::Fields::Field")
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $val =~ /$placeholder_re/B= $self->_is_number($val)
ABresult
1X1
011
000
3641 ? $val->name
3642 : ( $val =~ $placeholder_re || $self->_is_number( $val ) )
3643 ? $val
3644 : qq{'${val}'};
3645 0 return( DB::Object::Expression->new( "${lval} ${not}${in}" ) );
3646 }
3647  
3648 # NOTE: package DB::Object::Expression
3649 package DB::Object::Expression;
3650 BEGIN
3651 {
3652 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3653 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3654 8 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
3655 '""' => 'as_string',
3656 0 ▶ 'bool' => sub{1},
Subroutine __ANON__: not called CC=1 SCAR=6.9
3657 8 ▶ fallback => 1,
Subroutine BEGIN: not called CC=1 SCAR=0.0
3658 8 );
3659 };
3660  
3661 sub new
3662 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
3663 0 my $that = shift( @_ );
3664 0 ▶ my $val = ( scalar( @_ ) == 1 && ref( $_[0] ) eq 'ARRAY' ) ? [ @{$_[0]} ] : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && ref $_[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "ARRAY"
scalar @_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
3665 0 ▶ return( bless( { value => $val } => ( ref( $that ) || $that ) ) );
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
3666 }
3667  
3668 sub as_string
3669 0 ▶{
Subroutine as_string: not called CC=1 SCAR=6.9
3670 0 my $self = shift( @_ );
3671 0 my $vals = $self->components;
3672 0 return( join( ' ', @$vals ) );
3673 }
3674  
3675 0 ▶sub components { return( wantarray() ? @{$_[0]->{value}} : $_[0]->{value} ); }
Subroutine components: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
3676  
3677  
3678 # Ref:
3679 # <https://www.postgresql.org/docs/12/functions-subquery.html#FUNCTIONS-SUBQUERY-IN>
3680 # <https://www.postgresql.org/docs/12/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR>
3681 # <https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_in>
3682 # <https://www.sqlite.org/lang_expr.html#the_in_and_not_in_operators>
3683 # NOTE: package DB::Object::IN
3684 package DB::Object::IN;
3685 BEGIN
3686 {
3687 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3688 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3689 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
3690 8 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3691 8 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=1.2
3692 '""' => 'as_string',
3693 0 ▶ 'bool' => sub{1},
Subroutine __ANON__: not called CC=1 SCAR=6.9
3694 0 ▶ '==' => sub{ &_opt_overload( @_, '==' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3695 0 ▶ '!=' => sub{ &_opt_overload( @_, '!=' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3696 8 ▶ fallback => 1,
Subroutine BEGIN: not called CC=1 SCAR=0.0
3697 8 );
3698 };
3699  
3700 sub init
3701 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
3702 0 my $self = shift( @_ );
3703 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
3704 # $self->_copy_binded_elements || return( $self->pass_error );
3705 0 return( $self );
3706 }
3707  
3708 sub as_string
3709 0 ▶{
Subroutine as_string: not called CC=5 SCAR=34.0
3710 0 my $self = shift( @_ );
3711 0 my $vals = $self->value;
3712 0 my @list = ();
3713 0 foreach my $elem ( @$vals )
3714 {
3715 0 ▶ next unless( defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
3716 0 ▶ if( Scalar::Util::blessed( $elem ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($elem) and $elem->isa('DB::Object::Statement')) { } 0 0 0
Condition0%0/3
builtin::blessed($elem) and $elem->isa("DB::Object::Statement")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($elem) and $elem->isa("DB::Object::Statement")
builtin::blessed($elem) $elem->isa("DB::Object::Statement")
Truth table0%0/3
A and B
A= builtin::blessed($elem)B= $elem->isa("DB::Object::Statement")
ABresult
0X0
100
111
3717 $elem->isa( 'DB::Object::Statement' ) )
3718 {
3719 0 push( @list, $elem->as_string );
3720 }
3721 else
3722 {
3723 0 push( @list, $elem );
3724 }
3725 }
3726 0 local $" = ',';
3727 0 my $sql = "IN (@list)";
3728 0 return( $sql );
3729 }
3730  
3731 0 ▶sub operator { return( 'IN' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3732  
3733 sub _opt_overload
3734 0 ▶{
Subroutine _opt_overload: not called CC=6 SCAR=37.4
3735 0 my( $self, $val, $swap, $op ) = @_;
3736 0 my $map =
3737 {
3738 '!=' => 'NOT ',
3739 '<>' => 'NOT ',
3740 '==' => '',
3741 };
3742 0 ▶ my $not = $map->{ $op } // '';
Condition0%0/2
$map->{$op} // ""
l!l
00
MC/DC0%0/1
$map->{$op} // ""
$map->{$op}
Truth table0%0/2
A
A= $map->{$op}
Aresult
11
00
3743 0 my $in = $self->as_string;
3744 0 my $placeholder_re = $self->query_object->database_object->_placeholder_regexp;
3745 0 ▶ my $lval = ( Scalar::Util::blessed( $val ) && $val->isa( 'DB::Object::Fields::Field' ) )
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($val) && $val->isa('DB::Object::Fields::Field') ? : 0 0 0
$val =~ /$placeholder_re/ || $self->_is_number($val) ? : 0 0 0
Condition0%0/6
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
!ll&&!rl&&r
000
$val =~ /$placeholder_re/ or $self->_is_number($val)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
builtin::blessed($val) $val->isa("DB::Object::Fields::Field")
MC/DC0%0/2
$val =~ /$placeholder_re/ or $self->_is_number($val)
$val =~ /$placeholder_re/ $self->_is_number($val)
Truth table0%0/3
A and B
A= builtin::blessed($val)B= $val->isa("DB::Object::Fields::Field")
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $val =~ /$placeholder_re/B= $self->_is_number($val)
ABresult
1X1
011
000
3746 ? $val->name
3747 : ( $val =~ $placeholder_re || $self->_is_number( $val ) )
3748 ? $val
3749 : qq{'${val}'};
3750 0 return( DB::Object::Expression->new( "${lval} ${not}${in}" ) );
3751 }
3752  
3753 # Ref:
3754 # <https://www.postgresql.org/docs/current/functions-matching.html>
3755 # <https://dev.mysql.com/doc/refman/8.4/en/pattern-matching.html>
3756 # <https://www.sqlite.org/lang_corefunc.html#like>
3757 # <https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators>
3758 # NOTE: package DB::Object::LIKE
3759 # TODO: Finish the class DB::Object::LIKE
3760 package DB::Object::LIKE;
3761 BEGIN
3762 {
3763 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3764 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3765 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
3766 8 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3767 8 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=1.2
3768 '""' => 'as_string',
3769 0 ▶ 'bool' => sub{1},
Subroutine __ANON__: not called CC=1 SCAR=6.9
3770 0 ▶ '==' => sub{ &_opt_overload( @_, '==' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3771 0 ▶ '!=' => sub{ &_opt_overload( @_, '!=' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3772 8 ▶ fallback => 1,
Subroutine BEGIN: not called CC=1 SCAR=0.0
3773 8 );
3774 };
3775  
3776 sub init
3777 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
3778 0 my $self = shift( @_ );
3779 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
3780 # $self->_copy_binded_elements || return( $self->pass_error );
3781 0 return( $self );
3782 }
3783  
3784 sub as_string
3785 0 ▶{
Subroutine as_string: not called CC=1 SCAR=6.9
3786 0 my $self = shift( @_ );
3787 0 my $vals = $self->value;
3788 # Parameters can be given as an array for convenience, and they will concatenated
3789 0 my $sql = "LIKE '" . join( '', @$vals ) . "'";
3790 0 return( $sql );
3791 }
3792  
3793 sub _opt_overload
3794 0 ▶{
Subroutine _opt_overload: not called CC=6 SCAR=37.4
3795 0 my( $self, $val, $swap, $op ) = @_;
3796 0 my $map =
3797 {
3798 '!=' => 'NOT ',
3799 '<>' => 'NOT ',
3800 '==' => '',
3801 };
3802 0 ▶ my $not = $map->{ $op } // '';
Condition0%0/2
$map->{$op} // ""
l!l
00
MC/DC0%0/1
$map->{$op} // ""
$map->{$op}
Truth table0%0/2
A
A= $map->{$op}
Aresult
11
00
3803 0 my $like = $self->as_string;
3804 0 my $placeholder_re = $self->query_object->database_object->_placeholder_regexp;
3805 0 ▶ my $lval = ( Scalar::Util::blessed( $val ) && $val->isa( 'DB::Object::Fields::Field' ) )
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($val) && $val->isa('DB::Object::Fields::Field') ? : 0 0 0
$val =~ /$placeholder_re/ || $self->_is_number($val) ? : 0 0 0
Condition0%0/6
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
!ll&&!rl&&r
000
$val =~ /$placeholder_re/ or $self->_is_number($val)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($val) and $val->isa("DB::Object::Fields::Field")
builtin::blessed($val) $val->isa("DB::Object::Fields::Field")
MC/DC0%0/2
$val =~ /$placeholder_re/ or $self->_is_number($val)
$val =~ /$placeholder_re/ $self->_is_number($val)
Truth table0%0/3
A and B
A= builtin::blessed($val)B= $val->isa("DB::Object::Fields::Field")
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $val =~ /$placeholder_re/B= $self->_is_number($val)
ABresult
1X1
011
000
3806 ? $val->name
3807 : ( $val =~ $placeholder_re || $self->_is_number( $val ) )
3808 ? $val
3809 : qq{'${val}'};
3810 0 return( DB::Object::Expression->new( "${lval} ${not}${like}" ) );
3811 }
3812  
3813  
3814 # NOTE: package DB::Object::NOT
3815 package DB::Object::NOT;
3816 BEGIN
3817 {
3818 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3819 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
3820 };
3821  
3822 0 ▶sub operator { return( 'NOT' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3823  
3824 # NOTE: package DB::Object::OR
3825 package DB::Object::OR;
3826 BEGIN
3827 {
3828 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3829 8 ▶ use parent -norequire, qw( DB::Object::Operator );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
3830 };
3831  
3832 0 ▶sub operator { return( 'OR' ); }
Subroutine operator: not called CC=1 SCAR=6.9
3833  
3834 8 1;
3835 # NOTE: POD
3836 __END__
« blib/lib/DB/Object/Statement.pm ↑ Summary blib/lib/DB/Object/Query.pm »