DB.pm

filter: Statementstmt 43.9% 531 / 1209 Branchbran 35.1% 213 / 606 Conditioncond 36.7% 133 / 362 MC/DCmcdc 19.0% 37 / 194 Subroutinesub 39.5% 83 / 210 Podpod 43.6% 69 / 158 totaltotal 38.9% 1066 / 2739 CC 443 SCAR 39.3
CC
443
Cov
40%
parse_bitfield
240.0
primary_key_column_names
205.7
commit
156.3
CRAP 50.9
« DB/Oracle.pm ↑ Summary DB/Informix.pm »
1 package Rose::DB;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 17 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Clone::PP();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use Bit::Vector::Overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use SQL::ReservedWords();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 ▶use Time::Clock;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 17 ▶use Rose::DateTime::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 17 ▶use Rose::DB::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use Rose::DB::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use Rose::DB::Registry::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶use Rose::DB::Constants qw(IN_TRANSACTION);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 17 ▶use Rose::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 17 our @ISA = qw(Rose::Object);
21  
22 17 our $Error;
23  
24 17 our $VERSION = '0.788';
25  
26 17 our $Debug = 0;
27  
28 #
29 # Class data
30 #
31  
32 use Rose::Class::MakeMethods::Generic
33 17 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
34 17 inheritable_scalar =>
35 [
36 'default_domain',
37 'default_type',
38 'registry',
39 'max_array_characters',
40 'max_interval_characters',
41 '_db_cache',
42 'db_cache_class',
43 'parent_class',
44 ],
45  
46 inheritable_boolean =>
47 [
48 'default_keyword_function_calls',
49 ]
50 17 );
51  
52 use Rose::Class::MakeMethods::Generic
53 17 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
54 17 inheritable_hash =>
55 [
56 driver_classes => { interface => 'get_set_all' },
57 _driver_class => { interface => 'get_set', hash_key => 'driver_classes' },
58 delete_driver_class => { interface => 'delete', hash_key => 'driver_classes' },
59  
60 default_connect_options => { interface => 'get_set_all', },
61 default_connect_option => { interface => 'get_set', hash_key => 'default_connect_options' },
62 delete_connect_option => { interface => 'delete', hash_key => 'default_connect_options' },
63 ],
64 17 );
65  
66 17 __PACKAGE__->db_cache_class('Rose::DB::Cache');
67 17 __PACKAGE__->default_domain('default');
68 17 __PACKAGE__->default_type('default');
69  
70 17 __PACKAGE__->max_array_characters(255); # Used for array type emulation
71 17 __PACKAGE__->max_interval_characters(255); # Used for interval type emulation
72  
73 __PACKAGE__->default_keyword_function_calls(
74 17 ▶ defined $ENV{'ROSE_DB_KEYWORD_FUNCTION_CALLS'} ? $ENV{'ROSE_DB_KEYWORD_FUNCTION_CALLS'} : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'ROSE_DB_KEYWORD_FUNCTION_CALLS'} ? : 2 15 17
75  
76 17 __PACKAGE__->driver_classes
77 (
78 mysql => 'Rose::DB::MySQL',
79 mariadb => 'Rose::DB::MariaDB',
80 pg => 'Rose::DB::Pg',
81 informix => 'Rose::DB::Informix',
82 oracle => 'Rose::DB::Oracle',
83 sqlite => 'Rose::DB::SQLite',
84 generic => 'Rose::DB::Generic',
85 );
86  
87 17 __PACKAGE__->default_connect_options
88 (
89 AutoCommit => 1,
90 RaiseError => 1,
91 PrintError => 1,
92 ChopBlanks => 1,
93 Warn => 0,
94 );
95  
96 17 ▶BEGIN { __PACKAGE__->registry(Rose::DB::Registry->new(parent => __PACKAGE__)) }
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 17 my %Class_Loaded;
99  
100 # Load on demand instead
101 # LOAD_SUBCLASSES:
102 # {
103 # my %seen;
104 #
105 # my $map = __PACKAGE__->driver_classes;
106 #
107 # foreach my $class (values %$map)
108 # {
109 # eval qq(require $class) unless($seen{$class}++);
110 # die "Could not load $class - $@" if($@);
111 # }
112 # }
113  
114 #
115 # Object data
116 #
117  
118 use Rose::Object::MakeMethods::Generic
119 17 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
120 17 'scalar' =>
121 [
122 qw(dbi_driver username _dbh_refcount id)
123 ],
124  
125 'boolean' =>
126 [
127 'auto_create' => { default => 1 },
128 'european_dates' => { default => 0 },
129 ],
130  
131 'scalar --get_set_init' =>
132 [
133 'domain',
134 'type',
135 'date_handler',
136 'server_time_zone',
137 'keyword_function_calls',
138 ],
139  
140 'array' =>
141 [
142 'post_connect_sql',
143 'pre_disconnect_sql',
144 ],
145  
146 'hash' =>
147 [
148 connect_options => { interface => 'get_set_init' },
149 ]
150 17 );
151  
152 #
153 # Class methods
154 #
155  
156 sub register_db
157 226 ▶{
Subroutine register_db: called CC=3 SCAR=11.2
Pod documented
158 226 my $class = shift;
159  
160 # Smuggle parent/caller in with an otherwise nonsensical arrayref arg
161 226 my $entry = $class->registry->add_entry([ $class ], @_);
162  
163 226 ▶ if($entry)
Branch: 1 branch
BranchTrueFalseTotal
if ($entry) 226 0 226
164 {
165 226 my $driver = $entry->driver;
166  
167 226 ▶ Carp::confess "No driver found for registry entry $entry"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $driver 0 226 226
168 unless(defined $driver);
169  
170 226 $class->setup_dynamic_class_for_driver($driver);
171 }
172  
173 226 return $entry;
174 }
175  
176 17 our %Rebless;
177  
178 sub setup_dynamic_class_for_driver
179 308 ▶{
Subroutine setup_dynamic_class_for_driver: called CC=7 SCAR=19.5
Pod undocumented
180 308 my($class, $driver) = @_;
181  
182 308 ▶ my $driver_class = $class->driver_class($driver) ||
Condition60%3/5
$class->driver_class($driver) || $class->driver_class('generic') || Carp::croak("No driver class found for drivers '${driver}' or 'generic'")
l!l
3080
$class->driver_class($driver) or $class->driver_class("generic")
l!l&&r!l&&!r
30620
MC/DC0%0/2
$class->driver_class($driver) || $class->driver_class('generic') || Carp::croak("No driver class found for drivers '${driver}' or 'generic'")
$class->driver_class($driver) $class->driver_class("generic")
Truth table66%2/3
A or B
A= $class->driver_class($driver)B= $class->driver_class("generic")
ABresult
1X1
011
000
183 $class->driver_class('generic') || Carp::croak
184 "No driver class found for drivers '$driver' or 'generic'";
185  
186 308 ▶ unless($Rebless{$class,$driver_class})
Branch: 1 branch
BranchTrueFalseTotal
unless ($Rose::DB::Rebless{join $;, $class, $driver_class}) 185 123 308
187 {
188 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
189 185 ▶ unless($Class_Loaded{$driver_class} || @{"${driver_class}::ISA"})
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class_Loaded{$driver_class} or @{"${driver_class}::ISA";}) 83 102 185
Condition100%3/3
$Class_Loaded{$driver_class} or @{"${driver_class}::ISA";}
l!l&&r!l&&!r
208283
MC/DC100%2/2
$Class_Loaded{$driver_class} or @{"${driver_class}::ISA";}
$Class_Loaded{$driver_class} @{"${driver_class}::ISA";}
Truth table100%3/3
A or B
A= $Class_Loaded{$driver_class}B= @{"${driver_class}::ISA";}
ABresult
1X1
011
000
190 {
191 83 my $error;
192  
193 TRY:
194 {
195 83 local $@;
196 83 eval "require $driver_class";
197 83 $error = $@;
198 }
199  
200 83 ▶ Carp::croak "Could not load driver class '$driver_class' - $error" if($error);
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 83 83
201 }
202  
203 185 $Class_Loaded{$driver_class}++;
204  
205 # Make a new driver class based on the current class
206 185 my $new_class = $class . '::__RoseDBPrivate__::' . $driver_class;
207  
208 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
209 185 @{"${new_class}::ISA"} = ($driver_class, $class);
210 185 *{"${new_class}::STORABLE_thaw"} = \&STORABLE_thaw;
211 185 *{"${new_class}::STORABLE_freeze"} = \&STORABLE_freeze;
212  
213 185 $new_class->parent_class($class);
214  
215 # Cache result
216 185 $Rebless{$class,$driver_class} = $new_class;
217 }
218  
219 308 return $Rebless{$class,$driver_class};
220 }
221  
222 0 ▶sub unregister_db { shift->registry->delete_entry(@_) }
Subroutine unregister_db: not called CC=1 SCAR=6.9
Pod documented
223  
224 0 ▶sub default_implicit_schema { undef }
Subroutine default_implicit_schema: not called CC=1 SCAR=6.9
Pod undocumented
225 0 ▶sub registration_schema { undef }
Subroutine registration_schema: not called CC=1 SCAR=6.9
Pod undocumented
226  
227 19 ▶sub use_private_registry { $_[0]->registry(Rose::DB::Registry->new(parent => $_[0])) }
Subroutine use_private_registry: called CC=1 SCAR=0.0
Pod documented
228  
229 sub modify_db
230 6 ▶{
Subroutine modify_db: called CC=7 SCAR=21.8
Pod documented
231 6 my($class, %args) = @_;
232  
233 6 ▶ my $domain = delete $args{'domain'} || $class->default_domain ||
Condition40%2/5
delete $args{'domain'} || $class->default_domain || Carp::croak('Missing domain')
l!l
60
delete $args{"domain"} or $class->default_domain
l!l&&r!l&&!r
600
MC/DC0%0/2
delete $args{'domain'} || $class->default_domain || Carp::croak('Missing domain')
delete $args{"domain"} $class->default_domain
Truth table33%1/3
A or B
A= delete $args{"domain"}B= $class->default_domain
ABresult
1X1
011
000
234 Carp::croak "Missing domain";
235  
236 6 ▶ my $type = delete $args{'type'} || $class->default_type ||
Condition40%2/5
delete $args{'type'} || $class->default_type || Carp::croak('Missing type')
l!l
60
delete $args{"type"} or $class->default_type
l!l&&r!l&&!r
600
MC/DC0%0/2
delete $args{'type'} || $class->default_type || Carp::croak('Missing type')
delete $args{"type"} $class->default_type
Truth table33%1/3
A or B
A= delete $args{"type"}B= $class->default_type
ABresult
1X1
011
000
237 Carp::croak "Missing type";
238  
239 6 ▶ my $entry = $class->registry->entry(domain => $domain, type => $type) or
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $class->registry->entry("domain", $domain, "type", $type) or Carp::croak("No db defined for domain '${domain}' and type '${type}'") 6 0 6
240 Carp::croak "No db defined for domain '$domain' and type '$type'";
241  
242 6 ▶ while(my($key, $val) = each(%args))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 10 6 16
243 {
244 10 $entry->$key($val);
245 }
246  
247 6 return $entry;
248 }
249  
250 sub db_exists
251 14 ▶{
Subroutine db_exists: called CC=6 SCAR=19.3
Pod documented
252 14 my($class) = shift;
253  
254 14 ▶ my %args = (@_ == 1) ? (type => $_[0]) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 4 10 14
255  
256 14 ▶ my $domain = $args{'domain'} || $class->default_domain ||
Condition60%3/5
$args{'domain'} || $class->default_domain || Carp::croak('Missing domain')
l!l
140
$args{"domain"} or $class->default_domain
l!l&&r!l&&!r
680
MC/DC0%0/2
$args{'domain'} || $class->default_domain || Carp::croak('Missing domain')
$args{"domain"} $class->default_domain
Truth table66%2/3
A or B
A= $args{"domain"}B= $class->default_domain
ABresult
1X1
011
000
257 Carp::croak "Missing domain";
258  
259 14 ▶ my $type = $args{'type'} || $class->default_type ||
Condition40%2/5
$args{'type'} || $class->default_type || Carp::croak('Missing type')
l!l
140
$args{"type"} or $class->default_type
l!l&&r!l&&!r
1400
MC/DC0%0/2
$args{'type'} || $class->default_type || Carp::croak('Missing type')
$args{"type"} $class->default_type
Truth table33%1/3
A or B
A= $args{"type"}B= $class->default_type
ABresult
1X1
011
000
260 Carp::croak "Missing type";
261  
262 14 return $class->registry->entry_exists(domain => $domain, type => $type);
263 }
264  
265 sub alias_db
266 2 ▶{
Subroutine alias_db: called CC=8 SCAR=22.6
Pod documented
267 2 my($class, %args) = @_;
268  
269 2 ▶ my $source = $args{'source'} or Carp::croak "Missing source";
Branch: 1 branch
BranchTrueFalseTotal
my $source = $args{"source"} or Carp::croak("Missing source") 2 0 2
270  
271 2 ▶ my $src_domain = $source->{'domain'} or Carp::croak "Missing source domain";
Branch: 1 branch
BranchTrueFalseTotal
my $src_domain = $source->{"domain"} or Carp::croak("Missing source domain") 2 0 2
272 2 ▶ my $src_type = $source->{'type'} or Carp::croak "Missing source type";
Branch: 1 branch
BranchTrueFalseTotal
my $src_type = $source->{"type"} or Carp::croak("Missing source type") 2 0 2
273  
274 2 ▶ my $alias = $args{'alias'} or Carp::croak "Missing alias";
Branch: 1 branch
BranchTrueFalseTotal
my $alias = $args{"alias"} or Carp::croak("Missing alias") 2 0 2
275  
276 2 ▶ my $alias_domain = $alias->{'domain'} or Carp::croak "Missing source domain";
Branch: 1 branch
BranchTrueFalseTotal
my $alias_domain = $alias->{"domain"} or Carp::croak("Missing source domain") 2 0 2
277 2 ▶ my $alias_type = $alias->{'type'} or Carp::croak "Missing source type";
Branch: 1 branch
BranchTrueFalseTotal
my $alias_type = $alias->{"type"} or Carp::croak("Missing source type") 2 0 2
278  
279 2 my $registry = $class->registry;
280  
281 2 ▶ my $entry = $registry->entry(domain => $src_domain, type => $src_type) or
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $registry->entry("domain", $src_domain, "type", $src_type) or Carp::croak("No db defined for domain '${src_domain}' and type '${src_type}'") 2 0 2
282 Carp::croak "No db defined for domain '$src_domain' and type '$src_type'";
283  
284 2 $registry->add_entry(domain => $alias_domain,
285 type => $alias_type,
286 entry => $entry);
287 }
288  
289 0 ▶sub unregister_domain { shift->registry->delete_domain(@_) }
Subroutine unregister_domain: not called CC=1 SCAR=6.9
Pod documented
290  
291 sub driver_class
292 548 ▶{
Subroutine driver_class: called CC=2 SCAR=6.9
Pod documented
293 548 my($class, $driver) = (shift, lc shift);
294  
295 548 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 82 466 548
296 {
297 82 $class->_driver_class($driver, @_);
298 82 $class->setup_dynamic_class_for_driver($driver);
299 }
300  
301 548 return $class->_driver_class($driver);
302 }
303  
304 sub db_cache
305 0 ▶{
Subroutine db_cache: not called CC=4 SCAR=30.0
Pod documented
306 0 my($class) = shift;
307  
308 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
309 {
310 0 return $class->_db_cache(@_);
311 }
312  
313 0 ▶ if(my $cache = $class->_db_cache)
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache = $class->_db_cache) 0 0 0
314 {
315 0 return $cache;
316 }
317  
318 0 my $cache_class = $class->db_cache_class;
319  
320 0 my $error;
321  
322 TRY:
323 {
324 0 local $@;
325 0 eval "use $cache_class";
326 0 $error = $@;
327 }
328  
329 0 ▶ die "Could not load db cache class '$cache_class' - $error" if($error);
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
330  
331 0 return $class->_db_cache($cache_class->new);
332 }
333  
334 sub use_cache_during_apache_startup
335 0 ▶{
Subroutine use_cache_during_apache_startup: not called CC=1 SCAR=6.9
Pod documented
336 0 shift->db_cache->use_cache_during_apache_startup(@_);
337 }
338  
339 sub prepare_cache_for_apache_fork
340 0 ▶{
Subroutine prepare_cache_for_apache_fork: not called CC=1 SCAR=6.9
Pod documented
341 0 shift->db_cache->prepare_for_apache_fork(@_);
342 }
343  
344 sub new_or_cached
345 0 ▶{
Subroutine new_or_cached: not called CC=10 SCAR=47.0
Pod documented
346 0 my($class) = shift;
347  
348 0 ▶ @_ = (type => $_[0]) if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
349  
350 0 my %args = @_;
351  
352 0 ▶ $args{'domain'} = $class->default_domain unless(exists $args{'domain'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"domain"} 0 0 0
353 0 ▶ $args{'type'} = $class->default_type unless(exists $args{'type'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"type"} 0 0 0
354  
355 #$Debug && warn "New or cached db type: $args{'type'}, domain: $args{'domain'}\n";
356  
357 0 my $cache = $class->db_cache;
358  
359 0 ▶ if(my $db = $cache->get_db(%args))
Branch: 1 branch
BranchTrueFalseTotal
if (my $db = $cache->get_db(%args)) 0 0 0
360 {
361 0 ▶ $Debug && warn "$$ $class Returning cached db (", $db->domain, ', ', $db->type,
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Debug and warn "${$} $class Returning cached db (", $db->domain, ", ", $db->type, ") $db from ", $cache, "\n" 0 0 0
362 ") $db from ", $cache, "\n";
363 0 return $db;
364 }
365  
366 0 ▶ if($Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($Rose::DB::Debug) { } 0 0 0
367 {
368 0 my $db = $class->new(@_);
369 $Debug && warn "$$ $class Setting cached db $db (",
370 0 ▶ join(', ', map { $args{$_} } qw(domain type)),
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Debug and warn "${$} $class Setting cached db $db (", join(", ", map({$args{$_};} "domain", "type")), ") in ", $cache, "\n" 0 0 0
371 ") in ", $cache, "\n";
372  
373 # The set_db() call may refuse to set, so call get_db() to properly
374 # register clean-up handlers, etc., but fall back to the db returned
375 # by set_db() in the case where the db was never cached.
376 0 $db = $cache->set_db($class->new(@_));
377 0 ▶ return $cache->get_db(%args) || $db;
Condition0%0/3
$cache->get_db(%args) || $db
l!l&&r!l&&!r
000
MC/DC0%0/2
$cache->get_db(%args) || $db
$cache->get_db(%args) $db
Truth table0%0/3
A || B
A= $cache->get_db(%args)B= $db
ABresult
1X1
011
000
378 }
379 else
380 {
381 # The set_db() call may refuse to set, so call get_db() to properly
382 # register clean-up handlers, etc., but fall back to the db returned
383 # by set_db() in the case where the db was never cached.
384 0 my $db = $cache->set_db($class->new(@_));
385 0 ▶ return $cache->get_db(%args) || $db;
Condition0%0/3
$cache->get_db(%args) || $db
l!l&&r!l&&!r
000
MC/DC0%0/2
$cache->get_db(%args) || $db
$cache->get_db(%args) $db
Truth table0%0/3
A || B
A= $cache->get_db(%args)B= $db
ABresult
1X1
011
000
386 }
387 }
388  
389 0 ▶sub clear_db_cache { shift->db_cache->clear(@_) }
Subroutine clear_db_cache: not called CC=1 SCAR=6.9
Pod undocumented
390  
391 #
392 # Object methods
393 #
394  
395 sub new
396 86 ▶{
Subroutine new: called CC=15 SCAR=30.2
Pod documented
397 86 my($class) = shift;
398  
399 86 ▶ @_ = (type => $_[0]) if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 58 28 86
400  
401 86 my %args = @_;
402  
403 86 ▶ my $allow_empty = $args{'driver'} && !($args{'type'} || $args{'domain'});
Condition16%1/6
$args{'driver'} && !($args{'type'} || $args{'domain'})
!ll&&!rl&&r
8600
$args{'type'} || $args{'domain'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'driver'} && !($args{'type'} || $args{'domain'})
$args{'driver'} $args{'type'} $args{'domain'}
Truth table25%1/4
A && not(B || C)
A= $args{'driver'}B= $args{'type'}C= $args{'domain'}
ABCresult
0XX0
11X0
1010
1001
404  
405 my $domain =
406 86 ▶ exists $args{'domain'} ? delete $args{'domain'} : $class->default_domain;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'domain'} ? : 10 76 86
407  
408 my $type =
409 86 ▶ exists $args{'type'} ? delete $args{'type'} : $class->default_type;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'type'} ? : 72 14 86
410  
411 86 my $db_info;
412  
413 # I'm being bad here for speed purposes, digging into private hashes instead
414 # of using object methods. I'll fix it when the first person emails me to
415 # complain that I'm breaking their Rose::DB or Rose::DB::Registry[::Entry]
416 # subclass by doing this. Call it "demand-paged programming" :)
417 86 my $registry = $class->registry->hash;
418  
419 86 ▶ if(exists $registry->{$domain} && exists $registry->{$domain}{$type})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $registry->{$domain} and exists $registry->{$domain}{$type}) { } 68 18 86
elsif (not $allow_empty) { } 18 0 18
Condition100%3/3
exists $registry->{$domain} and exists $registry->{$domain}{$type}
!ll&&!rl&&r
21668
MC/DC100%2/2
exists $registry->{$domain} and exists $registry->{$domain}{$type}
exists $registry->{$domain} exists $registry->{$domain}{$type}
Truth table100%3/3
A and B
A= exists $registry->{$domain}B= exists $registry->{$domain}{$type}
ABresult
0X0
100
111
420 {
421 68 $db_info = $registry->{$domain}{$type}
422 }
423 elsif(!$allow_empty)
424 {
425 18 Carp::croak "No database information found for domain '$domain' and ",
426 "type '$type' and no driver type specified in call to ",
427 "$class->new(...)";
428 }
429  
430 68 ▶ my $driver = $db_info->{'driver'} || $args{'driver'};
Condition33%1/3
$db_info->{'driver'} || $args{'driver'}
l!l&&r!l&&!r
6800
MC/DC0%0/2
$db_info->{'driver'} || $args{'driver'}
$db_info->{'driver'} $args{'driver'}
Truth table33%1/3
A || B
A= $db_info->{'driver'}B= $args{'driver'}
ABresult
1X1
011
000
431  
432 68 ▶ Carp::croak "No driver found for domain '$domain' and type '$type'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $driver 0 68 68
433 unless(defined $driver);
434  
435 68 ▶ my $driver_class = $class->driver_class($driver) ||
Condition60%3/5
$class->driver_class($driver) || $class->driver_class('generic') || Carp::croak("No driver class found for drivers '${driver}' or 'generic'")
l!l
680
$class->driver_class($driver) or $class->driver_class("generic")
l!l&&r!l&&!r
6620
MC/DC0%0/2
$class->driver_class($driver) || $class->driver_class('generic') || Carp::croak("No driver class found for drivers '${driver}' or 'generic'")
$class->driver_class($driver) $class->driver_class("generic")
Truth table66%2/3
A or B
A= $class->driver_class($driver)B= $class->driver_class("generic")
ABresult
1X1
011
000
436 $class->driver_class('generic') || Carp::croak
437 "No driver class found for drivers '$driver' or 'generic'";
438  
439 68 ▶ unless($Class_Loaded{$driver_class})
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class_Loaded{$driver_class}) 0 68 68
440 {
441 0 $class->load_driver_class($driver_class);
442 }
443  
444 68 my $self;
445  
446 REBLESS: # Do slightly evil re-blessing magic
447 {
448 # Check cache
449 68 ▶ if(my $new_class = $Rebless{$class,$driver_class})
Branch: 1 branch
BranchTrueFalseTotal
if (my $new_class = $Rose::DB::Rebless{join $;, $class, $driver_class}) { } 68 0 68
450 {
451 68 $self = bless {}, $new_class;
452 }
453 else
454 {
455 # Make a new driver class based on the current class
456 0 my $new_class = $class . '::__RoseDBPrivate__::' . $driver_class;
457  
458 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
459 0 @{"${new_class}::ISA"} = ($driver_class, $class);
460  
461 0 $self = bless {}, $new_class;
462  
463 0 $new_class->parent_class($class);
464  
465 # Cache result
466 0 $Rebless{$class,$driver_class} = ref $self;
467 }
468 }
469  
470 68 $self->class($class);
471  
472 68 $self->{'id'} = "$domain\0$type";
473 68 $self->{'type'} = $type;
474 68 $self->{'domain'} = $domain;
475  
476 68 $self->init(@_);
477  
478 68 $self->init_db_info;
479  
480 68 return $self;
481 }
482  
483 sub class
484 140 ▶{
Subroutine class: called CC=3 SCAR=11.4
Pod undocumented
485 140 my($self) = shift;
486 140 ▶ return $self->{'_origin_class'} = shift if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 68 72 140
487 72 ▶ return $self->{'_origin_class'} || ref $self;
Condition33%1/3
$self->{'_origin_class'} || ref $self
l!l&&r!l&&!r
7200
MC/DC0%0/2
$self->{'_origin_class'} || ref $self
$self->{'_origin_class'} ref $self
Truth table33%1/3
A || B
A= $self->{'_origin_class'}B= ref $self
ABresult
1X1
011
000
488 }
489  
490 6 ▶sub init_keyword_function_calls { ref($_[0])->default_keyword_function_calls }
Subroutine init_keyword_function_calls: called CC=1 SCAR=0.0
Pod undocumented
491  
492 # sub init
493 # {
494 # my($self) = shift;
495 # $self->SUPER::init(@_);
496 # $self->init_db_info;
497 # }
498  
499 sub load_driver_class
500 80 ▶{
Subroutine load_driver_class: called CC=4 SCAR=14.0
Pod undocumented
501 80 my($class, $arg) = @_;
502  
503 80 ▶ my $driver_class = $class->driver_class($arg) || $arg;
Condition33%1/3
$class->driver_class($arg) || $arg
l!l&&r!l&&!r
8000
MC/DC0%0/2
$class->driver_class($arg) || $arg
$class->driver_class($arg) $arg
Truth table33%1/3
A || B
A= $class->driver_class($arg)B= $arg
ABresult
1X1
011
000
504  
505 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
506 80 ▶ unless(defined ${"${driver_class}::VERSION"})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined ${"${driver_class}::VERSION";}) 16 64 80
507 {
508 16 my $error;
509  
510 TRY:
511 {
512 16 local $@;
513 16 eval "require $driver_class";
514 16 $error = $@;
515 }
516  
517 16 ▶ Carp::croak "Could not load driver class '$driver_class' - $error" if($error);
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 16 16
518 }
519  
520 80 $Class_Loaded{$driver_class}++;
521 }
522  
523 0 ▶sub driver_class_is_loaded { $Class_Loaded{$_[1]} }
Subroutine driver_class_is_loaded: not called CC=1 SCAR=6.9
Pod undocumented
524  
525 sub load_driver_classes
526 16 ▶{
Subroutine load_driver_classes: called CC=3 SCAR=11.1
Pod undocumented
527 16 my($class) = shift;
528  
529 16 my $map = $class->driver_classes;
530  
531 16 ▶ foreach my $arg (@_ ? @_ : keys %$map)
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 16 0 16
532 {
533 80 $class->load_driver_class($arg);
534 }
535  
536 16 return;
537 }
538  
539 sub database
540 76 ▶{
Subroutine database: called CC=3 SCAR=11.0
Pod documented
541 76 my($self) = shift;
542  
543 76 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 74 2 76
544 {
545 74 ▶ $self->{'dsn'} = undef if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 2 72 74
546 74 return $self->{'database'} = shift;
547 }
548  
549 2 return $self->{'database'};
550 }
551  
552 sub schema
553 0 ▶{
Subroutine schema: not called CC=3 SCAR=24.8
Pod documented
554 0 my($self) = shift;
555  
556 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
557 {
558 0 ▶ $self->{'dsn'} = undef if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 0 0 0
559 0 return $self->{'schema'} = shift;
560 }
561  
562 0 return $self->{'schema'};
563 }
564  
565 sub catalog
566 0 ▶{
Subroutine catalog: not called CC=3 SCAR=24.8
Pod documented
567 0 my($self) = shift;
568  
569 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
570 {
571 0 ▶ $self->{'dsn'} = undef if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 0 0 0
572 0 return $self->{'catalog'} = shift;
573 }
574  
575 0 return $self->{'catalog'};
576 }
577  
578 sub service
579 0 ▶{
Subroutine service: not called CC=3 SCAR=24.8
Pod undocumented
580 0 my($self) = shift;
581  
582 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
583 {
584 0 ▶ $self->{'dsn'} = undef if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 0 0 0
585 0 return $self->{'service'} = shift;
586 }
587  
588 0 return $self->{'service'};
589 }
590  
591 sub host
592 62 ▶{
Subroutine host: called CC=3 SCAR=12.0
Pod documented
593 62 my($self) = shift;
594  
595 62 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 62 0 62
596 {
597 62 ▶ $self->{'dsn'} = undef if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 0 62 62
598 62 return $self->{'host'} = shift;
599 }
600  
601 0 return $self->{'host'};
602 }
603  
604 sub port
605 10 ▶{
Subroutine port: called CC=3 SCAR=12.0
Pod documented
606 10 my($self) = shift;
607  
608 10 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 10 0 10
609 {
610 10 ▶ $self->{'dsn'} = undef if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 0 10 10
611 10 return $self->{'port'} = shift;
612 }
613  
614 0 return $self->{'port'};
615 }
616  
617 sub database_version
618 0 ▶{
Subroutine database_version: not called CC=2 SCAR=17.9
Pod undocumented
619 0 my($self) = shift;
620 0 ▶ return $self->{'database_version'} if(defined $self->{'database_version'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"database_version"} 0 0 0
621 0 return $self->{'database_version'} = $self->dbh->get_info(18); # SQL_DBMS_VER
622 }
623  
624 # Use a closure to keep the password from appearing when the
625 # object is dumped using Data::Dumper
626 sub password
627 95 ▶{
Subroutine password: called CC=3 SCAR=11.0
Pod documented
628 95 my($self) = shift;
629  
630 95 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 54 41 95
631 {
632 54 my $password = shift;
633 54 ▶ $self->{'password_closure'} = sub { $password };
Subroutine __ANON__: called CC=1 SCAR=0.0
634 54 return $password;
635 }
636  
637 41 ▶ return $self->{'password_closure'} ? $self->{'password_closure'}->() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'password_closure'} ? : 31 10 41
638 }
639  
640 # These have to "cheat" to get the right values by going through
641 # the real origin class because they may be called after the
642 # re-blessing magic takes place.
643 0 ▶sub init_domain { shift->{'_origin_class'}->default_domain }
Subroutine init_domain: not called CC=1 SCAR=6.9
Pod undocumented
644 0 ▶sub init_type { shift->{'_origin_class'}->default_type }
Subroutine init_type: not called CC=1 SCAR=6.9
Pod undocumented
645  
646 2 ▶sub init_date_handler { Rose::DateTime::Format::Generic->new }
Subroutine init_date_handler: called CC=1 SCAR=0.0
Pod undocumented
647 0 ▶sub init_server_time_zone { 'floating' }
Subroutine init_server_time_zone: not called CC=1 SCAR=6.9
Pod undocumented
648  
649 sub init_db_info
650 72 ▶{
Subroutine init_db_info: called CC=13 SCAR=26.9
Pod documented
651 72 my($self, %args) = @_;
652  
653 72 ▶ return 1 if($self->{'dsn'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dsn"} 2 70 72
654  
655 70 my $class = ref $self;
656  
657 70 my $domain = $self->domain;
658 70 my $type = $self->type;
659  
660 70 my $db_info;
661  
662 # I'm being bad here for speed purposes, digging into private hashes instead
663 # of using object methods. I'll fix it when the first person emails me to
664 # complain that I'm breaking their Rose::DB or Rose::DB::Registry[::Entry]
665 # subclass by doing this. Call it "demand-paged programming" :)
666 70 my $registry = $self->class->registry->hash;
667  
668 70 ▶ if(exists $registry->{$domain} && exists $registry->{$domain}{$type})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $registry->{$domain} and exists $registry->{$domain}{$type}) { } 70 0 70
Condition33%1/3
exists $registry->{$domain} and exists $registry->{$domain}{$type}
!ll&&!rl&&r
0070
MC/DC0%0/2
exists $registry->{$domain} and exists $registry->{$domain}{$type}
exists $registry->{$domain} exists $registry->{$domain}{$type}
Truth table33%1/3
A and B
A= exists $registry->{$domain}B= exists $registry->{$domain}{$type}
ABresult
0X0
100
111
669 {
670 70 $db_info = $registry->{$domain}{$type}
671 }
672 else
673 {
674 0 ▶ return 1 if($self->{'driver'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driver"} 0 0 0
675 0 Carp::croak "No database information found for domain '$domain' and type '$type'";
676 }
677  
678 70 ▶ unless($args{'refresh'} || ($self->{'connect_options_for'}{$domain} &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"refresh"} or $self->{"connect_options_for"}{$domain} and $self->{"connect_options_for"}{$domain}{$type}) 66 4 70
Condition50%3/6
$args{"refresh"} or $self->{"connect_options_for"}{$domain} and $self->{"connect_options_for"}{$domain}{$type}
l!l&&r!l&&!r
4066
$self->{"connect_options_for"}{$domain} and $self->{"connect_options_for"}{$domain}{$type}
!ll&&!rl&&r
6600
MC/DC33%1/3
$args{"refresh"} or $self->{"connect_options_for"}{$domain} and $self->{"connect_options_for"}{$domain}{$type}
$args{"refresh"} $self->{"connect_options_for"}{$domain} $self->{"connect_options_for"}{$domain}{$type}
Truth table50%2/4
A or B and C
A= $args{"refresh"}B= $self->{"connect_options_for"}{$domain}C= $self->{"connect_options_for"}{$domain}{$type}
ABCresult
1XX1
0111
00X0
0100
679 $self->{'connect_options_for'}{$domain}{$type}))
680 {
681 66 ▶ if(my $custom_options = $db_info->{'connect_options'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $custom_options = $db_info->{"connect_options"}) 28 38 66
682 {
683 28 my $options = $self->connect_options;
684 28 @$options{keys %$custom_options} = values %$custom_options;
685 }
686  
687 66 $self->{'connect_options_for'} = { $domain => { $type => 1 } };
688 }
689  
690 70 $self->driver($db_info->{'driver'});
691  
692 70 ▶ while(my($field, $value) = each(%$db_info))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$db_info) 573 70 643
693 {
694 573 ▶ if($field ne 'connect_options' && defined $value && !defined $self->{$field})
Branch: 1 branch
BranchTrueFalseTotal
if ($field ne "connect_options" and defined $value and not defined $self->{$field}) 317 256 573
Condition83%5/6
$field ne "connect_options" and defined $value and not defined $self->{$field}
!ll&&!rl&&r
32224317
$field ne "connect_options" and defined $value
!ll&&!rl&&r
320541
MC/DC66%2/3
$field ne "connect_options" and defined $value and not defined $self->{$field}
$field ne "connect_options" defined $value not defined $self->{$field}
Truth table75%3/4
A and B and not(C)
A= $field ne "connect_options"B= defined $valueC= not defined $self->{$field}
ABCresult
0XX0
10X0
1100
1111
695 {
696 317 $self->$field($value);
697 }
698 }
699  
700 70 return 1;
701 }
702  
703 sub init_connect_options
704 57 ▶{
Subroutine init_connect_options: called CC=1 SCAR=0.0
Pod undocumented
705 57 my($class) = ref $_[0];
706 57 return Clone::PP::clone(scalar $class->default_connect_options);
707 }
708  
709 sub connect_option
710 50 ▶{
Subroutine connect_option: called CC=2 SCAR=6.9
Pod documented
711 50 my($self, $param) = (shift, shift);
712  
713 50 my $options = $self->connect_options;
714  
715 50 ▶ return $options->{$param} = shift if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 25 25 50
716 25 return $options->{$param};
717 }
718  
719 sub dsn
720 51 ▶{
Subroutine dsn: called CC=5 SCAR=16.7
Pod documented
721 51 my($self) = shift;
722  
723 51 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 45 6 51
724 {
725 45 ▶ return $self->{'dsn'} || $self->build_dsn(%$self);
Condition66%2/3
$self->{'dsn'} || $self->build_dsn(%$self)
l!l&&r!l&&!r
2430
MC/DC0%0/2
$self->{'dsn'} || $self->build_dsn(%$self)
$self->{'dsn'} $self->build_dsn(%$self)
Truth table66%2/3
A || B
A= $self->{'dsn'}B= $self->build_dsn(%$self)
ABresult
1X1
011
000
726 }
727  
728 6 ▶ if(my $dsn = shift)
Branch: 1 branch
BranchTrueFalseTotal
if (my $dsn = shift()) { } 6 0 6
729 {
730 6 foreach my $method (qw(database host port))
731 {
732 18 $self->$method(undef);
733 }
734  
735 6 $self->init($self->parse_dsn($dsn));
736 4 return $self->{'dsn'} = $dsn;
737 }
738 else
739 {
740 0 $self->{'dsn'} = undef;
741 0 return $self->build_dsn(%$self);
742 }
743 }
744  
745 17 my %DSN_Attr_Method =
746 (
747 db => 'database',
748 dbname => 'database',
749 user => 'username',
750 hostname => 'host',
751 hostaddr => 'host',
752 sid => 'database',
753 service => 'service_name',
754 );
755  
756 16 ▶sub dsn_attribute_to_db_method { $DSN_Attr_Method{$_[1]} }
Subroutine dsn_attribute_to_db_method: called CC=1 SCAR=0.0
Pod undocumented
757  
758 sub parse_dsn
759 6 ▶{
Subroutine parse_dsn: called CC=6 SCAR=18.4
Pod undocumented
760 6 my($self, $dsn) = @_;
761  
762 6 my($scheme, $driver, $attr_string, $attr_hash, $driver_dsn);
763  
764 # x DBI->parse_dsn('dbi:mysql:database=test;host=localhost')
765 # 0 'dbi'
766 # 1 'mysql'
767 # 2 undef
768 # 3 undef
769 # 4 'database=test;host=localhost'
770  
771 6 ▶ if(DBI->can('parse_dsn'))
Branch: 1 branch
BranchTrueFalseTotal
if ('DBI'->can('parse_dsn')) { } 6 0 6
772 {
773 6 ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) =
774 DBI->parse_dsn($dsn);
775 }
776 else
777 {
778 0 ($scheme, $driver, $attr_string, $driver_dsn) =
779 ($dsn =~ /^((?i)dbi) : (\w+) : (?: \( ([^)]+) \) : )? (.*)/x);
780 }
781  
782 6 my %init =
783 (
784 dbi_driver => $driver,
785 driver => $driver,
786 );
787  
788 6 ▶ while($driver_dsn =~ /\G(\w+)=([^;]+)(?:;|$)?/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($driver_dsn =~ /\G(\w+)=([^;]+)(?:;|$)?/g) 16 6 22
789 {
790 16 my($name, $value) = ($1, $2);
791  
792 16 ▶ if(my $method = $self->dsn_attribute_to_db_method($name))
Branch: 2 branches
BranchTrueFalseTotal
if (my $method = $self->dsn_attribute_to_db_method($name)) { } 4 12 16
elsif ($self->can($name)) { } 12 0 12
793 {
794 4 $init{$method} = $value;
795 }
796 elsif($self->can($name))
797 {
798 12 $init{$name} = $value;
799 }
800 }
801  
802 6 ▶ unless($init{'database'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($init{"database"}) 0 6 6
803 {
804 0 $init{'database'} = $driver_dsn;
805 }
806  
807 6 return %init;
808 }
809  
810 sub database_from_dsn
811 0 ▶{
Subroutine database_from_dsn: not called CC=1 SCAR=6.9
Pod undocumented
812 0 my($self_or_class, $dsn) = @_;
813 0 my %attrs = $self_or_class->parse_dsn($dsn);
814 0 return $attrs{'database'};
815 }
816  
817 sub dbh
818 41 ▶{
Subroutine dbh: called CC=7 SCAR=34.0
Pod documented
819 41 my($self) = shift;
820  
821 41 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 41 0 41
822 {
823 41 ▶ if(my $dbh = $self->{'dbh'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh = $self->{"dbh"}) 0 41 41
824 {
825 # If this db connection wasn't created in another process or thread, return it
826 0 ▶ if((!$INC{'threads.pm'} || $dbh->{'private_tid'} == threads->tid) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!$INC{"threads.pm"} || $dbh->{"private_tid"} == "threads"->tid and $dbh->{"private_pid"} == $$) 0 0 0
Condition0%0/6
!$INC{"threads.pm"} || $dbh->{"private_tid"} == "threads"->tid and $dbh->{"private_pid"} == $$
!ll&&!rl&&r
000
not $INC{"threads.pm"} or $dbh->{"private_tid"} == "threads"->tid
l!l&&r!l&&!r
000
MC/DC0%0/3
!$INC{"threads.pm"} || $dbh->{"private_tid"} == "threads"->tid and $dbh->{"private_pid"} == $$
not $INC{"threads.pm"} $dbh->{"private_tid"} == "threads"->tid $dbh->{"private_pid"} == $$
Truth table0%0/5
not(A) or B and C
A= not $INC{"threads.pm"}B= $dbh->{"private_tid"} == "threads"->tidC= $dbh->{"private_pid"} == $$
ABCresult
00X0
1X00
0100
1X11
0111
827 $dbh->{'private_pid'} == $$)
828 {
829 0 return $dbh;
830 }
831  
832 # This $dbh wasn't created here, so disable destroy actions,
833 # undef it, and create a new one by falling through to the
834 # init_dbh() call below.
835 0 $dbh->{'InactiveDestroy'} = 1;
836 0 $self->{'dbh'} = undef;
837 }
838  
839 41 return $self->init_dbh;
840 }
841  
842 0 ▶ unless(defined($_[0]))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 0 0
843 {
844 0 return $self->{'dbh'} = undef;
845 }
846  
847 0 $self->driver($_[0]->{'Driver'}{'Name'});
848  
849 0 $self->{'_dbh_refcount'}++;
850 0 return $self->{'dbh'} = $_[0];
851 }
852  
853 sub driver
854 76 ▶{
Subroutine driver: called CC=5 SCAR=16.4
Pod documented
855 76 ▶ if(@_ > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 76 0 76
856 {
857 76 my $driver = lc $_[1];
858  
859 76 ▶ if(defined $driver && defined $_[0]->{'driver'} && $_[0]->{'driver'} ne $driver)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $driver and defined $_[0]{"driver"} and $_[0]{"driver"} ne $driver) 2 74 76
Condition83%5/6
defined $driver and defined $_[0]{"driver"} and $_[0]{"driver"} ne $driver
!ll&&!rl&&r
6862
defined $driver and defined $_[0]{"driver"}
!ll&&!rl&&r
0688
MC/DC66%2/3
defined $driver and defined $_[0]{"driver"} and $_[0]{"driver"} ne $driver
defined $driver defined $_[0]{"driver"} $_[0]{"driver"} ne $driver
Truth table75%3/4
A and B and C
A= defined $driverB= defined $_[0]{"driver"}C= $_[0]{"driver"} ne $driver
ABCresult
0XX0
10X0
1100
1111
860 {
861 2 Carp::croak "Attempt to change driver from '$_[0]->{'driver'}' to ",
862 "'$driver' detected. The driver cannot be changed after ",
863 "object creation.";
864 }
865  
866 74 return $_[0]->{'driver'} = $driver;
867 }
868  
869 0 return $_[0]->{'driver'};
870 }
871  
872 sub retain_dbh
873 41 ▶{
Subroutine retain_dbh: called CC=2 SCAR=11.6
Pod documented
874 41 my($self) = shift;
875 41 ▶ my $dbh = $self->dbh or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or return undef 0 0 0
876 #$Debug && warn "$self->{'_dbh_refcount'} -> ", ($self->{'_dbh_refcount'} + 1), " $dbh\n";
877 0 $self->{'_dbh_refcount'}++;
878 0 return $dbh;
879 }
880  
881 sub release_dbh
882 68 ▶{
Subroutine release_dbh: called CC=10 SCAR=44.9
Pod documented
883 68 my($self, %args) = @_;
884  
885 68 ▶ my $dbh = $self->{'dbh'} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->{"dbh"} or return 0 0 68 68
886  
887 0 ▶ if($args{'force'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"force"}) 0 0 0
888 {
889 0 $self->{'_dbh_refcount'} = 0;
890  
891 # Account for possible Apache::DBI magic
892 0 ▶ if(UNIVERSAL::isa($dbh, 'Apache::DBI::db'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($dbh, 'Apache::DBI::db')) { } 0 0 0
893 {
894 0 return $dbh->DBI::db::disconnect; # bypass Apache::DBI
895 }
896 else
897 {
898 0 return $dbh->disconnect;
899 }
900 }
901  
902 #$Debug && warn "$self->{'_dbh_refcount'} -> ", ($self->{'_dbh_refcount'} - 1), " $dbh\n";
903 0 $self->{'_dbh_refcount'}--;
904  
905 0 ▶ unless($self->{'_dbh_refcount'} || $self->{'_dbh_has_foreign_owner'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_dbh_refcount"} or $self->{"_dbh_has_foreign_owner"}) 0 0 0
Condition0%0/3
$self->{"_dbh_refcount"} or $self->{"_dbh_has_foreign_owner"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_dbh_refcount"} or $self->{"_dbh_has_foreign_owner"}
$self->{"_dbh_refcount"} $self->{"_dbh_has_foreign_owner"}
Truth table0%0/3
A or B
A= $self->{"_dbh_refcount"}B= $self->{"_dbh_has_foreign_owner"}
ABresult
1X1
011
000
906 {
907 0 ▶ if(my $sqls = $self->pre_disconnect_sql)
Branch: 1 branch
BranchTrueFalseTotal
if (my $sqls = $self->pre_disconnect_sql) 0 0 0
908 {
909 0 my $error;
910  
911 TRY:
912 {
913 0 local $@;
914  
915 eval
916 0 {
917 0 foreach my $sql (@$sqls)
918 {
919 0 ▶ $dbh->do($sql) or die "$sql - " . $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do($sql) or die "$sql - " . $dbh->errstr 0 0 0
920 0 return undef;
921 }
922 };
923  
924 0 $error = $@;
925 }
926  
927 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
928 {
929 0 $self->error("Could not do pre-disconnect SQL: $error");
930 0 return undef;
931 }
932 }
933  
934 #$Debug && warn "DISCONNECT $dbh ", join(':', (caller(3))[0,2]), "\n";
935 0 return $dbh->disconnect;
936 }
937 #else { $Debug && warn "DISCONNECT NOOP $dbh ", join(':', (caller(2))[0,2]), "\n"; }
938  
939 0 return 1;
940 }
941  
942 sub dbh_attribute
943 0 ▶{
Subroutine dbh_attribute: not called CC=4 SCAR=30.0
Pod undocumented
944 0 my($self, $name) = (shift, shift);
945  
946 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
947 {
948 0 ▶ if(my $dbh = $self->{'dbh'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh = $self->{'dbh'}) { } 0 0 0
949 {
950 0 return $self->{'dbh'}{$name} = $self->{'__dbh_attributes'}{$name} = shift;
951 }
952 else
953 {
954 0 return $self->{'__dbh_attributes'}{$name} = shift;
955 }
956 }
957  
958 0 ▶ if(my $dbh = $self->{'dbh'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh = $self->{'dbh'}) { } 0 0 0
959 {
960 0 return $self->{'dbh'}{$name};
961 }
962 else
963 {
964 0 return $self->{'__dbh_attributes'}{$name};
965 }
966 }
967  
968 sub dbh_attribute_boolean
969 0 ▶{
Subroutine dbh_attribute_boolean: not called CC=3 SCAR=24.8
Pod undocumented
970 0 my($self, $name) = (shift, shift);
971 0 ▶ return $self->dbh_attribute($name, (@_ ? ($_[0] ? 1 : 0) : ()));
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
$_[0] ? : 0 0 0
972 }
973  
974 2 ▶sub has_dbh { defined shift->{'dbh'} }
Subroutine has_dbh: called CC=1 SCAR=0.0
Pod documented
975  
976 sub dbi_connect
977 41 ▶{
Subroutine dbi_connect: called CC=3 SCAR=19.2
Pod documented
978 41 shift;
979  
980 41 ▶ if($Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($Rose::DB::Debug) 0 41 41
981 {
982 0 require Data::Dumper;
983 0 local $Data::Dumper::Terse = 1;
984 0 local $Data::Dumper::Indent = 1;
985 0 local $Data::Dumper::Maxdepth = 1;
986 0 local $Data::Dumper::Quotekeys = 0;
987 0 local $Data::Dumper::Sortkeys = 1;
988 0 ▶ my $options = Data::Dumper::Dumper($_[3] || {});
Condition0%0/2
$_[3] || {}
l!l
00
MC/DC0%0/1
$_[3] || {}
$_[3]
Truth table0%0/2
A
A= $_[3]
Aresult
11
00
989 0 $options =~ s/\n\s*/ /g;
990 0 warn "DBI->connect('$_[0]', '$_[1]', ..., $options)\n";
991 }
992  
993 41 DBI->connect(@_);
994 }
995  
996 17 ▶use constant DID_PCSQL_KEY => 'private_rose_db_did_post_connect_sql';
Subroutine BEGIN: called CC=1 SCAR=0.0
997  
998 sub init_dbh
999 41 ▶{
Subroutine init_dbh: called CC=12 SCAR=44.6
Pod undocumented
1000 41 my($self) = shift;
1001  
1002 41 my $options = $self->connect_options;
1003  
1004 41 $options->{'private_pid'} = $$;
1005 41 ▶ $options->{'private_tid'} = threads->tid if($INC{'threads.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 41 41
1006  
1007 41 my $dsn = $self->dsn;
1008  
1009 41 $self->{'error'} = undef;
1010 41 $self->{'database_version'} = undef;
1011 41 $self->{'_dbh_refcount'} = 0;
1012 41 $self->{'_dbh_has_foreign_owner'} = undef;
1013  
1014 41 my $dbh = $self->dbi_connect($dsn, $self->username, $self->password, $options);
1015  
1016 0 ▶ unless($dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
1017 {
1018 0 $self->error("Could not connect to database: $DBI::errstr");
1019 0 return undef;
1020 }
1021  
1022 0 ▶ if($dbh->{'private_rose_db_inited'})
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{'private_rose_db_inited'}) { } 0 0 0
1023 {
1024 # Someone else owns this dbh
1025 0 $self->{'_dbh_has_foreign_owner'} = 1;
1026 }
1027 else # Only initialize if this is really a new connection
1028 {
1029 0 $dbh->{'private_rose_db_inited'} = 1;
1030  
1031 0 ▶ if($self->{'__dbh_attributes'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__dbh_attributes"}) 0 0 0
1032 {
1033 0 foreach my $attr (keys %{$self->{'__dbh_attributes'}})
1034 {
1035 0 my $val = $self->dbh_attribute($attr);
1036 0 ▶ next unless(defined $val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1037 0 $dbh->{$attr} = $val;
1038 }
1039 }
1040  
1041 0 ▶ if((my $sqls = $self->post_connect_sql) && !$dbh->{DID_PCSQL_KEY()})
Branch: 1 branch
BranchTrueFalseTotal
if (my $sqls = $self->post_connect_sql and not $dbh->{"private_rose_db_did_post_connect_sql"}) 0 0 0
Condition0%0/3
my $sqls = $self->post_connect_sql and not $dbh->{"private_rose_db_did_post_connect_sql"}
!ll&&!rl&&r
000
MC/DC0%0/2
my $sqls = $self->post_connect_sql and not $dbh->{"private_rose_db_did_post_connect_sql"}
my $sqls = $self->post_connect_sql not $dbh->{"private_rose_db_did_post_connect_sql"}
Truth table0%0/3
A and not(B)
A= my $sqls = $self->post_connect_sqlB= not $dbh->{"private_rose_db_did_post_connect_sql"}
ABresult
0X0
100
111
1042 {
1043 0 my $error;
1044  
1045 TRY:
1046 {
1047 0 local $@;
1048  
1049 eval
1050 0 {
1051 0 foreach my $sql (@$sqls)
1052 {
1053 #$Debug && warn "$dbh DO: $sql\n";
1054 0 ▶ $dbh->do($sql) or die "$sql - " . $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do($sql) or die "$sql - " . $dbh->errstr 0 0 0
1055 }
1056 };
1057  
1058 0 $error = $@;
1059 }
1060  
1061 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1062 {
1063 0 $self->error("Could not do post-connect SQL: $error");
1064 0 $dbh->disconnect;
1065 0 return undef;
1066 }
1067  
1068 0 $dbh->{DID_PCSQL_KEY()} = 1;
1069 }
1070 }
1071  
1072 0 $self->{'_dbh_refcount'} = 1;
1073  
1074 0 return $self->{'dbh'} = $dbh;
1075 }
1076  
1077 25 ▶sub print_error { shift->_dbh_and_connect_option('PrintError', @_) }
Subroutine print_error: called CC=1 SCAR=0.0
Pod documented
1078 0 ▶sub raise_error { shift->_dbh_and_connect_option('RaiseError', @_) }
Subroutine raise_error: not called CC=1 SCAR=6.9
Pod documented
1079 0 ▶sub autocommit { shift->_dbh_and_connect_option('AutoCommit', @_) }
Subroutine autocommit: not called CC=1 SCAR=6.9
Pod documented
1080 0 ▶sub handle_error { shift->_dbh_and_connect_option('HandleError', @_) }
Subroutine handle_error: not called CC=1 SCAR=6.9
Pod documented
1081  
1082 sub _dbh_and_connect_option
1083 25 ▶{
Subroutine _dbh_and_connect_option: called CC=5 SCAR=17.2
1084 25 my($self, $param) = (shift, shift);
1085  
1086 25 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 25 0 25
1087 {
1088 25 ▶ my $val = $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 25 25
1089 25 $self->connect_option($param => $val);
1090  
1091 25 ▶ $self->{'dbh'}{$param} = $val if($self->{'dbh'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbh"} 0 25 25
1092 }
1093  
1094 25 ▶ return $self->{'dbh'} ? $self->{'dbh'}{$param} :
Branch: 1 branch
BranchTrueFalseTotal
$self->{'dbh'} ? : 0 25 25
1095 $self->connect_option($param);
1096 }
1097  
1098 sub connect
1099 0 ▶{
Subroutine connect: not called CC=2 SCAR=17.9
Pod documented
1100 0 my($self) = shift;
1101  
1102 0 ▶ $self->dbh or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->dbh or return 0 0 0 0
1103 0 return 1;
1104 }
1105  
1106 sub disconnect
1107 68 ▶{
Subroutine disconnect: called CC=2 SCAR=8.1
Pod documented
1108 68 my($self) = shift;
1109  
1110 68 ▶ $self->release_dbh(@_) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->release_dbh(@_) or return undef 0 68 68
1111  
1112 0 $self->{'dbh'} = undef;
1113 }
1114  
1115 sub begin_work
1116 0 ▶{
Subroutine begin_work: not called CC=8 SCAR=40.7
Pod documented
1117 0 my($self) = shift;
1118  
1119 0 ▶ my $dbh = $self->dbh or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or return undef 0 0 0
1120  
1121 0 ▶ if($dbh->{'AutoCommit'})
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"AutoCommit"}) 0 0 0
1122 {
1123 0 my $ret;
1124  
1125 #$Debug && warn "BEGIN TRX\n";
1126  
1127 my $error;
1128  
1129 TRY:
1130 {
1131 0 local $@;
1132  
1133 eval
1134 0 {
1135 0 local $dbh->{'RaiseError'} = 1;
1136  
1137 # XXX: Detect DBD::mysql bug (in some versions before 4.012) that
1138 # XXX: fails to set Active back to 1 when mysql_auto_reconnect
1139 # XXX: is in use.
1140 0 ▶ unless($dbh->{'Active'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh->{"Active"}) 0 0 0
1141 {
1142 0 ▶ if($dbh->{'Driver'}{'Name'} eq 'mysql' && $dbh->{'Driver'}{'Version'} < 4.012)
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{'Driver'}{'Name'} eq 'mysql' and $dbh->{'Driver'}{'Version'} < 4.012) { } 0 0 0
Condition0%0/3
$dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012"
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012"
$dbh->{"Driver"}{"Name"} eq "mysql" $dbh->{"Driver"}{"Version"} < "4.012"
Truth table0%0/3
A and B
A= $dbh->{"Driver"}{"Name"} eq "mysql"B= $dbh->{"Driver"}{"Version"} < "4.012"
ABresult
0X0
100
111
1143 {
1144 0 die 'Database handle does not have Active set to a true value. DBD::mysql ',
1145 'versions before 4.012 may fail to set Active back to 1 when the ',
1146 'mysql_auto_reconnect is set. Try upgrading to DBD::mysql 4.012 or later';
1147 }
1148 else
1149 {
1150 0 die "Cannot start transaction on inactive database handle ($dbh)";
1151 }
1152 }
1153  
1154 0 $ret = $dbh->begin_work
1155 };
1156  
1157 0 $error = $@;
1158 }
1159  
1160 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1161 {
1162 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1163 0 $self->error("begin_work() - $error " . $dbh->errstr);
1164 0 return undef;
1165 }
1166  
1167 0 ▶ unless($ret)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 0 0
1168 {
1169 0 $self->error('begin_work() failed - ' . $dbh->errstr);
1170 0 return undef;
1171 }
1172  
1173 0 return 1;
1174 }
1175  
1176 0 return IN_TRANSACTION;
1177 }
1178  
1179 sub in_transaction
1180 0 ▶{
Subroutine in_transaction: not called CC=3 SCAR=24.8
Pod documented
1181 0 ▶ my $dbh = shift->{'dbh'} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = +(shift())->{"dbh"} or return undef 0 0 0
1182 0 ▶ return ($dbh->{'AutoCommit'}) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->{'AutoCommit'} ? : 0 0 0
1183 }
1184  
1185 sub commit
1186 0 ▶{
Subroutine commit: not called CC=13 SCAR=50.5
Pod documented
1187 0 my($self) = shift;
1188  
1189 0 ▶ my $is_active = (defined $self->{'dbh'} && $self->{'dbh'}{'Active'}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'dbh'} && $self->{'dbh'}{'Active'} ? : 0 0 0
Condition0%0/3
defined $self->{"dbh"} and $self->{"dbh"}{"Active"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"dbh"} and $self->{"dbh"}{"Active"}
defined $self->{"dbh"} $self->{"dbh"}{"Active"}
Truth table0%0/3
A and B
A= defined $self->{"dbh"}B= $self->{"dbh"}{"Active"}
ABresult
0X0
100
111
1190  
1191 0 ▶ unless(defined $self->{'dbh'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
1192 {
1193 0 $self->error("Could not commit transaction: database handle is undefined");
1194 0 return 0;
1195 }
1196  
1197 0 ▶ my $dbh = $self->dbh or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or return undef 0 0 0
1198  
1199 0 ▶ unless($dbh->{'AutoCommit'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh->{"AutoCommit"}) 0 0 0
1200 {
1201 0 my $ret;
1202  
1203 #$Debug && warn "COMMIT TRX\n";
1204  
1205 my $error;
1206  
1207 TRY:
1208 {
1209 0 local $@;
1210  
1211 eval
1212 0 {
1213 0 local $dbh->{'RaiseError'} = 1;
1214 0 $ret = $dbh->commit;
1215 };
1216  
1217 0 $error = $@;
1218 }
1219  
1220 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1221 {
1222 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1223 0 $self->error("commit() $error - " . $dbh->errstr);
1224  
1225 0 ▶ unless($is_active)
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_active) 0 0 0
1226 {
1227 0 ▶ if($dbh->{'Driver'}{'Name'} eq 'mysql' && $dbh->{'Driver'}{'Version'} < 4.012)
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012") 0 0 0
Condition0%0/3
$dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012"
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012"
$dbh->{"Driver"}{"Name"} eq "mysql" $dbh->{"Driver"}{"Version"} < "4.012"
Truth table0%0/3
A and B
A= $dbh->{"Driver"}{"Name"} eq "mysql"B= $dbh->{"Driver"}{"Version"} < "4.012"
ABresult
0X0
100
111
1228 {
1229 0 $self->error($self->error . '; Also, the database handle did not ' .
1230 'have Active set to a true value. DBD::mysql versions before 4.012 ' .
1231 'may fail to set Active back to 1 when the mysql_auto_reconnect is ' .
1232 'set. Try upgrading to DBD::mysql 4.012 or later');
1233 }
1234  
1235 0 return 0;
1236 }
1237  
1238 0 return undef;
1239 }
1240  
1241 0 ▶ unless($ret)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 0 0
1242 {
1243 0 ▶ $self->error('Could not commit transaction: ' .
Condition0%0/5
$dbh->errstr || $DBI::errstr || 'Possibly a referential integrity violation. Check the database error log for more information.'
l!l
00
$dbh->errstr or $DBI::errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbh->errstr || $DBI::errstr || 'Possibly a referential integrity violation. Check the database error log for more information.'
$dbh->errstr $DBI::errstr
Truth table0%0/3
A or B
A= $dbh->errstrB= $DBI::errstr
ABresult
1X1
011
000
1244 ($dbh->errstr || $DBI::errstr ||
1245 'Possibly a referential integrity violation. ' .
1246 'Check the database error log for more information.'));
1247 0 return undef;
1248 }
1249  
1250 0 return 1;
1251 }
1252  
1253 0 return -1;
1254 }
1255  
1256 sub rollback
1257 0 ▶{
Subroutine rollback: not called CC=12 SCAR=48.9
Pod documented
1258 0 my($self) = shift;
1259  
1260 0 ▶ my $is_active = (defined $self->{'dbh'} && $self->{'dbh'}{'Active'}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'dbh'} && $self->{'dbh'}{'Active'} ? : 0 0 0
Condition0%0/3
defined $self->{"dbh"} and $self->{"dbh"}{"Active"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"dbh"} and $self->{"dbh"}{"Active"}
defined $self->{"dbh"} $self->{"dbh"}{"Active"}
Truth table0%0/3
A and B
A= defined $self->{"dbh"}B= $self->{"dbh"}{"Active"}
ABresult
0X0
100
111
1261  
1262 0 ▶ unless(defined $self->{'dbh'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
1263 {
1264 0 $self->error("Could not roll back transaction: database handle is undefined");
1265 0 return 0;
1266 }
1267  
1268 0 ▶ my $dbh = $self->dbh or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or return undef 0 0 0
1269  
1270 0 my $ac = $dbh->{'AutoCommit'};
1271  
1272 0 ▶ return 1 if($ac);
Branch: 1 branch
BranchTrueFalseTotal
if $ac 0 0 0
1273  
1274 0 my $ret;
1275  
1276 #$Debug && warn "ROLLBACK TRX\n";
1277  
1278 my $error;
1279  
1280 TRY:
1281 {
1282 0 local $@;
1283  
1284 eval
1285 0 {
1286 0 local $dbh->{'RaiseError'} = 1;
1287 0 $ret = $dbh->rollback;
1288 };
1289  
1290 0 $error = $@;
1291 }
1292  
1293 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1294 {
1295 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1296 0 $self->error("rollback() - $error " . $dbh->errstr);
1297  
1298 0 ▶ unless($is_active)
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_active) 0 0 0
1299 {
1300 0 ▶ if($dbh->{'Driver'}{'Name'} eq 'mysql' && $dbh->{'Driver'}{'Version'} < 4.012)
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012") 0 0 0
Condition0%0/3
$dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012"
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->{"Driver"}{"Name"} eq "mysql" and $dbh->{"Driver"}{"Version"} < "4.012"
$dbh->{"Driver"}{"Name"} eq "mysql" $dbh->{"Driver"}{"Version"} < "4.012"
Truth table0%0/3
A and B
A= $dbh->{"Driver"}{"Name"} eq "mysql"B= $dbh->{"Driver"}{"Version"} < "4.012"
ABresult
0X0
100
111
1301 {
1302 0 $self->error($self->error . '; Also, the database handle did not ' .
1303 'have Active set to a true value. DBD::mysql versions before 4.012 ' .
1304 'may fail to set Active back to 1 when the mysql_auto_reconnect is ' .
1305 'set. Try upgrading to DBD::mysql 4.012 or later');
1306 }
1307  
1308 0 return 0;
1309 }
1310  
1311 0 return undef;
1312 }
1313  
1314 0 ▶ unless($ret || $ac)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret or $ac) 0 0 0
Condition0%0/3
$ret or $ac
l!l&&r!l&&!r
000
MC/DC0%0/2
$ret or $ac
$ret $ac
Truth table0%0/3
A or B
A= $retB= $ac
ABresult
1X1
011
000
1315 {
1316 0 $self->error('rollback() failed - ' . $dbh->errstr);
1317 0 return undef;
1318 }
1319  
1320 # DBI does this for me...
1321 #$dbh->{'AutoCommit'} = 1;
1322  
1323 0 return 1;
1324 }
1325  
1326 sub do_transaction
1327 0 ▶{
Subroutine do_transaction: not called CC=7 SCAR=40.3
Pod documented
1328 0 my($self, $code) = (shift, shift);
1329  
1330 0 ▶ my $dbh = $self->dbh or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or return undef 0 0 0
1331  
1332 0 my $error;
1333  
1334 TRY:
1335 {
1336 0 local $@;
1337  
1338 eval
1339 0 {
1340 0 ▶ $self->begin_work or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
$self->begin_work or die $self->error 0 0 0
1341 0 $code->(@_);
1342 0 ▶ $self->commit or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
$self->commit or die $self->error 0 0 0
1343 };
1344  
1345 0 $error = $@;
1346 }
1347  
1348 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1349 {
1350 0 ▶ $error = ref $error ? $error : "do_transaction() failed - $error";
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
1351  
1352 0 ▶ if($self->rollback)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rollback) { } 0 0 0
1353 {
1354 0 $self->error($error);
1355 }
1356 else
1357 {
1358 0 $self->error("$error. rollback() also failed - " . $self->error)
1359 }
1360  
1361 0 return undef;
1362 }
1363  
1364 0 return 1;
1365 }
1366  
1367 sub auto_quote_table_name
1368 0 ▶{
Subroutine auto_quote_table_name: not called CC=3 SCAR=24.8
Pod undocumented
1369 0 my($self, $name) = @_;
1370  
1371 0 ▶ if($name =~ /\W/ || $self->is_reserved_word($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\W/ or $self->is_reserved_word($name)) 0 0 0
Condition0%0/3
$name =~ /\W/ or $self->is_reserved_word($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$name =~ /\W/ or $self->is_reserved_word($name)
$name =~ /\W/ $self->is_reserved_word($name)
Truth table0%0/3
A or B
A= $name =~ /\W/B= $self->is_reserved_word($name)
ABresult
1X1
011
000
1372 {
1373 0 return $self->quote_table_name($name, @_);
1374 }
1375  
1376 0 return $name;
1377 }
1378  
1379 sub auto_quote_column_name
1380 0 ▶{
Subroutine auto_quote_column_name: not called CC=3 SCAR=24.8
Pod undocumented
1381 0 my($self, $name) = @_;
1382  
1383 0 ▶ if($name =~ /\W/ || $self->is_reserved_word($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\W/ or $self->is_reserved_word($name)) 0 0 0
Condition0%0/3
$name =~ /\W/ or $self->is_reserved_word($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$name =~ /\W/ or $self->is_reserved_word($name)
$name =~ /\W/ $self->is_reserved_word($name)
Truth table0%0/3
A or B
A= $name =~ /\W/B= $self->is_reserved_word($name)
ABresult
1X1
011
000
1384 {
1385 0 return $self->quote_column_name($name, @_);
1386 }
1387  
1388 0 return $name;
1389 }
1390  
1391 sub quote_column_name
1392 0 ▶{
Subroutine quote_column_name: not called CC=1 SCAR=6.9
Pod documented
1393 0 my $name = $_[1];
1394 0 $name =~ s/"/""/g;
1395 0 return qq("$name");
1396 }
1397  
1398 sub quote_table_name
1399 0 ▶{
Subroutine quote_table_name: not called CC=1 SCAR=6.9
Pod undocumented
1400 0 my $name = $_[1];
1401 0 $name =~ s/"/""/g;
1402 0 return qq("$name");
1403 }
1404  
1405 sub unquote_column_name
1406 0 ▶{
Subroutine unquote_column_name: not called CC=2 SCAR=12.6
Pod undocumented
1407 0 my($self_or_class, $name) = @_;
1408  
1409 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1410  
1411 # handle quoted strings with quotes doubled inside them
1412 0 ▶ if($name =~ /^(['"`])(.+)\1$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(['"`])(.+)\1$/) 0 0 0
1413 {
1414 0 my $q = $1;
1415 0 $name = $2;
1416 0 $name =~ s/$q$q/$q/g;
1417 }
1418  
1419 0 return $name;
1420 }
1421  
1422 17 *unquote_table_name = \&unquote_column_name;
1423  
1424 #sub is_reserved_word { 0 }
1425  
1426 17 *is_reserved_word = \&SQL::ReservedWords::is_reserved;
1427  
1428 BEGIN
1429 17 ▶{
Subroutine BEGIN: called CC=2 SCAR=13.7
1430 sub quote_identifier_dbi
1431 0 ▶ {
Subroutine quote_identifier_dbi: not called CC=2 SCAR=17.9
Pod undocumented
1432 0 my($self) = shift;
1433 0 ▶ my $dbh = $self->dbh or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or die $self->error 0 0 0
1434 0 return $dbh->quote_identifier(@_);
1435 }
1436  
1437 sub quote_identifier_fallback
1438 0 ▶ {
Subroutine quote_identifier_fallback: not called CC=1 SCAR=6.9
Pod undocumented
1439 0 my($self, $catalog, $schema, $table) = @_;
1440 0 return join('.', map { qq("$_") } grep { defined } ($schema, $table));
1441 }
1442  
1443 17 ▶ if($DBI::VERSION >= 1.21)
Branch: 1 branch
BranchTrueFalseTotal
if ($DBI::VERSION >= 1.21) { } 17 0 17
1444 {
1445 17 *quote_identifier = \&quote_identifier_dbi;
1446 }
1447 else
1448 {
1449 0 *quote_identifier = \&quote_identifier_fallback;
1450 }
1451 }
1452  
1453 17 *quote_identifier_for_sequence = \&quote_identifier;
1454  
1455 sub quote_column_with_table
1456 0 ▶{
Subroutine quote_column_with_table: not called CC=2 SCAR=17.9
Pod undocumented
1457 0 my($self, $column, $table) = @_;
1458  
1459 0 ▶ return $table ?
Branch: 1 branch
BranchTrueFalseTotal
$table ? : 0 0 0
1460 $self->quote_table_name($table) . '.' .
1461 $self->quote_column_name($column) :
1462 $self->quote_column_name($column);
1463 }
1464  
1465 sub auto_quote_column_with_table
1466 0 ▶{
Subroutine auto_quote_column_with_table: not called CC=2 SCAR=17.9
Pod undocumented
1467 0 my($self, $column, $table) = @_;
1468  
1469 0 ▶ return $table ?
Branch: 1 branch
BranchTrueFalseTotal
$table ? : 0 0 0
1470 $self->auto_quote_table_name($table) . '.' .
1471 $self->auto_quote_column_name($column) :
1472 $self->auto_quote_column_name($column);
1473 }
1474  
1475 sub has_primary_key
1476 0 ▶{
Subroutine has_primary_key: not called CC=3 SCAR=24.8
Pod documented
1477 0 my($self) = shift;
1478 0 my $columns = $self->primary_key_column_names(@_);
1479 0 ▶ return (ref $columns && @$columns) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $columns && @$columns ? : 0 0 0
Condition0%0/3
ref $columns and @$columns
!ll&&!rl&&r
000
MC/DC0%0/2
ref $columns and @$columns
ref $columns @$columns
Truth table0%0/3
A and B
A= ref $columnsB= @$columns
ABresult
0X0
100
111
1480 }
1481  
1482 sub primary_key_column_names
1483 0 ▶{
Subroutine primary_key_column_names: not called CC=15 SCAR=53.3
Pod documented
1484 0 my($self) = shift;
1485  
1486 0 ▶ my %args = @_ == 1 ? (table => @_) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
1487  
1488 0 ▶ my $table = $args{'table'} or Carp::croak "Missing table name parameter";
Branch: 1 branch
BranchTrueFalseTotal
my $table = $args{"table"} or Carp::croak("Missing table name parameter") 0 0 0
1489 0 ▶ my $catalog = $args{'catalog'} || $self->catalog;
Condition0%0/3
$args{'catalog'} || $self->catalog
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'catalog'} || $self->catalog
$args{'catalog'} $self->catalog
Truth table0%0/3
A || B
A= $args{'catalog'}B= $self->catalog
ABresult
1X1
011
000
1490 0 ▶ my $schema = $args{'schema'} || $self->schema;
Condition0%0/3
$args{'schema'} || $self->schema
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'schema'} || $self->schema
$args{'schema'} $self->schema
Truth table0%0/3
A || B
A= $args{'schema'}B= $self->schema
ABresult
1X1
011
000
1491  
1492 0 ▶ $schema = $self->default_implicit_schema unless(defined $schema);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $schema 0 0 0
1493  
1494 0 ▶ $table = lc $table if($self->likes_lowercase_table_names);
Branch: 1 branch
BranchTrueFalseTotal
if $self->likes_lowercase_table_names 0 0 0
1495  
1496 0 ▶ $schema = lc $schema
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema and $self->likes_lowercase_schema_names 0 0 0
Condition0%0/3
defined $schema and $self->likes_lowercase_schema_names
!ll&&!rl&&r
000
MC/DC0%0/2
defined $schema and $self->likes_lowercase_schema_names
defined $schema $self->likes_lowercase_schema_names
Truth table0%0/3
A and B
A= defined $schemaB= $self->likes_lowercase_schema_names
ABresult
0X0
100
111
1497 if(defined $schema && $self->likes_lowercase_schema_names);
1498  
1499 0 ▶ $catalog = lc $catalog
Branch: 1 branch
BranchTrueFalseTotal
if defined $catalog and $self->likes_lowercase_catalog_names 0 0 0
Condition0%0/3
defined $catalog and $self->likes_lowercase_catalog_names
!ll&&!rl&&r
000
MC/DC0%0/2
defined $catalog and $self->likes_lowercase_catalog_names
defined $catalog $self->likes_lowercase_catalog_names
Truth table0%0/3
A and B
A= defined $catalogB= $self->likes_lowercase_catalog_names
ABresult
0X0
100
111
1500 if(defined $catalog && $self->likes_lowercase_catalog_names);
1501  
1502 0 my $table_unquoted = $self->unquote_table_name($table);
1503  
1504 0 my $columns;
1505  
1506 my $error;
1507  
1508 TRY:
1509 {
1510 0 local $@;
1511  
1512 eval
1513 0 {
1514 0 $columns =
1515 $self->_get_primary_key_column_names($catalog, $schema, $table_unquoted);
1516 };
1517  
1518 0 $error = $@;
1519 }
1520  
1521 0 ▶ if($error || !$columns)
Branch: 1 branch
BranchTrueFalseTotal
if ($error or not $columns) 0 0 0
Condition0%0/3
$error or not $columns
l!l&&r!l&&!r
000
MC/DC0%0/2
$error or not $columns
$error not $columns
Truth table0%0/3
A or not(B)
A= $errorB= not $columns
ABresult
1X1
011
000
1522 {
1523 17 ▶ no warnings 'uninitialized'; # undef strings okay
Subroutine BEGIN: called CC=1 SCAR=0.0
1524 0 ▶ $error = 'no primary key columns found' unless(defined $error);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 0 0
1525 0 Carp::croak "Could not get primary key columns for catalog '" .
1526 $catalog . "' schema '" . $schema . "' table '" .
1527 $table_unquoted . "' - " . $error;
1528 }
1529  
1530 0 ▶ return wantarray ? @$columns : $columns;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1531 }
1532  
1533 sub _get_primary_key_column_names
1534 0 ▶{
Subroutine _get_primary_key_column_names: not called CC=9 SCAR=40.9
1535 0 my($self, $catalog, $schema, $table) = @_;
1536  
1537 0 ▶ my $dbh = $self->dbh or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or die $self->error 0 0 0
1538  
1539 0 local $dbh->{'FetchHashKeyName'} = 'NAME';
1540  
1541 0 my $sth = $dbh->primary_key_info($catalog, $schema, $table);
1542  
1543 0 ▶ unless(defined $sth)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sth) 0 0 0
1544 {
1545 17 ▶ no warnings 'uninitialized'; # undef strings okay
Subroutine BEGIN: called CC=1 SCAR=0.0
1546 0 $self->error("No primary key information found for catalog '", $catalog,
1547 "' schema '", $schema, "' table '", $table, "'");
1548 0 return [];
1549 }
1550  
1551 0 my @columns;
1552  
1553 0 my $supports_catalog = $self->supports_catalog;
1554  
1555 0 ▶ PK: while(my $pk_info = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $pk_info = $sth->fetchrow_hashref) 0 0 0
1556 {
1557 CHECK_TABLE: # Make sure this column is from the right table
1558 {
1559 0 ▶ no warnings; # Allow undef coercion to empty string
Subroutine BEGIN: called CC=1 SCAR=0.2
1560  
1561 $pk_info->{'TABLE_NAME'} =
1562 0 $self->unquote_table_name($pk_info->{'TABLE_NAME'});
1563  
1564 next PK unless((!$supports_catalog || $pk_info->{'TABLE_CAT'} eq $catalog) &&
1565 $pk_info->{'TABLE_SCHEM'} eq $schema &&
1566 0 ▶ $pk_info->{'TABLE_NAME'} eq $table);
Branch: 1 branch
BranchTrueFalseTotal
unless !$supports_catalog || $pk_info->{"TABLE_CAT"} eq $catalog and $pk_info->{"TABLE_SCHEM"} eq $schema and $pk_info->{"TABLE_NAME"} eq $table 0 0 0
Condition0%0/9
!$supports_catalog || $pk_info->{"TABLE_CAT"} eq $catalog and $pk_info->{"TABLE_SCHEM"} eq $schema and $pk_info->{"TABLE_NAME"} eq $table
!ll&&!rl&&r
000
!$supports_catalog || $pk_info->{"TABLE_CAT"} eq $catalog and $pk_info->{"TABLE_SCHEM"} eq $schema
!ll&&!rl&&r
000
not $supports_catalog or $pk_info->{"TABLE_CAT"} eq $catalog
l!l&&r!l&&!r
000
MC/DC0%0/4
!$supports_catalog || $pk_info->{"TABLE_CAT"} eq $catalog and $pk_info->{"TABLE_SCHEM"} eq $schema and $pk_info->{"TABLE_NAME"} eq $table
not $supports_catalog $pk_info->{"TABLE_CAT"} eq $catalog $pk_info->{"TABLE_SCHEM"} eq $schema $pk_info->{"TABLE_NAME"} eq $table
Truth table0%0/7
not(A) or B and C and D
A= not $supports_catalogB= $pk_info->{"TABLE_CAT"} eq $catalogC= $pk_info->{"TABLE_SCHEM"} eq $schemaD= $pk_info->{"TABLE_NAME"} eq $table
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
1567 }
1568  
1569 0 ▶ unless(defined $pk_info->{'COLUMN_NAME'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pk_info->{"COLUMN_NAME"}) 0 0 0
1570 {
1571 0 Carp::croak "Could not extract column name from DBI primary_key_info()";
1572 }
1573  
1574 0 push(@columns, $self->unquote_column_name($pk_info->{'COLUMN_NAME'}));
1575 }
1576  
1577 0 return \@columns;
1578 }
1579  
1580 #
1581 # These methods could/should be overridden in driver-specific subclasses
1582 #
1583  
1584 0 ▶sub insertid_param { undef }
Subroutine insertid_param: not called CC=1 SCAR=6.9
Pod documented
1585 0 ▶sub null_date { '0000-00-00' }
Subroutine null_date: not called CC=1 SCAR=6.9
Pod undocumented
1586 0 ▶sub null_datetime { '0000-00-00 00:00:00' }
Subroutine null_datetime: not called CC=1 SCAR=6.9
Pod undocumented
1587 0 ▶sub null_timestamp { '00000000000000' }
Subroutine null_timestamp: not called CC=1 SCAR=6.9
Pod undocumented
1588 0 ▶sub min_timestamp { '00000000000000' }
Subroutine min_timestamp: not called CC=1 SCAR=6.9
Pod undocumented
1589 0 ▶sub max_timestamp { '00000000000000' }
Subroutine max_timestamp: not called CC=1 SCAR=6.9
Pod undocumented
1590  
1591 0 ▶sub last_insertid_from_sth { $_[1]->{$_[0]->insertid_param} }
Subroutine last_insertid_from_sth: not called CC=1 SCAR=6.9
Pod documented
1592 0 ▶sub generate_primary_key_values { (undef) x ($_[1] || 1) }
Subroutine generate_primary_key_values: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$_[1] || 1
l!l
00
MC/DC0%0/1
$_[1] || 1
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
1593 0 ▶sub generate_primary_key_placeholders { (undef) x ($_[1] || 1) }
Subroutine generate_primary_key_placeholders: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$_[1] || 1
l!l
00
MC/DC0%0/1
$_[1] || 1
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
1594  
1595 0 ▶sub max_column_name_length { 255 }
Subroutine max_column_name_length: not called CC=1 SCAR=6.9
Pod undocumented
1596 0 ▶sub max_column_alias_length { 255 }
Subroutine max_column_alias_length: not called CC=1 SCAR=6.9
Pod undocumented
1597  
1598 # Boolean formatting and parsing
1599  
1600 0 ▶sub format_boolean { $_[1] ? 1 : 0 }
Subroutine format_boolean: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
1601  
1602 sub parse_boolean
1603 0 ▶{
Subroutine parse_boolean: not called CC=6 SCAR=37.4
Pod documented
1604 0 my($self, $value) = @_;
1605  
1606 0 ▶ return $value if($self->validate_boolean_keyword($_[1]) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->validate_boolean_keyword($_[1]) or $self->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/6
$self->validate_boolean_keyword($_[1]) or $self->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$self->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/3
$self->validate_boolean_keyword($_[1]) or $self->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
$self->validate_boolean_keyword($_[1]) $self->keyword_function_calls $_[1] =~ /^\w+\(.*\)$/
Truth table0%0/4
A or B and C
A= $self->validate_boolean_keyword($_[1])B= $self->keyword_function_callsC= $_[1] =~ /^\w+\(.*\)$/
ABCresult
1XX1
0111
00X0
0100
1607 ($self->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/));
1608 0 ▶ return 1 if($value =~ /^(?:t(?:rue)?|y(?:es)?|1)$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(?:t(?:rue)?|y(?:es)?|1)$/i 0 0 0
1609 0 ▶ return 0 if($value =~ /^(?:f(?:alse)?|no?|0)$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(?:f(?:alse)?|no?|0)$/i 0 0 0
1610  
1611 0 $self->error("Invalid boolean value: '$value'");
1612 0 return undef;
1613 }
1614  
1615 # Date formatting
1616  
1617 sub format_date
1618 0 ▶{
Subroutine format_date: not called CC=4 SCAR=30.0
Pod documented
1619 0 my($self, $date) = @_;
1620 0 ▶ return $date
Branch: 1 branch
BranchTrueFalseTotal
if $self->validate_date_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/6
$self->validate_date_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/3
$self->validate_date_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
$self->validate_date_keyword($date) $self->keyword_function_calls $date =~ /^\w+\(.*\)$/
Truth table0%0/4
A or B and C
A= $self->validate_date_keyword($date)B= $self->keyword_function_callsC= $date =~ /^\w+\(.*\)$/
ABCresult
1XX1
0111
00X0
0100
1621 if($self->validate_date_keyword($date) ||
1622 ($self->keyword_function_calls && $date =~ /^\w+\(.*\)$/));
1623 0 return $self->date_handler->format_date($date);
1624 }
1625  
1626 sub format_datetime
1627 0 ▶{
Subroutine format_datetime: not called CC=4 SCAR=30.0
Pod documented
1628 0 my($self, $date) = @_;
1629 0 ▶ return $date if($self->validate_datetime_keyword($date) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->validate_datetime_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/6
$self->validate_datetime_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/3
$self->validate_datetime_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
$self->validate_datetime_keyword($date) $self->keyword_function_calls $date =~ /^\w+\(.*\)$/
Truth table0%0/4
A or B and C
A= $self->validate_datetime_keyword($date)B= $self->keyword_function_callsC= $date =~ /^\w+\(.*\)$/
ABCresult
1XX1
0111
00X0
0100
1630 ($self->keyword_function_calls && $date =~ /^\w+\(.*\)$/));
1631 0 return $self->date_handler->format_datetime($date);
1632 }
1633  
1634 17 ▶use constant HHMMSS_PRECISION => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
1635 17 ▶use constant HHMM_PRECISION => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
1636  
1637 sub format_time
1638 24 ▶{
Subroutine format_time: called CC=8 SCAR=33.4
Pod documented
1639 24 my($self, $time, $precision) = @_;
1640 24 ▶ return $time if($self->validate_time_keyword($time) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->validate_time_keyword($time) or $self->keyword_function_calls and $time =~ /^\w+\(.*\)$/ 0 24 24
Condition33%2/6
$self->validate_time_keyword($time) or $self->keyword_function_calls and $time =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
0024
$self->keyword_function_calls and $time =~ /^\w+\(.*\)$/
!ll&&!rl&&r
2400
MC/DC0%0/3
$self->validate_time_keyword($time) or $self->keyword_function_calls and $time =~ /^\w+\(.*\)$/
$self->validate_time_keyword($time) $self->keyword_function_calls $time =~ /^\w+\(.*\)$/
Truth table25%1/4
A or B and C
A= $self->validate_time_keyword($time)B= $self->keyword_function_callsC= $time =~ /^\w+\(.*\)$/
ABCresult
1XX1
0111
00X0
0100
1641 ($self->keyword_function_calls && $time =~ /^\w+\(.*\)$/));
1642  
1643 24 ▶ if(defined $precision)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $precision) 0 24 24
1644 {
1645 0 ▶ if($precision > HHMMSS_PRECISION)
Branch: 3 branches
BranchTrueFalseTotal
if ($precision > 6) { } 0 0 0
elsif ($precision == 6) { } 0 0 0
elsif ($precision == 4) { } 0 0 0
1646 {
1647 0 my $scale = $precision - HHMMSS_PRECISION;
1648 0 return $time->format("%H:%M:%S%${scale}n");
1649 }
1650 elsif($precision == HHMMSS_PRECISION)
1651 {
1652 0 return $time->format("%H:%M:%S");
1653 }
1654 elsif($precision == HHMM_PRECISION)
1655 {
1656 0 return $time->format("%H:%M");
1657 }
1658 }
1659  
1660 # Punt
1661 24 return $time->as_string;
1662 }
1663  
1664 sub format_timestamp
1665 0 ▶{
Subroutine format_timestamp: not called CC=4 SCAR=30.0
Pod documented
1666 0 my($self, $date) = @_;
1667 0 ▶ return $date if($self->validate_timestamp_keyword($date) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->validate_timestamp_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/6
$self->validate_timestamp_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/3
$self->validate_timestamp_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
$self->validate_timestamp_keyword($date) $self->keyword_function_calls $date =~ /^\w+\(.*\)$/
Truth table0%0/4
A or B and C
A= $self->validate_timestamp_keyword($date)B= $self->keyword_function_callsC= $date =~ /^\w+\(.*\)$/
ABCresult
1XX1
0111
00X0
0100
1668 ($self->keyword_function_calls && $date =~ /^\w+\(.*\)$/));
1669 0 return $self->date_handler->format_timestamp($date);
1670 }
1671  
1672 sub format_timestamp_with_time_zone
1673 0 ▶{
Subroutine format_timestamp_with_time_zone: not called CC=4 SCAR=30.0
Pod documented
1674 0 my($self, $date) = @_;
1675 0 ▶ return $date if($self->validate_timestamp_keyword($date) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->validate_timestamp_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/6
$self->validate_timestamp_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/3
$self->validate_timestamp_keyword($date) or $self->keyword_function_calls and $date =~ /^\w+\(.*\)$/
$self->validate_timestamp_keyword($date) $self->keyword_function_calls $date =~ /^\w+\(.*\)$/
Truth table0%0/4
A or B and C
A= $self->validate_timestamp_keyword($date)B= $self->keyword_function_callsC= $date =~ /^\w+\(.*\)$/
ABCresult
1XX1
0111
00X0
0100
1676 ($self->keyword_function_calls && $date =~ /^\w+\(.*\)$/));
1677 0 return $self->date_handler->format_timestamp_with_time_zone($date);
1678 }
1679  
1680 # Date parsing
1681  
1682 sub parse_date
1683 0 ▶{
Subroutine parse_date: not called CC=4 SCAR=30.0
Pod documented
1684 0 my($self, $value) = @_;
1685  
1686 0 ▶ if(UNIVERSAL::isa($value, 'DateTime') || $self->validate_date_keyword($value))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "DateTime") or $self->validate_date_keyword($value)) 0 0 0
Condition0%0/3
UNIVERSAL::isa($value, "DateTime") or $self->validate_date_keyword($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($value, "DateTime") or $self->validate_date_keyword($value)
UNIVERSAL::isa($value, "DateTime") $self->validate_date_keyword($value)
Truth table0%0/3
A or B
A= UNIVERSAL::isa($value, "DateTime")B= $self->validate_date_keyword($value)
ABresult
1X1
011
000
1687 {
1688 0 return $value;
1689 }
1690  
1691 0 my($dt, $error);
1692  
1693 TRY:
1694 {
1695 0 local $@;
1696 0 eval { $dt = $self->date_handler->parse_date($value) };
1697 0 $error = $@;
1698 }
1699  
1700 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1701 {
1702 0 $self->error("Could not parse date '$value' - $error");
1703 0 return undef;
1704 }
1705  
1706 0 return $dt;
1707 }
1708  
1709 sub parse_datetime
1710 0 ▶{
Subroutine parse_datetime: not called CC=4 SCAR=30.0
Pod documented
1711 0 my($self, $value) = @_;
1712  
1713 0 ▶ if(UNIVERSAL::isa($value, 'DateTime') ||
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "DateTime") or $self->validate_datetime_keyword($value)) 0 0 0
Condition0%0/3
UNIVERSAL::isa($value, "DateTime") or $self->validate_datetime_keyword($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($value, "DateTime") or $self->validate_datetime_keyword($value)
UNIVERSAL::isa($value, "DateTime") $self->validate_datetime_keyword($value)
Truth table0%0/3
A or B
A= UNIVERSAL::isa($value, "DateTime")B= $self->validate_datetime_keyword($value)
ABresult
1X1
011
000
1714 $self->validate_datetime_keyword($value))
1715 {
1716 0 return $value;
1717 }
1718  
1719 0 my($dt, $error);
1720  
1721 TRY:
1722 {
1723 0 local $@;
1724 0 eval { $dt = $self->date_handler->parse_datetime($value) };
1725 0 $error = $@;
1726 }
1727  
1728 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1729 {
1730 0 $self->error("Could not parse datetime '$value' - $error");
1731 0 return undef;
1732 }
1733  
1734 0 return $dt;
1735 }
1736  
1737 sub parse_timestamp
1738 0 ▶{
Subroutine parse_timestamp: not called CC=4 SCAR=30.0
Pod documented
1739 0 my($self, $value) = @_;
1740  
1741 0 ▶ if(UNIVERSAL::isa($value, 'DateTime') ||
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "DateTime") or $self->validate_timestamp_keyword($value)) 0 0 0
Condition0%0/3
UNIVERSAL::isa($value, "DateTime") or $self->validate_timestamp_keyword($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($value, "DateTime") or $self->validate_timestamp_keyword($value)
UNIVERSAL::isa($value, "DateTime") $self->validate_timestamp_keyword($value)
Truth table0%0/3
A or B
A= UNIVERSAL::isa($value, "DateTime")B= $self->validate_timestamp_keyword($value)
ABresult
1X1
011
000
1742 $self->validate_timestamp_keyword($value))
1743 {
1744 0 return $value;
1745 }
1746  
1747 0 my($dt, $error);
1748  
1749 TRY:
1750 {
1751 0 local $@;
1752 0 eval { $dt = $self->date_handler->parse_timestamp($value) };
1753 0 $error = $@;
1754 }
1755  
1756 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1757 {
1758 0 $self->error("Could not parse timestamp '$value' - $error");
1759 0 return undef;
1760 }
1761  
1762 0 return $dt;
1763 }
1764  
1765 sub parse_timestamp_with_time_zone
1766 0 ▶{
Subroutine parse_timestamp_with_time_zone: not called CC=4 SCAR=30.0
Pod documented
1767 0 my($self, $value) = @_;
1768  
1769 0 ▶ if(UNIVERSAL::isa($value, 'DateTime') ||
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "DateTime") or $self->validate_timestamp_keyword($value)) 0 0 0
Condition0%0/3
UNIVERSAL::isa($value, "DateTime") or $self->validate_timestamp_keyword($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($value, "DateTime") or $self->validate_timestamp_keyword($value)
UNIVERSAL::isa($value, "DateTime") $self->validate_timestamp_keyword($value)
Truth table0%0/3
A or B
A= UNIVERSAL::isa($value, "DateTime")B= $self->validate_timestamp_keyword($value)
ABresult
1X1
011
000
1770 $self->validate_timestamp_keyword($value))
1771 {
1772 0 return $value;
1773 }
1774  
1775 0 my($dt, $error);
1776  
1777 TRY:
1778 {
1779 0 local $@;
1780 0 eval { $dt = $self->date_handler->parse_timestamp_with_time_zone($value) };
1781 0 $error = $@;
1782 }
1783  
1784 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1785 {
1786 0 $self->error("Could not parse timestamp with time zone '$value' - $error");
1787 0 return undef;
1788 }
1789  
1790 0 return $dt;
1791 }
1792  
1793 sub parse_time
1794 30 ▶{
Subroutine parse_time: called CC=8 SCAR=22.9
Pod documented
1795 30 my($self, $value) = @_;
1796  
1797 30 ▶ if(!defined $value || UNIVERSAL::isa($value, 'Time::Clock') ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or UNIVERSAL::isa($value, "Time::Clock") or $self->validate_time_keyword($value) or $self->keyword_function_calls and $value =~ /^\w+\(.*\)$/) 0 30 30
Condition33%4/12
not defined $value or UNIVERSAL::isa($value, "Time::Clock") or $self->validate_time_keyword($value) or $self->keyword_function_calls and $value =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
0030
not defined $value or UNIVERSAL::isa($value, "Time::Clock") or $self->validate_time_keyword($value)
l!l&&r!l&&!r
0030
not defined $value or UNIVERSAL::isa($value, "Time::Clock")
l!l&&r!l&&!r
0030
$self->keyword_function_calls and $value =~ /^\w+\(.*\)$/
!ll&&!rl&&r
3000
MC/DC0%0/5
not defined $value or UNIVERSAL::isa($value, "Time::Clock") or $self->validate_time_keyword($value) or $self->keyword_function_calls and $value =~ /^\w+\(.*\)$/
not defined $value UNIVERSAL::isa($value, "Time::Clock") $self->validate_time_keyword($value) $self->keyword_function_calls $value =~ /^\w+\(.*\)$/
Truth table16%1/6
not(A) or B or C or D and E
A= not defined $valueB= UNIVERSAL::isa($value, "Time::Clock")C= $self->validate_time_keyword($value)D= $self->keyword_function_callsE= $value =~ /^\w+\(.*\)$/
ABCDEresult
1XXXX1
01XXX1
001XX1
000111
0000X0
000100
1798 $self->validate_time_keyword($value) ||
1799 ($self->keyword_function_calls && $value =~ /^\w+\(.*\)$/))
1800 {
1801 0 return $value;
1802 }
1803  
1804 30 my($time, $error);
1805  
1806 TRY:
1807 {
1808 30 local $@;
1809 30 eval { $time = Time::Clock->new->parse($value) };
1810 30 $error = $@;
1811 }
1812  
1813 30 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 6 24 30
1814 {
1815 6 my $second_error;
1816  
1817 TRY:
1818 {
1819 6 local $@;
1820  
1821 eval
1822 6 {
1823 6 my $dt = $self->date_handler->parse_time($value);
1824 # Using parse()/strftime() is faster than using the
1825 # Time::Clock constructor and the DateTime accessors.
1826 0 $time = Time::Clock->new->parse($dt->strftime('%H:%M:%S.%N'));
1827 };
1828  
1829 6 $second_error = $@;
1830 }
1831  
1832 6 ▶ if($second_error)
Branch: 1 branch
BranchTrueFalseTotal
if ($second_error) 6 0 6
1833 {
1834 6 $self->error("Could not parse time '$value' - Time::Clock::parse() failed " .
1835 "($error) and $second_error");
1836 6 return undef;
1837 }
1838 }
1839  
1840 24 return $time;
1841 }
1842  
1843 sub parse_bitfield
1844 0 ▶{
Subroutine parse_bitfield: not called CC=15 SCAR=54.8
Pod documented
1845 0 my($self, $val, $size) = @_;
1846  
1847 0 ▶ return undef unless(defined $val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1848  
1849 0 ▶ if(ref $val)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) 0 0 0
1850 {
1851 0 ▶ if($size && $val->Size != $size)
Branch: 1 branch
BranchTrueFalseTotal
if ($size and $val->Size != $size) 0 0 0
Condition0%0/3
$size and $val->Size != $size
!ll&&!rl&&r
000
MC/DC0%0/2
$size and $val->Size != $size
$size $val->Size != $size
Truth table0%0/3
A and B
A= $sizeB= $val->Size != $size
ABresult
0X0
100
111
1852 {
1853 0 return Bit::Vector->new_Bin($size, $val->to_Bin);
1854 }
1855  
1856 0 return $val;
1857 }
1858  
1859 0 ▶ if($val =~ /^[10]+$/)
Branch: 4 branches
BranchTrueFalseTotal
if ($val =~ /^[10]+$/) { } 0 0 0
elsif ($val =~ /^\d*[2-9]\d*$/) { } 0 0 0
elsif ($val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/ or $val =~ /^[0-9a-f]+$/i) { } 0 0 0
elsif ($val =~ s/^B'([10]+)'$/$1/i) { } 0 0 0
1860 {
1861 0 ▶ return Bit::Vector->new_Bin($size || length $val, $val);
Condition0%0/3
$size || length $val
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length $val
$size length $val
Truth table0%0/3
A || B
A= $sizeB= length $val
ABresult
1X1
011
000
1862 }
1863 elsif($val =~ /^\d*[2-9]\d*$/)
1864 {
1865 0 ▶ return Bit::Vector->new_Dec($size || (length($val) * 4), $val);
Condition0%0/3
$size || length($val) * 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length($val) * 4
$size length($val) * 4
Truth table0%0/3
A || B
A= $sizeB= length($val) * 4
ABresult
1X1
011
000
1866 }
1867 ▶ elsif($val =~ s/^0x// || $val =~ s/^X'(.*)'$/$1/ || $val =~ /^[0-9a-f]+$/i)
Condition0%0/6
$val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/ or $val =~ /^[0-9a-f]+$/i
l!l&&r!l&&!r
000
$val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/
l!l&&r!l&&!r
000
MC/DC0%0/3
$val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/ or $val =~ /^[0-9a-f]+$/i
$val =~ s/^0x// $val =~ s/^X'(.*)'$/$1/ $val =~ /^[0-9a-f]+$/i
Truth table0%0/4
A or B or C
A= $val =~ s/^0x//B= $val =~ s/^X'(.*)'$/$1/C= $val =~ /^[0-9a-f]+$/i
ABCresult
1XX1
01X1
0011
0000
1868 {
1869 0 ▶ return Bit::Vector->new_Hex($size || (length($val) * 4), $val);
Condition0%0/3
$size || length($val) * 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length($val) * 4
$size length($val) * 4
Truth table0%0/3
A || B
A= $sizeB= length($val) * 4
ABresult
1X1
011
000
1870 }
1871 elsif($val =~ s/^B'([10]+)'$/$1/i)
1872 {
1873 0 ▶ return Bit::Vector->new_Bin($size || length $val, $val);
Condition0%0/3
$size || length $val
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length $val
$size length $val
Truth table0%0/3
A || B
A= $sizeB= length $val
ABresult
1X1
011
000
1874 }
1875 else
1876 {
1877 0 $self->error("Could not parse bitfield value '$val'");
1878 0 return undef;
1879 #return Bit::Vector->new_Bin($size || length($val), $val);
1880 }
1881 }
1882  
1883 sub format_bitfield
1884 0 ▶{
Subroutine format_bitfield: not called CC=2 SCAR=17.9
Pod documented
1885 0 my($self, $vec, $size) = @_;
1886  
1887 0 ▶ if($size)
Branch: 1 branch
BranchTrueFalseTotal
if ($size) 0 0 0
1888 {
1889 0 $vec = Bit::Vector->new_Bin($size, $vec->to_Bin);
1890 0 return sprintf('%0*b', $size, hex($vec->to_Hex));
1891 }
1892  
1893 0 return sprintf('%b', hex($vec->to_Hex));
1894 }
1895  
1896 0 ▶sub select_bitfield_column_sql { shift->auto_quote_column_with_table(@_) }
Subroutine select_bitfield_column_sql: not called CC=1 SCAR=6.9
Pod undocumented
1897  
1898 sub parse_array
1899 0 ▶{
Subroutine parse_array: not called CC=8 SCAR=42.8
Pod undocumented
1900 0 my($self) = shift;
1901  
1902 0 ▶ return $_[0] if(ref $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1903 0 ▶ return [ @_ ] if(@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
1904  
1905 0 my $val = $_[0];
1906  
1907 0 ▶ return undef unless(defined $val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1908  
1909 0 $val =~ s/^ (?:\[.+\]=)? \{ (.*) \} $/$1/sx;
1910  
1911 0 my @array;
1912  
1913 0 ▶ while($val =~ s/(?:"((?:[^"\\]+|\\.)*)"|([^",]+))(?:,|$)//)
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s/(?:"((?:[^"\\]+|\\.)*)"|([^",]+))(?:,|$)//) 0 0 0
1914 {
1915 0 ▶ my($item) = map { $_ eq 'NULL' ? undef : $_ } (defined $1 ? $1 : $2);
Branch: 2 branches
BranchTrueFalseTotal
$_ eq 'NULL' ? : 0 0 0
defined $1 ? : 0 0 0
1916 0 ▶ $item =~ s{\\(.)}{$1}g if(defined $item);
Branch: 1 branch
BranchTrueFalseTotal
if defined $item 0 0 0
1917 0 push(@array, $item);
1918 }
1919  
1920 0 return \@array;
1921 }
1922  
1923 sub format_array
1924 0 ▶{
Subroutine format_array: not called CC=7 SCAR=40.3
Pod undocumented
1925 0 my($self) = shift;
1926  
1927 0 ▶ return undef unless(ref $_[0] || defined $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] or defined $_[0] 0 0 0
Condition0%0/3
ref $_[0] or defined $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] or defined $_[0]
ref $_[0] defined $_[0]
Truth table0%0/3
A or B
A= ref $_[0]B= defined $_[0]
ABresult
1X1
011
000
1928  
1929 0 ▶ my @array = (ref $_[0]) ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
1930  
1931 my $str = '{' . join(',', map
1932 {
1933 0 ▶ if(!defined $_)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $_) { } 0 0 0
elsif (/^[-+]?\d+(?:\.\d*)?$/) { } 0 0 0
1934 {
1935 0 'NULL'
1936 }
1937 elsif(/^[-+]?\d+(?:\.\d*)?$/)
1938 {
1939 0 $_
1940 }
1941 else
1942 {
1943 0 s/\\/\\\\/g;
1944 0 s/"/\\"/g;
1945 0 qq("$_")
1946 }
1947 } @array) . '}';
1948  
1949 0 ▶ if(length($str) > $self->max_array_characters)
Branch: 1 branch
BranchTrueFalseTotal
if (length $str > $self->max_array_characters) 0 0 0
1950 {
1951 0 Carp::croak "Array string is longer than ", ref($self),
1952 "->max_array_characters (", $self->max_array_characters,
1953 ") characters long: $str";
1954 }
1955  
1956 0 return $str;
1957 }
1958  
1959 17 my $Interval_Regex = qr{
1960 (?:\@\s*)?
1961 (?:
1962 (?: (?: \s* ([+-]?) (\d+) : ([0-5]?\d)? (?:: ([0-5]?\d (?:\.\d+)? )? )?)) # (sign)hhh:mm:ss
1963 |
1964 (?: \s* ( [+-]? \d+ (?:\.\d+(?=\s+s))? ) \s+ # quantity
1965 (?: # unit
1966 (?:\b(dec) (?:ades?\b | s?\b)?\b) # decades
1967 | (?:\b(d) (?:ays?\b)?\b) # days
1968 | (?:\b(y) (?:ears?\b)?\b) # years
1969 | (?:\b(h) (?:ours?\b)?\b) # hours
1970 | (?:\b(mon) (?:s\b | ths?\b)?\b) # months
1971 | (?:\b(mil) (?:s\b | lenniums?\b)?\b) # millenniums
1972 | (?:\b(m) (?:inutes?\b | ins?\b)?\b) # minutes
1973 | (?:\b(s) (?:ec(?:s | onds?)?)?\b) # seconds
1974 | (?:\b(w) (?:eeks?\b)?\b) # weeks
1975 | (?:\b(c) (?:ent(?:s | ury | uries)?\b)?\b) # centuries
1976 )
1977 )
1978 )
1979 (?: \s+ (ago) \b)? # direction
1980 | (.+)
1981 }ix;
1982  
1983 sub parse_interval
1984 76 ▶{
Subroutine parse_interval: called CC=66 SCAR=49.4
Pod documented
1985 76 my($self, $value, $end_of_month_mode) = @_;
1986  
1987 76 ▶ if(!defined $value || UNIVERSAL::isa($value, 'DateTime::Duration') ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or UNIVERSAL::isa($value, "DateTime::Duration") or $self->validate_interval_keyword($value) or $self->keyword_function_calls and $value =~ /^\w+\(.*\)$/) 2 74 76
Condition58%7/12
not defined $value or UNIVERSAL::isa($value, "DateTime::Duration") or $self->validate_interval_keyword($value) or $self->keyword_function_calls and $value =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
0274
not defined $value or UNIVERSAL::isa($value, "DateTime::Duration") or $self->validate_interval_keyword($value)
l!l&&r!l&&!r
0076
not defined $value or UNIVERSAL::isa($value, "DateTime::Duration")
l!l&&r!l&&!r
0076
$self->keyword_function_calls and $value =~ /^\w+\(.*\)$/
!ll&&!rl&&r
2722
MC/DC40%2/5
not defined $value or UNIVERSAL::isa($value, "DateTime::Duration") or $self->validate_interval_keyword($value) or $self->keyword_function_calls and $value =~ /^\w+\(.*\)$/
not defined $value UNIVERSAL::isa($value, "DateTime::Duration") $self->validate_interval_keyword($value) $self->keyword_function_calls $value =~ /^\w+\(.*\)$/
Truth table50%3/6
not(A) or B or C or D and E
A= not defined $valueB= UNIVERSAL::isa($value, "DateTime::Duration")C= $self->validate_interval_keyword($value)D= $self->keyword_function_callsE= $value =~ /^\w+\(.*\)$/
ABCDEresult
1XXXX1
01XXX1
001XX1
000111
0000X0
000100
1988 $self->validate_interval_keyword($value) ||
1989 ($self->keyword_function_calls && $value =~ /^\w+\(.*\)$/))
1990 {
1991 2 return $value;
1992 }
1993  
1994 74 for($value)
1995 {
1996 74 s/\A //;
1997 74 s/ \z//;
1998 74 s/\s+/ /g;
1999 }
2000  
2001 74 my(%units, $is_ago, $sign, $error, $dt_duration);
2002  
2003 74 my $value_pos;
2004  
2005 74 ▶ while(!$error && $value =~ /$Interval_Regex/go)
Branch: 1 branch
BranchTrueFalseTotal
if (not $error and $value =~ /$Interval_Regex/go) 218 40 258
Condition66%2/3
not $error and $value =~ /$Interval_Regex/go
!ll&&!rl&&r
040218
MC/DC50%1/2
not $error and $value =~ /$Interval_Regex/go
not $error $value =~ /$Interval_Regex/go
Truth table66%2/3
not(A) and B
A= not $errorB= $value =~ /$Interval_Regex/go
ABresult
0X0
100
111
2006 {
2007 218 $value_pos = pos($value);
2008  
2009 218 ▶ $is_ago = 1 if($16);
Branch: 1 branch
BranchTrueFalseTotal
if $16 12 206 218
2010  
2011 218 ▶ if($2 || $3 || $4)
Branch: 12 branches
BranchTrueFalseTotal
if ($2 or $3 or $4) { } 22 196 218
elsif ($6) { } 10 186 196
elsif (defined $7) { } 28 158 186
elsif (defined $8) { } 20 138 158
elsif (defined $9) { } 18 120 138
elsif (defined $10) { } 14 106 120
elsif (defined $11) { } 14 92 106
elsif (defined $12) { } 22 70 92
elsif (defined $13) { } 26 44 70
elsif (defined $14) { } 10 34 44
elsif (defined $15) { } 10 24 34
elsif (defined $17) { } 22 2 24
Condition83%5/6
$2 or $3 or $4
l!l&&r!l&&!r
220196
$2 or $3
l!l&&r!l&&!r
202196
MC/DC66%2/3
$2 or $3 or $4
$2 $3 $4
Truth table75%3/4
A or B or C
A= $2B= $3C= $4
ABCresult
1XX1
01X1
0011
0000
2012 {
2013 22 ▶ if($sign || defined $units{'hours'} || defined $units{'minutes'} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($sign or defined $units{"hours"} or defined $units{"minutes"} or defined $units{"seconds"}) 10 12 22
Condition88%8/9
$sign or defined $units{"hours"} or defined $units{"minutes"} or defined $units{"seconds"}
l!l&&r!l&&!r
8212
$sign or defined $units{"hours"} or defined $units{"minutes"}
l!l&&r!l&&!r
8014
$sign or defined $units{"hours"}
l!l&&r!l&&!r
6214
MC/DC75%3/4
$sign or defined $units{"hours"} or defined $units{"minutes"} or defined $units{"seconds"}
$sign defined $units{"hours"} defined $units{"minutes"} defined $units{"seconds"}
Truth table80%4/5
A or B or C or D
A= $signB= defined $units{"hours"}C= defined $units{"minutes"}D= defined $units{"seconds"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2014 defined $units{'seconds'})
2015 {
2016 10 $error = 1;
2017 10 last;
2018 }
2019  
2020 12 ▶ $sign = ($1 && $1 eq '-') ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$1 && $1 eq '-' ? : 2 10 12
Condition66%2/3
$1 and $1 eq "-"
!ll&&!rl&&r
1002
MC/DC50%1/2
$1 and $1 eq "-"
$1 $1 eq "-"
Truth table66%2/3
A and B
A= $1B= $1 eq "-"
ABresult
0X0
100
111
2021  
2022 12 my $secs = $4;
2023  
2024 12 ▶ if(defined $secs && $secs != int($secs))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $secs and $secs != int $secs) 0 12 12
Condition33%1/3
defined $secs and $secs != int $secs
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $secs and $secs != int $secs
defined $secs $secs != int $secs
Truth table33%1/3
A and B
A= defined $secsB= $secs != int $secs
ABresult
0X0
100
111
2025 {
2026 0 my $fsecs = substr($secs, index($secs, '.') + 1);
2027 0 $secs = int($secs);
2028  
2029 0 my $len = length $fsecs;
2030  
2031 0 ▶ if($len < 9)
Branch: 2 branches
BranchTrueFalseTotal
if ($len < 9) { } 0 0 0
elsif ($len > 9) { } 0 0 0
2032 {
2033 0 $fsecs .= ('0' x (9 - length $fsecs));
2034 }
2035 elsif($len > 9)
2036 {
2037 0 $fsecs = substr($fsecs, 0, 9);
2038 }
2039  
2040 0 $units{'nanoseconds'} = $sign * $fsecs;
2041 }
2042  
2043 12 ▶ $units{'hours'} = $sign * ($2 || 0);
Condition100%2/2
$2 || 0
l!l
102
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
2044 12 ▶ $units{'minutes'} = $sign * ($3 || 0);
Condition100%2/2
$3 || 0
l!l
66
MC/DC100%1/1
$3 || 0
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
2045 12 ▶ $units{'seconds'} = $sign * ($secs || 0);
Condition50%1/2
$secs || 0
l!l
012
MC/DC0%0/1
$secs || 0
$secs
Truth table50%1/2
A
A= $secs
Aresult
11
00
2046 }
2047 elsif($6)
2048 {
2049 0 ▶ if($units{'decades'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"decades"}) 0 10 10
2050 10 $units{'decades'} = $5;
2051 }
2052 elsif(defined $7)
2053 {
2054 28 ▶ if($units{'days'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"days"}) 2 26 28
2055 26 $units{'days'} = $5;
2056 }
2057 elsif(defined $8)
2058 {
2059 0 ▶ if($units{'years'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"years"}) 0 20 20
2060 20 $units{'years'} = $5;
2061 }
2062 elsif(defined $9)
2063 {
2064 0 ▶ if($units{'hours'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"hours"}) 0 18 18
2065 18 $units{'hours'} = $5;
2066 }
2067 elsif(defined $10)
2068 {
2069 0 ▶ if($units{'months'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"months"}) 0 14 14
2070 14 $units{'months'} = $5;
2071 }
2072 elsif(defined $11)
2073 {
2074 0 ▶ if($units{'millenniums'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"millenniums"}) 0 14 14
2075 14 $units{'millenniums'} = $5;
2076 }
2077 elsif(defined $12)
2078 {
2079 0 ▶ if($units{'minutes'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"minutes"}) 0 22 22
2080 22 $units{'minutes'} = $5;
2081 }
2082 elsif(defined $13)
2083 {
2084 0 ▶ if($units{'seconds'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"seconds"}) 0 26 26
2085  
2086 26 my $secs = $5;
2087  
2088 26 $units{'seconds'} = int($secs);
2089  
2090 26 ▶ if($units{'seconds'} != $secs)
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"seconds"} != $secs) 2 24 26
2091 {
2092 2 my $fsecs = substr($secs, index($secs, '.') + 1);
2093  
2094 2 my $len = length $fsecs;
2095  
2096 2 ▶ if($len < 9)
Branch: 2 branches
BranchTrueFalseTotal
if ($len < 9) { } 2 0 2
elsif ($len > 9) { } 0 0 0
2097 {
2098 2 $fsecs .= ('0' x (9 - length $fsecs));
2099 }
2100 elsif($len > 9)
2101 {
2102 0 $fsecs = substr($fsecs, 0, 9);
2103 }
2104  
2105 2 $units{'nanoseconds'} = $fsecs;
2106 }
2107 }
2108 elsif(defined $14)
2109 {
2110 0 ▶ if($units{'weeks'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"weeks"}) 0 10 10
2111 10 $units{'weeks'} = $5;
2112 }
2113 elsif(defined $15)
2114 {
2115 0 ▶ if($units{'centuries'}) { $error = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"centuries"}) 0 10 10
2116 10 $units{'centuries'} = $5;
2117 }
2118 elsif(defined $17)
2119 {
2120 22 $error = 1;
2121 22 last;
2122 }
2123 }
2124  
2125 74 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 34 40 74
2126 {
2127 34 $self->error("Could not parse interval '$value' - found overlaping time units");
2128 34 return undef;
2129 }
2130  
2131 40 ▶ if($value_pos != length($value))
Branch: 1 branch
BranchTrueFalseTotal
if ($value_pos != length $value) 0 40 40
2132 {
2133 0 $self->error("Could not parse interval '$value' - could not interpret all tokens");
2134 0 return undef;
2135 }
2136  
2137 40 ▶ if(defined $units{'millenniums'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $units{"millenniums"}) 14 26 40
2138 {
2139 14 $units{'years'} += 1000 * $units{'millenniums'};
2140 14 delete $units{'millenniums'};
2141 }
2142  
2143 40 ▶ if(defined $units{'centuries'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $units{"centuries"}) 10 30 40
2144 {
2145 10 $units{'years'} += 100 * $units{'centuries'};
2146 10 delete $units{'centuries'};
2147 }
2148  
2149 40 ▶ if(defined $units{'decades'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $units{"decades"}) 10 30 40
2150 {
2151 10 $units{'years'} += 10 * $units{'decades'};
2152 10 delete $units{'decades'};
2153 }
2154  
2155 40 ▶ if($units{'hours'} || $units{'minutes'} || $units{'seconds'})
Branch: 1 branch
BranchTrueFalseTotal
if ($units{"hours"} or $units{"minutes"} or $units{"seconds"}) 24 16 40
Condition100%6/6
$units{"hours"} or $units{"minutes"} or $units{"seconds"}
l!l&&r!l&&!r
22216
$units{"hours"} or $units{"minutes"}
l!l&&r!l&&!r
18418
MC/DC100%3/3
$units{"hours"} or $units{"minutes"} or $units{"seconds"}
$units{"hours"} $units{"minutes"} $units{"seconds"}
Truth table100%4/4
A or B or C
A= $units{"hours"}B= $units{"minutes"}C= $units{"seconds"}
ABCresult
1XX1
01X1
0011
0000
2156 {
2157 my $seconds = ($units{'hours'} || 0) * 60 * 60 +
2158 ($units{'minutes'} || 0) * 60 +
2159 24 ▶ ($units{'seconds'} || 0);
Condition100%6/6
$units{'hours'} || 0
l!l
186
$units{'minutes'} || 0
l!l
204
$units{'seconds'} || 0
l!l
204
MC/DC100%1/1
$units{'hours'} || 0
$units{'hours'}
MC/DC100%1/1
$units{'minutes'} || 0
$units{'minutes'}
MC/DC100%1/1
$units{'seconds'} || 0
$units{'seconds'}
Truth table100%2/2
A
A= $units{'hours'}
Aresult
11
00
Truth table100%2/2
A
A= $units{'minutes'}
Aresult
11
00
Truth table100%2/2
A
A= $units{'seconds'}
Aresult
11
00
2160 24 $units{'hours'} = int($seconds / 3600);
2161 24 $seconds -= $units{'hours'} * 3600;
2162 24 $units{'minutes'} = int($seconds / 60);
2163 24 $units{'seconds'} = $seconds - $units{'minutes'} * 60;
2164 }
2165  
2166 40 ▶ $units{'end_of_month'} = $end_of_month_mode if(defined $end_of_month_mode);
Branch: 1 branch
BranchTrueFalseTotal
if defined $end_of_month_mode 0 40 40
2167  
2168 40 ▶ $dt_duration = $is_ago ?
Branch: 1 branch
BranchTrueFalseTotal
$is_ago ? : 8 32 40
2169 DateTime::Duration->new(%units)->inverse :
2170 DateTime::Duration->new(%units);
2171  
2172 # XXX: Ugly hack workaround for DateTime::Duration bug (RT 53985)
2173 40 ▶ if($is_ago && defined $end_of_month_mode &&
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ago and defined $end_of_month_mode and $dt_duration->end_of_month_mode ne $end_of_month_mode) 0 40 40
Condition50%3/6
$is_ago and defined $end_of_month_mode and $dt_duration->end_of_month_mode ne $end_of_month_mode
!ll&&!rl&&r
4000
$is_ago and defined $end_of_month_mode
!ll&&!rl&&r
3280
MC/DC0%0/3
$is_ago and defined $end_of_month_mode and $dt_duration->end_of_month_mode ne $end_of_month_mode
$is_ago defined $end_of_month_mode $dt_duration->end_of_month_mode ne $end_of_month_mode
Truth table50%2/4
A and B and C
A= $is_agoB= defined $end_of_month_modeC= $dt_duration->end_of_month_mode ne $end_of_month_mode
ABCresult
0XX0
10X0
1100
1111
2174 $dt_duration->end_of_month_mode ne $end_of_month_mode)
2175 {
2176 0 $dt_duration->{'end_of_month'} = $end_of_month_mode;
2177 }
2178  
2179 40 return $dt_duration;
2180 }
2181  
2182 sub format_interval
2183 74 ▶{
Subroutine format_interval: called CC=36 SCAR=36.2
Pod documented
2184 74 my($self, $dur) = @_;
2185  
2186 74 ▶ if(!defined $dur || $self->validate_interval_keyword($dur) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dur or $self->validate_interval_keyword($dur) or $self->keyword_function_calls and $dur =~ /^\w+\(.*\)$/) 34 40 74
Condition66%6/9
not defined $dur or $self->validate_interval_keyword($dur) or $self->keyword_function_calls and $dur =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
34040
not defined $dur or $self->validate_interval_keyword($dur)
l!l&&r!l&&!r
34040
$self->keyword_function_calls and $dur =~ /^\w+\(.*\)$/
!ll&&!rl&&r
2380
MC/DC25%1/4
not defined $dur or $self->validate_interval_keyword($dur) or $self->keyword_function_calls and $dur =~ /^\w+\(.*\)$/
not defined $dur $self->validate_interval_keyword($dur) $self->keyword_function_calls $dur =~ /^\w+\(.*\)$/
Truth table60%3/5
not(A) or B or C and D
A= not defined $durB= $self->validate_interval_keyword($dur)C= $self->keyword_function_callsD= $dur =~ /^\w+\(.*\)$/
ABCDresult
1XXX1
01XX1
00111
000X0
00100
2187 ($self->keyword_function_calls && $dur =~ /^\w+\(.*\)$/))
2188 {
2189 34 return $dur;
2190 }
2191  
2192 40 my $output = '';
2193  
2194 40 my(%deltas, %unit, $neg);
2195  
2196 40 @deltas{qw/years mons days h m s/} =
2197 $dur->in_units(qw/years months days hours minutes seconds/);
2198  
2199 40 foreach (qw/years mons days/)
2200 {
2201 120 $unit{$_} = $_;
2202 120 ▶ $unit{$_} =~ s/s\z// if $deltas{$_} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $deltas{$_} == 1 8 112 120
2203 }
2204  
2205 40 ▶ $output .= "$deltas{'years'} $unit{'years'} " if($deltas{'years'});
Branch: 1 branch
BranchTrueFalseTotal
if $deltas{"years"} 18 22 40
2206 40 ▶ $neg = 1 if($deltas{'years'} < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $deltas{"years"} < 0 8 32 40
2207  
2208 40 ▶ $output .= '+' if ($neg && $deltas{'mons'} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $neg and $deltas{"mons"} > 0 0 40 40
Condition66%2/3
$neg and $deltas{"mons"} > 0
!ll&&!rl&&r
3280
MC/DC0%0/2
$neg and $deltas{"mons"} > 0
$neg $deltas{"mons"} > 0
Truth table66%2/3
A and B
A= $negB= $deltas{"mons"} > 0
ABresult
0X0
100
111
2209 40 ▶ $output .= "$deltas{'mons'} $unit{'mons'} " if($deltas{'mons'});
Branch: 1 branch
BranchTrueFalseTotal
if $deltas{"mons"} 14 26 40
2210 $neg = $deltas{'mons'} < 0 ? 1 :
2211 40 ▶ $deltas{'mons'} ? 0 :
Branch: 2 branches
BranchTrueFalseTotal
$deltas{'mons'} < 0 ? : 6 34 40
$deltas{'mons'} ? : 8 26 34
2212 $neg;
2213  
2214 40 ▶ $output .= '+' if($neg && $deltas{'days'} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $neg and $deltas{"days"} > 0 6 34 40
Condition100%3/3
$neg and $deltas{"days"} > 0
!ll&&!rl&&r
2866
MC/DC100%2/2
$neg and $deltas{"days"} > 0
$neg $deltas{"days"} > 0
Truth table100%3/3
A and B
A= $negB= $deltas{"days"} > 0
ABresult
0X0
100
111
2215 40 ▶ $output .= "$deltas{'days'} $unit{'days'} " if($deltas{'days'});
Branch: 1 branch
BranchTrueFalseTotal
if $deltas{"days"} 24 16 40
2216  
2217 40 ▶ if($deltas{'h'} || $deltas{'m'} || $deltas{'s'} || $dur->nanoseconds)
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"h"} or $deltas{"m"} or $deltas{"s"} or $dur->nanoseconds) 26 14 40
Condition100%9/9
$deltas{"h"} or $deltas{"m"} or $deltas{"s"} or $dur->nanoseconds
l!l&&r!l&&!r
24214
$deltas{"h"} or $deltas{"m"} or $deltas{"s"}
l!l&&r!l&&!r
22216
$deltas{"h"} or $deltas{"m"}
l!l&&r!l&&!r
20218
MC/DC100%4/4
$deltas{"h"} or $deltas{"m"} or $deltas{"s"} or $dur->nanoseconds
$deltas{"h"} $deltas{"m"} $deltas{"s"} $dur->nanoseconds
Truth table100%5/5
A or B or C or D
A= $deltas{"h"}B= $deltas{"m"}C= $deltas{"s"}D= $dur->nanoseconds
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2218 {
2219 $neg = $deltas{'days'} < 0 ? 1 :
2220 26 ▶ $deltas{'days'} ? 0 :
Branch: 2 branches
BranchTrueFalseTotal
$deltas{'days'} < 0 ? : 4 22 26
$deltas{'days'} ? : 8 14 22
2221 $neg;
2222  
2223 26 ▶ if($neg && (($deltas{'h'} > 0) || (!$deltas{'h'} && $deltas{'m'} > 0) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($neg and $deltas{"h"} > 0 || !$deltas{"h"} && $deltas{"m"} > 0 || !($deltas{"h"} || $deltas{"m"}) && $deltas{"s"} > 0) 4 22 26
Condition77%14/18
$neg and $deltas{"h"} > 0 || !$deltas{"h"} && $deltas{"m"} > 0 || !($deltas{"h"} || $deltas{"m"}) && $deltas{"s"} > 0
!ll&&!rl&&r
2024
$deltas{"h"} > 0 or not $deltas{"h"} and $deltas{"m"} > 0 or not $deltas{"h"} || $deltas{"m"} and $deltas{"s"} > 0
l!l&&r!l&&!r
222
$deltas{"h"} > 0 or not $deltas{"h"} and $deltas{"m"} > 0
l!l&&r!l&&!r
204
not $deltas{"h"} and $deltas{"m"} > 0
!ll&&!rl&&r
220
not $deltas{"h"} || $deltas{"m"} and $deltas{"s"} > 0
!ll&&!rl&&r
202
$deltas{'h'} || $deltas{'m'}
l!l&&r!l&&!r
202
MC/DC28%2/7
$neg and $deltas{"h"} > 0 || !$deltas{"h"} && $deltas{"m"} > 0 || !($deltas{"h"} || $deltas{"m"}) && $deltas{"s"} > 0
$neg $deltas{"h"} > 0 not $deltas{"h"} $deltas{"m"} > 0 $deltas{'h'} $deltas{'m'} $deltas{"s"} > 0
Truth table36%4/11
A and B or not(C) and D or not(E || F) and G
A= $negB= $deltas{"h"} > 0C= not $deltas{"h"}D= $deltas{"m"} > 0E= $deltas{'h'}F= $deltas{'m'}G= $deltas{"s"} > 0
ABCDEFGresult
0XXXXXX0
100X1XX0
100X01X0
100X0000
10101XX0
101001X0
10100000
11XXXXX1
1011XXX1
100X0011
10100011
2224 (!$deltas{'h'} && !$deltas{'m'} && $deltas{'s'} > 0)))
2225 {
2226 4 $output .= '+';
2227 }
2228  
2229 26 my $nsec = $dur->nanoseconds;
2230  
2231 26 ▶ $output .= '-' if(!$deltas{'h'} && ($deltas{'m'} < 0 || $deltas{'s'} < 0));
Branch: 1 branch
BranchTrueFalseTotal
if not $deltas{"h"} and $deltas{"m"} < 0 || $deltas{"s"} < 0 2 24 26
Condition83%5/6
not $deltas{"h"} and $deltas{"m"} < 0 || $deltas{"s"} < 0
!ll&&!rl&&r
2042
$deltas{"m"} < 0 or $deltas{"s"} < 0
l!l&&r!l&&!r
204
MC/DC66%2/3
not $deltas{"h"} and $deltas{"m"} < 0 || $deltas{"s"} < 0
not $deltas{"h"} $deltas{"m"} < 0 $deltas{"s"} < 0
Truth table75%3/4
not(A) and B or C
A= not $deltas{"h"}B= $deltas{"m"} < 0C= $deltas{"s"} < 0
ABCresult
0XX0
1000
11X1
1011
2232 26 @deltas{qw/m s/} = (abs($deltas{'m'}), abs($deltas{'s'}));
2233 52 ▶ $deltas{'hms'} = join(':', map { sprintf('%.2d', $deltas{$_}) } (qw/h m/)) .
Branch: 1 branch
BranchTrueFalseTotal
$nsec ? : 2 24 26
2234 ($nsec ? sprintf(':%02d.%09d', $deltas{'s'}, $nsec) :
2235 26 sprintf(':%02d', $deltas{'s'}));
2236  
2237 26 ▶ $output .= "$deltas{'hms'}" if($deltas{'hms'});
Branch: 1 branch
BranchTrueFalseTotal
if $deltas{"hms"} 26 0 26
2238 }
2239  
2240 40 $output =~ s/ \z//;
2241  
2242 40 ▶ if(length($output) > $self->max_interval_characters)
Branch: 1 branch
BranchTrueFalseTotal
if (length $output > $self->max_interval_characters) 2 38 40
2243 {
2244 2 Carp::croak "Interval string is longer than ", ref($self),
2245 "->max_interval_characters (", $self->max_interval_characters,
2246 ") characters long: $output";
2247 }
2248  
2249 38 return $output;
2250 }
2251  
2252 0 ▶sub build_dsn { 'override in subclass' }
Subroutine build_dsn: not called CC=1 SCAR=6.9
Pod undocumented
2253  
2254 0 ▶sub validate_integer_keyword { 0 }
Subroutine validate_integer_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2255 0 ▶sub validate_float_keyword { 0 }
Subroutine validate_float_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2256 0 ▶sub validate_numeric_keyword { 0 }
Subroutine validate_numeric_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2257 0 ▶sub validate_decimal_keyword { 0 }
Subroutine validate_decimal_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2258 0 ▶sub validate_double_precision_keyword { 0 }
Subroutine validate_double_precision_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2259 0 ▶sub validate_bigint_keyword { 0 }
Subroutine validate_bigint_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2260 0 ▶sub validate_date_keyword { 0 }
Subroutine validate_date_keyword: not called CC=1 SCAR=6.9
Pod documented
2261 0 ▶sub validate_datetime_keyword { 0 }
Subroutine validate_datetime_keyword: not called CC=1 SCAR=6.9
Pod documented
2262 54 ▶sub validate_time_keyword { 0 }
Subroutine validate_time_keyword: called CC=1 SCAR=0.0
Pod documented
2263 0 ▶sub validate_timestamp_keyword { 0 }
Subroutine validate_timestamp_keyword: not called CC=1 SCAR=6.9
Pod documented
2264 116 ▶sub validate_interval_keyword { 0 }
Subroutine validate_interval_keyword: called CC=1 SCAR=0.0
Pod documented
2265 0 ▶sub validate_set_keyword { 0 }
Subroutine validate_set_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2266 0 ▶sub validate_array_keyword { 0 }
Subroutine validate_array_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2267 0 ▶sub validate_bitfield_keyword { 0 }
Subroutine validate_bitfield_keyword: not called CC=1 SCAR=6.9
Pod undocumented
2268  
2269 sub validate_boolean_keyword
2270 0 ▶{
Subroutine validate_boolean_keyword: not called CC=1 SCAR=0.2
Pod documented
2271 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
2272 0 $_[1] =~ /^(?:TRUE|FALSE)$/;
2273 }
2274  
2275 sub should_inline_keyword
2276 0 ▶{
Subroutine should_inline_keyword: not called CC=2 SCAR=9.2
Pod undocumented
2277 17 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
2278 0 ▶ ($_[1] =~ /^\w+\(.*\)$/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /^\w+\(.*\)$/ ? : 0 0 0
2279 }
2280  
2281 BEGIN
2282 17 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
2283 17 *should_inline_integer_keyword = \&should_inline_keyword;
2284 17 *should_inline_float_keyword = \&should_inline_keyword;
2285 17 *should_inline_decimal_keyword = \&should_inline_keyword;
2286 17 *should_inline_numeric_keyword = \&should_inline_keyword;
2287 17 *should_inline_double_precision_keyword = \&should_inline_keyword;
2288 17 *should_inline_bigint_keyword = \&should_inline_keyword;
2289 17 *should_inline_date_keyword = \&should_inline_keyword;
2290 17 *should_inline_datetime_keyword = \&should_inline_keyword;
2291 17 *should_inline_time_keyword = \&should_inline_keyword;
2292 17 *should_inline_timestamp_keyword = \&should_inline_keyword;
2293 17 *should_inline_interval_keyword = \&should_inline_keyword;
2294 17 *should_inline_set_keyword = \&should_inline_keyword;
2295 17 *should_inline_array_keyword = \&should_inline_keyword;
2296 17 *should_inline_boolean_keyword = \&should_inline_keyword;
2297 17 *should_inline_bitfield_value = \&should_inline_keyword;
2298 }
2299  
2300 sub next_value_in_sequence
2301 0 ▶{
Subroutine next_value_in_sequence: not called CC=1 SCAR=6.9
Pod undocumented
2302 0 my($self, $seq) = @_;
2303 0 $self->error("Don't know how to select next value in sequence '$seq' " .
2304 "for database driver " . $self->driver);
2305 0 return undef;
2306 }
2307  
2308 sub current_value_in_sequence
2309 0 ▶{
Subroutine current_value_in_sequence: not called CC=1 SCAR=6.9
Pod undocumented
2310 0 my($self, $seq) = @_;
2311 0 $self->error("Don't know how to select current value in sequence '$seq' " .
2312 "for database driver " . $self->driver);
2313 0 return undef;
2314 }
2315  
2316 sub sequence_exists
2317 0 ▶{
Subroutine sequence_exists: not called CC=1 SCAR=6.9
Pod undocumented
2318 0 my($self, $seq) = @_;
2319 0 $self->error("Don't know how to tell if sequence '$seq' exists " .
2320 "for database driver " . $self->driver);
2321 0 return undef;
2322 }
2323  
2324 0 ▶sub auto_sequence_name { undef }
Subroutine auto_sequence_name: not called CC=1 SCAR=6.9
Pod undocumented
2325  
2326 0 ▶sub supports_multi_column_count_distinct { 1 }
Subroutine supports_multi_column_count_distinct: not called CC=1 SCAR=6.9
Pod undocumented
2327 0 ▶sub supports_nested_joins { 1 }
Subroutine supports_nested_joins: not called CC=1 SCAR=6.9
Pod undocumented
2328 0 ▶sub supports_limit_with_offset { 1 }
Subroutine supports_limit_with_offset: not called CC=1 SCAR=6.9
Pod undocumented
2329 0 ▶sub supports_arbitrary_defaults_on_insert { 0 }
Subroutine supports_arbitrary_defaults_on_insert: not called CC=1 SCAR=6.9
Pod undocumented
2330 0 ▶sub supports_select_from_subselect { 0 }
Subroutine supports_select_from_subselect: not called CC=1 SCAR=6.9
Pod undocumented
2331 0 ▶sub format_select_from_subselect { "(\n$_[1]\n )" }
Subroutine format_select_from_subselect: not called CC=1 SCAR=6.9
Pod undocumented
2332  
2333 0 ▶sub likes_redundant_join_conditions { 0 }
Subroutine likes_redundant_join_conditions: not called CC=1 SCAR=6.9
Pod undocumented
2334 0 ▶sub likes_lowercase_table_names { 0 }
Subroutine likes_lowercase_table_names: not called CC=1 SCAR=6.9
Pod undocumented
2335 0 ▶sub likes_uppercase_table_names { 0 }
Subroutine likes_uppercase_table_names: not called CC=1 SCAR=6.9
Pod undocumented
2336 0 ▶sub likes_lowercase_schema_names { 0 }
Subroutine likes_lowercase_schema_names: not called CC=1 SCAR=6.9
Pod undocumented
2337 0 ▶sub likes_uppercase_schema_names { 0 }
Subroutine likes_uppercase_schema_names: not called CC=1 SCAR=6.9
Pod undocumented
2338 0 ▶sub likes_lowercase_catalog_names { 0 }
Subroutine likes_lowercase_catalog_names: not called CC=1 SCAR=6.9
Pod undocumented
2339 0 ▶sub likes_uppercase_catalog_names { 0 }
Subroutine likes_uppercase_catalog_names: not called CC=1 SCAR=6.9
Pod undocumented
2340 0 ▶sub likes_lowercase_sequence_names { 0 }
Subroutine likes_lowercase_sequence_names: not called CC=1 SCAR=6.9
Pod undocumented
2341 0 ▶sub likes_uppercase_sequence_names { 0 }
Subroutine likes_uppercase_sequence_names: not called CC=1 SCAR=6.9
Pod undocumented
2342 0 ▶sub likes_implicit_joins { 0 }
Subroutine likes_implicit_joins: not called CC=1 SCAR=6.9
Pod undocumented
2343  
2344 0 ▶sub supports_schema { 0 }
Subroutine supports_schema: not called CC=1 SCAR=6.9
Pod undocumented
2345 0 ▶sub supports_catalog { 0 }
Subroutine supports_catalog: not called CC=1 SCAR=6.9
Pod undocumented
2346  
2347 0 ▶sub use_auto_sequence_name { 0 }
Subroutine use_auto_sequence_name: not called CC=1 SCAR=6.9
Pod undocumented
2348  
2349 sub format_limit_with_offset
2350 0 ▶{
Subroutine format_limit_with_offset: not called CC=2 SCAR=17.9
Pod undocumented
2351 0 my($self, $limit, $offset, $args) = @_;
2352  
2353 0 delete $args->{'limit'};
2354 0 delete $args->{'offset'};
2355  
2356 0 ▶ if(defined $offset)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 0 0 0
2357 {
2358 0 $args->{'limit_suffix'} = "LIMIT $limit OFFSET $offset";
2359 }
2360 else
2361 {
2362 0 $args->{'limit_suffix'} = "LIMIT $limit";
2363 }
2364 }
2365  
2366 sub format_table_with_alias
2367 0 ▶{
Subroutine format_table_with_alias: not called CC=1 SCAR=6.9
Pod undocumented
2368 #my($self, $table, $alias, $hints) = @_;
2369 0 return "$_[1] $_[2]";
2370 }
2371  
2372 sub format_select_start_sql
2373 0 ▶{
Subroutine format_select_start_sql: not called CC=3 SCAR=24.8
Pod undocumented
2374 0 my($self, $hints) = @_;
2375 0 ▶ return 'SELECT' unless($hints);
Branch: 1 branch
BranchTrueFalseTotal
unless $hints 0 0 0
2376 0 ▶ return 'SELECT ' . ($hints->{'comment'} ? "/* $hints->{'comment'} */" : '');
Branch: 1 branch
BranchTrueFalseTotal
$hints->{'comment'} ? : 0 0 0
2377 }
2378  
2379 0 ▶sub format_select_lock { '' }
Subroutine format_select_lock: not called CC=1 SCAR=6.9
Pod undocumented
2380  
2381 sub column_sql_from_lock_on_value
2382 0 ▶{
Subroutine column_sql_from_lock_on_value: not called CC=10 SCAR=47.0
Pod undocumented
2383 0 my($self, $object_or_class, $name, $tables) = @_;
2384  
2385 0 my %map;
2386  
2387 0 ▶ if($tables)
Branch: 1 branch
BranchTrueFalseTotal
if ($tables) 0 0 0
2388 {
2389 0 my $tn = 1;
2390  
2391 0 foreach my $table (@$tables)
2392 {
2393 0 (my $table_key = $table) =~ s/^(["']?)[^.]+\1\.//;
2394 0 $map{$table_key} = 't' . $tn++;
2395 }
2396 }
2397  
2398 0 my $table;
2399 0 my $chase_meta = $object_or_class->meta;
2400  
2401 # Chase down multi-level keys: e.g., products.vendor.name
2402 0 ▶ while($name =~ /\G([^.]+)(\.|$)/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\G([^.]+)(\.|$)/g) 0 0 0
2403 {
2404 0 my($sub_name, $more) = ($1, $2);
2405  
2406 0 ▶ my $key = $chase_meta->foreign_key($sub_name) ||
Condition0%0/3
$chase_meta->foreign_key($sub_name) || $chase_meta->relationship($sub_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$chase_meta->foreign_key($sub_name) || $chase_meta->relationship($sub_name)
$chase_meta->foreign_key($sub_name) $chase_meta->relationship($sub_name)
Truth table0%0/3
A || B
A= $chase_meta->foreign_key($sub_name)B= $chase_meta->relationship($sub_name)
ABresult
1X1
011
000
2407 $chase_meta->relationship($sub_name);
2408  
2409 0 ▶ if($key)
Branch: 1 branch
BranchTrueFalseTotal
if ($key) { } 0 0 0
2410 {
2411 0 ▶ $chase_meta = $key->can('foreign_class') ?
Branch: 1 branch
BranchTrueFalseTotal
$key->can('foreign_class') ? : 0 0 0
2412 $key->foreign_class->meta : $key->class->meta;
2413  
2414 0 $table = $chase_meta->table;
2415 }
2416 else
2417 {
2418 0 ▶ if($more)
Branch: 1 branch
BranchTrueFalseTotal
if ($more) { } 0 0 0
2419 {
2420 0 Carp::confess 'Invalid lock => { on => ... } argument: ',
2421 "no foreign key or relationship named '$sub_name' ",
2422 'found in ', $chase_meta->class;
2423 }
2424 else
2425 {
2426 0 my $column = $sub_name;
2427  
2428 0 ▶ if($table)
Branch: 1 branch
BranchTrueFalseTotal
if ($table) { } 0 0 0
2429 {
2430 0 ▶ $table = $map{$table} if(defined $map{$table});
Branch: 1 branch
BranchTrueFalseTotal
if defined $map{$table} 0 0 0
2431 0 return $self->auto_quote_column_with_table($column, $table);
2432 }
2433 else
2434 {
2435 0 return $self->auto_quote_column_name($column);
2436 }
2437 }
2438 }
2439 }
2440  
2441 0 Carp::confess "Invalid lock => { on => ... } argument: $name";
2442 }
2443  
2444 sub table_sql_from_lock_on_value
2445 0 ▶{
Subroutine table_sql_from_lock_on_value: not called CC=11 SCAR=48.8
Pod undocumented
2446 0 my($self, $object_or_class, $name, $tables) = @_;
2447  
2448 0 my %map;
2449  
2450 0 ▶ if($tables)
Branch: 1 branch
BranchTrueFalseTotal
if ($tables) 0 0 0
2451 {
2452 0 my $tn = 1;
2453  
2454 0 foreach my $table (@$tables)
2455 {
2456 0 (my $table_key = $table) =~ s/^(["']?)[^.]+\1\.//;
2457 0 $map{$table_key} = 't' . $tn++;
2458 }
2459 }
2460  
2461 0 my $table;
2462 0 my $chase_meta = $object_or_class->meta;
2463  
2464 # Chase down multi-level keys: e.g., products.vendor.location
2465 0 ▶ while($name =~ /\G([^.]+)(\.|$)/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\G([^.]+)(\.|$)/g) 0 0 0
2466 {
2467 0 my($sub_name, $more) = ($1, $2);
2468  
2469 0 ▶ my $key = $chase_meta->foreign_key($sub_name) ||
Condition0%0/3
$chase_meta->foreign_key($sub_name) || $chase_meta->relationship($sub_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$chase_meta->foreign_key($sub_name) || $chase_meta->relationship($sub_name)
$chase_meta->foreign_key($sub_name) $chase_meta->relationship($sub_name)
Truth table0%0/3
A || B
A= $chase_meta->foreign_key($sub_name)B= $chase_meta->relationship($sub_name)
ABresult
1X1
011
000
2470 $chase_meta->relationship($sub_name);
2471  
2472 0 ▶ if($key || !$more)
Branch: 1 branch
BranchTrueFalseTotal
if ($key or not $more) { } 0 0 0
Condition0%0/3
$key or not $more
l!l&&r!l&&!r
000
MC/DC0%0/2
$key or not $more
$key not $more
Truth table0%0/3
A or not(B)
A= $keyB= not $more
ABresult
1X1
011
000
2473 {
2474 0 ▶ if($key)
Branch: 1 branch
BranchTrueFalseTotal
if ($key) { } 0 0 0
2475 {
2476 0 ▶ $chase_meta = $key->can('foreign_class') ?
Branch: 1 branch
BranchTrueFalseTotal
$key->can('foreign_class') ? : 0 0 0
2477 $key->foreign_class->meta : $key->class->meta;
2478  
2479 0 $table = $chase_meta->table;
2480 }
2481 else
2482 {
2483 0 $table = $sub_name;
2484 }
2485  
2486 0 ▶ next if($more);
Branch: 1 branch
BranchTrueFalseTotal
if $more 0 0 0
2487  
2488 0 ▶ $table = $map{$table} if(defined $map{$table});
Branch: 1 branch
BranchTrueFalseTotal
if defined $map{$table} 0 0 0
2489 0 return $self->auto_quote_table_name($table);
2490 }
2491 else
2492 {
2493 0 Carp::confess 'Invalid lock => { on => ... } argument: ',
2494 "no foreign key or relationship named '$sub_name' ",
2495 'found in ', $chase_meta->class;
2496 }
2497 }
2498  
2499 0 Carp::confess "Invalid lock => { on => ... } argument: $name";
2500 }
2501  
2502 0 ▶sub supports_on_duplicate_key_update { 0 }
Subroutine supports_on_duplicate_key_update: not called CC=1 SCAR=6.9
Pod undocumented
2503  
2504 #
2505 # DBI introspection
2506 #
2507  
2508 sub refine_dbi_column_info
2509 0 ▶{
Subroutine refine_dbi_column_info: not called CC=1 SCAR=6.9
Pod undocumented
2510 0 my($self, $col_info) = @_;
2511  
2512 # Parse odd default value syntaxes
2513 $col_info->{'COLUMN_DEF'} =
2514 0 $self->parse_dbi_column_info_default($col_info->{'COLUMN_DEF'}, $col_info);
2515  
2516 # Make sure the data type name is lowercase
2517 0 $col_info->{'TYPE_NAME'} = lc $col_info->{'TYPE_NAME'};
2518  
2519 # Unquote column name
2520 0 $col_info->{'COLUMN_NAME'} = $self->unquote_column_name($col_info->{'COLUMN_NAME'});
2521  
2522 0 return;
2523 }
2524  
2525 sub refine_dbi_foreign_key_info
2526 0 ▶{
Subroutine refine_dbi_foreign_key_info: not called CC=4 SCAR=30.0
Pod undocumented
2527 0 my($self, $fk_info) = @_;
2528  
2529 # Unquote names
2530 0 foreach my $name (qw(NAME COLUMN_NAME DATA_TYPE TABLE_NAME TABLE_CAT TABLE_SCHEM))
2531 {
2532 0 foreach my $prefix (qw(FK_ UK_))
2533 {
2534 0 my $param = $prefix . $name;
2535 $fk_info->{$param} = $self->unquote_column_name($fk_info->{$param})
2536 0 ▶ if(exists $fk_info->{$param});
Branch: 1 branch
BranchTrueFalseTotal
if exists $fk_info->{$param} 0 0 0
2537 }
2538 }
2539  
2540 0 return;
2541 }
2542  
2543 0 ▶sub parse_dbi_column_info_default { $_[1] }
Subroutine parse_dbi_column_info_default: not called CC=1 SCAR=6.9
Pod undocumented
2544  
2545 sub list_tables
2546 0 ▶{
Subroutine list_tables: not called CC=6 SCAR=37.4
Pod documented
2547 0 my($self, %args) = @_;
2548  
2549 0 ▶ my $types = $args{'include_views'} ? "'TABLE','VIEW'" : 'TABLE';
Branch: 1 branch
BranchTrueFalseTotal
$args{'include_views'} ? : 0 0 0
2550  
2551 0 my(@tables, $error);
2552  
2553 TRY:
2554 {
2555 0 local $@;
2556  
2557 eval
2558 0 {
2559 0 ▶ my $dbh = $self->dbh or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or die $self->error 0 0 0
2560  
2561 0 local $dbh->{'RaiseError'} = 1;
2562 0 local $dbh->{'FetchHashKeyName'} = 'NAME';
2563  
2564 0 my $sth = $dbh->table_info($self->catalog, $self->schema, '%', $types);
2565  
2566 0 $sth->execute;
2567  
2568 0 ▶ while(my $table_info = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $table_info = $sth->fetchrow_hashref) 0 0 0
2569 {
2570 0 push(@tables, $table_info->{'TABLE_NAME'})
2571 }
2572 };
2573  
2574 0 $error = $@;
2575 }
2576  
2577 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
2578 {
2579 0 Carp::croak "Could not list tables from ", $self->dsn, " - $error";
2580 }
2581  
2582 0 ▶ return wantarray ? @tables : \@tables;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2583 }
2584  
2585 #
2586 # Setup overrides
2587 #
2588  
2589 # - Rose::DB development init file - Perl code
2590 # - Rose::DB fixup rc file - YAML format
2591  
2592 sub auto_load_fixups
2593 1 ▶{
Subroutine auto_load_fixups: called CC=13 SCAR=39.7
Pod documented
2594 1 my($class) = shift;
2595  
2596 # Load a file full of fix-ups for the data sources (usually just passwords)
2597 # from a "well-known" (or at least "well-specified") location.
2598 1 my $fixup_file = $ENV{'ROSEDBRC'};
2599 1 ▶ $fixup_file = '/etc/rosedbrc' unless(defined $fixup_file && -e $fixup_file);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fixup_file and -e $fixup_file 0 1 1
Condition33%1/3
defined $fixup_file and -e $fixup_file
!ll&&!rl&&r
001
MC/DC0%0/2
defined $fixup_file and -e $fixup_file
defined $fixup_file -e $fixup_file
Truth table33%1/3
A and B
A= defined $fixup_fileB= -e $fixup_file
ABresult
0X0
100
111
2600  
2601 1 ▶ if(-e $fixup_file)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $fixup_file) 1 0 1
2602 {
2603 1 ▶ if(-r $fixup_file)
Branch: 1 branch
BranchTrueFalseTotal
if (-r $fixup_file) { } 1 0 1
2604 {
2605 1 $class->load_yaml_fixup_file($fixup_file);
2606 }
2607 else
2608 {
2609 0 warn "Cannot read Rose::DB fixup file '$fixup_file'";
2610 }
2611 }
2612  
2613 # Load a file or package full of arbitrary Perl used to alter the data
2614 # source registry. This is intended for use in development only.
2615 1 my $rosedb_devinit = $ENV{'ROSEDB_DEVINIT'};
2616  
2617 1 my $error;
2618  
2619 1 ▶ if(defined $rosedb_devinit)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rosedb_devinit) 1 0 1
2620 {
2621 1 ▶ if(-e $rosedb_devinit)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $rosedb_devinit) { } 0 1 1
2622 {
2623 TRY:
2624 {
2625 0 local $@;
2626 0 do $rosedb_devinit;
2627 0 $error = $@;
2628 }
2629 }
2630 else
2631 {
2632 TRY:
2633 {
2634 1 local $@;
2635 1 eval qq(require $rosedb_devinit);
2636 1 $error = $@;
2637 }
2638  
2639 1 ▶ if($rosedb_devinit->can('fixup'))
Branch: 1 branch
BranchTrueFalseTotal
if ($rosedb_devinit->can("fixup")) 1 0 1
2640 {
2641 1 $rosedb_devinit->fixup($class);
2642 }
2643 }
2644 }
2645  
2646 1 ▶ if($error || !defined $rosedb_devinit)
Branch: 1 branch
BranchTrueFalseTotal
if ($error or not defined $rosedb_devinit) 0 1 1
Condition33%1/3
$error or not defined $rosedb_devinit
l!l&&r!l&&!r
001
MC/DC0%0/2
$error or not defined $rosedb_devinit
$error not defined $rosedb_devinit
Truth table33%1/3
A or not(B)
A= $errorB= not defined $rosedb_devinit
ABresult
1X1
011
000
2647 {
2648 0 my $username;
2649  
2650 # The getpwuid() function is often(?) unimplemented in perl on Windows
2651 TRY:
2652 {
2653 0 local $@;
2654 0 eval { $username = lc getpwuid($<) };
2655 0 $error = $@;
2656 }
2657  
2658 0 ▶ unless($error)
Branch: 1 branch
BranchTrueFalseTotal
unless ($error) 0 0 0
2659 {
2660 0 $rosedb_devinit = "Rose::DB::Devel::Init::$username";
2661  
2662 TRY:
2663 {
2664 0 local $@;
2665 0 eval qq(require $rosedb_devinit);
2666 0 $error = $@;
2667 }
2668  
2669 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 0 0 0
2670 {
2671 TRY:
2672 {
2673 0 local $@;
2674 0 eval { do $rosedb_devinit };
2675 0 $error = $@;
2676 }
2677 }
2678 else
2679 {
2680 0 ▶ if($rosedb_devinit->can('fixup'))
Branch: 1 branch
BranchTrueFalseTotal
if ($rosedb_devinit->can("fixup")) 0 0 0
2681 {
2682 0 $rosedb_devinit->fixup($class);
2683 }
2684 }
2685 }
2686 }
2687 }
2688  
2689 # YAML syntax example:
2690 #
2691 # ---
2692 # production:
2693 # g3db:
2694 # password: mysecret
2695 # ---
2696 # mqa:
2697 # g3db:
2698 # password: myothersecret
2699  
2700 17 our $YAML_Class;
2701  
2702 sub load_yaml_fixup_file
2703 1 ▶{
Subroutine load_yaml_fixup_file: called CC=9 SCAR=22.4
Pod undocumented
2704 1 my($class, $file) = @_;
2705  
2706 1 my $registry = $class->registry;
2707  
2708 1 ▶ unless($YAML_Class)
Branch: 1 branch
BranchTrueFalseTotal
unless ($Rose::DB::YAML_Class) 1 0 1
2709 {
2710 1 my $error;
2711  
2712 TRY:
2713 {
2714 1 local $@;
2715 1 eval { require YAML::Syck };
2716 1 $error = $@;
2717 }
2718  
2719 1 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 1 0 1
2720 {
2721 1 require YAML;
2722 #warn "# Using YAML\n";
2723 1 $YAML_Class = 'YAML';
2724 }
2725 else
2726 {
2727 #warn "# Using YAML::Syck\n";
2728 0 $YAML_Class = 'YAML::Syck';
2729 }
2730 }
2731  
2732 1 ▶ $Debug && warn "$class - Loading fixups from $file...\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Debug and warn "$class - Loading fixups from $file...\n" 0 1 1
2733 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2734 1 my @data = &{"${YAML_Class}::LoadFile"}($file);
2735  
2736 1 foreach my $data (@data)
2737 {
2738 2 foreach my $domain (sort keys %$data)
2739 {
2740 2 foreach my $type (sort keys %{$data->{$domain}})
2741 {
2742 2 my $entry = $registry->entry(domain => $domain, type => $type);
2743  
2744 2 ▶ unless($entry)
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry) 0 2 2
2745 {
2746 0 warn "No $class data source found for domain '$domain' ",
2747 "and type '$type'";
2748 0 next;
2749 }
2750  
2751 2 ▶ while(my($method, $value) = each(%{$data->{$domain}{$type}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$data{$domain}{$type};}) 3 2 5
2752 {
2753 #$Debug && warn "$class - $domain:$type - $method = $value\n";
2754 3 $entry->$method($value);
2755 }
2756 }
2757 }
2758 }
2759 }
2760  
2761 #
2762 # Storable hooks
2763 #
2764  
2765 sub STORABLE_freeze
2766 0 ▶{
Subroutine STORABLE_freeze: not called CC=2 SCAR=17.9
Pod undocumented
2767 0 my($self, $cloning) = @_;
2768  
2769 0 ▶ return if($cloning);
Branch: 1 branch
BranchTrueFalseTotal
if $cloning 0 0 0
2770  
2771 # Ditch the DBI $dbh and pull the password out of its closure
2772 0 my $db = { %$self };
2773 0 $db->{'dbh'} = undef;
2774 0 $db->{'password'} = $self->password;
2775 0 $db->{'password_closure'} = undef;
2776  
2777 0 require Storable;
2778 0 return Storable::freeze($db);
2779 }
2780  
2781 sub STORABLE_thaw
2782 0 ▶{
Subroutine STORABLE_thaw: not called CC=2 SCAR=17.9
Pod undocumented
2783 0 my($self, $cloning, $serialized) = @_;
2784  
2785 0 %$self = %{ Storable::thaw($serialized) };
2786  
2787 # Put the password back in a closure
2788 0 my $password = delete $self->{'password'};
2789 0 ▶ $self->{'password_closure'} = sub { $password } if(defined $password);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if defined $password 0 0 0
2790 }
2791  
2792 #
2793 # This is both a class and an object method
2794 #
2795  
2796 sub error
2797 54 ▶{
Subroutine error: called CC=4 SCAR=13.9
Pod documented
2798 54 my($self_or_class) = shift;
2799  
2800 54 ▶ if(ref $self_or_class) # Object method
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self_or_class) 48 6 54
2801 {
2802 48 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 4 48
2803 {
2804 44 return $self_or_class->{'error'} = $Error = shift;
2805 }
2806 4 return $self_or_class->{'error'};
2807 }
2808  
2809 # Class method
2810 6 ▶ return $Error = shift if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 4 6
2811 4 return $Error;
2812 }
2813  
2814 sub DESTROY
2815 68 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
2816 68 $_[0]->disconnect;
2817 }
2818  
2819 BEGIN
2820 17 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
2821 package Rose::DateTime::Format::Generic;
2822  
2823 17 ▶ use Rose::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
2824 17 our @ISA = qw(Rose::Object);
2825  
2826 use Rose::Object::MakeMethods::Generic
2827 17 ▶ (
Subroutine BEGIN: called CC=1 SCAR=0.0
2828 17 scalar => 'server_tz',
2829 boolean => 'european',
2830 17 );
2831  
2832 0 ▶ sub format_date { shift; Rose::DateTime::Util::format_date($_[0], '%Y-%m-%d') }
Subroutine format_date: not called CC=1 SCAR=6.9
2833 0 ▶ sub format_datetime { shift; Rose::DateTime::Util::format_date($_[0], '%Y-%m-%d %T') }
Subroutine format_datetime: not called CC=1 SCAR=6.9
2834 0 ▶ sub format_timestamp { shift; Rose::DateTime::Util::format_date($_[0], '%Y-%m-%d %H:%M:%S.%N') }
Subroutine format_timestamp: not called CC=1 SCAR=6.9
2835 0 ▶ sub format_timestamp_with_time_zone { shift->format_timestamp(@_) }
Subroutine format_timestamp_with_time_zone: not called CC=1 SCAR=6.9
2836  
2837 0 ▶ sub parse_date { shift; Rose::DateTime::Util::parse_date($_[0], $_[0]->server_tz) }
Subroutine parse_date: not called CC=1 SCAR=6.9
2838 0 ▶ sub parse_datetime { shift; Rose::DateTime::Util::parse_date($_[0], $_[0]->server_tz) }
Subroutine parse_datetime: not called CC=1 SCAR=6.9
2839 0 ▶ sub parse_timestamp { shift; Rose::DateTime::Util::parse_date($_[0], $_[0]->server_tz) }
Subroutine parse_timestamp: not called CC=1 SCAR=6.9
2840 0 ▶ sub parse_timestamp_with_time_zone { shift->parse_timestamp(@_) }
Subroutine parse_timestamp_with_time_zone: not called CC=1 SCAR=6.9
2841 }
2842  
2843 17 1;
2844  
2845 __END__
« DB/Oracle.pm ↑ Summary DB/Informix.pm »