lib/DB/Object.pm

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