lib/DB/Object/Tables.pm

filter: Statementstmt 8.6% 46 / 533 Branchbran 0.9% 2 / 212 Conditioncond 0.0% 0 / 215 MC/DCmcdc 0.0% 0 / 111 Subroutinesub 15.3% 15 / 98 Podpod 93.9% 78 / 83 totaltotal 11.2% 141 / 1252 CC 196 SCAR 48.0
CC
196
Cov
5%
init
600.0
THAW
460.7
attach
156.0
CRAP 121.4
« blib/lib/DB/Object/Mysql/Query.pm ↑ Summary lib/DB/Object/Fields.pm »
1 # -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## SQL API Abstraction - ~/lib/DB/Object/Tables.pm
4 ## Version v1.3.1
5 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2017/07/19
8 ## Modified 2026/10/01
9 ## All rights reserved
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 # This package's purpose is to separate the object of the tables from the main
15 # DB::Object package so that when they get DESTROY'ed, it does not interrupt
16 # the SQL connection
17 ##----------------------------------------------------------------------------
18 package DB::Object::Tables;
19 BEGIN
20 4 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 warnings::register_categories( 'DB::Object' );
24 4 ▶ use parent qw( DB::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶ use vars qw( $VERSION $DEBUG $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶ use DB::Object::Fields;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 our $DEBUG = 0;
29 4 our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
30 4 our $VERSION = 'v1.3.1';
31 };
32  
33 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 0 ▶sub new { return( shift->Module::Generic::new( @_ ) ); }
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
37  
38 sub init
39 0 ▶{
Subroutine init: not called CC=24 SCAR=64.0
Pod documented
40 0 my $self = shift( @_ );
41 0 my $table;
42 my @test_args;
43 0 ▶ if( @_ &&
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and @_ == 1 && defined $_[0] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) || @_ == 2 && defined $_[0] && defined $_[1] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) && ref $_[1] eq "HASH" || @_ > 2 && defined $_[0] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) && (@test_args = @_[1 .. $#_]) && !(@test_args % 2)) 0 0 0
Condition0%0/48
@_ and @_ == 1 && defined $_[0] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) || @_ == 2 && defined $_[0] && defined $_[1] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) && ref $_[1] eq "HASH" || @_ > 2 && defined $_[0] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) && (@test_args = @_[1 .. $#_]) && !(@test_args % 2)
!ll&&!rl&&r
000
@_ == 1 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") or @_ == 2 and defined $_[0] and defined $_[1] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and ref $_[1] eq "HASH" or @_ > 2 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and @test_args = @_[1 .. $#_] and not @test_args % 2
l!l&&r!l&&!r
000
@_ == 1 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") or @_ == 2 and defined $_[0] and defined $_[1] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and ref $_[1] eq "HASH"
l!l&&r!l&&!r
000
@_ == 1 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"")
!ll&&!rl&&r
000
@_ == 1 and defined $_[0]
!ll&&!rl&&r
000
not ref $_[0] or $self->_can_overload($_[0], "\"\"")
l!l&&r!l&&!r
000
@_ == 2 and defined $_[0] and defined $_[1] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and ref $_[1] eq "HASH"
!ll&&!rl&&r
000
@_ == 2 and defined $_[0] and defined $_[1] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"")
!ll&&!rl&&r
000
@_ == 2 and defined $_[0] and defined $_[1]
!ll&&!rl&&r
000
@_ == 2 and defined $_[0]
!ll&&!rl&&r
000
not ref $_[0] or $self->_can_overload($_[0], "\"\"")
l!l&&r!l&&!r
000
@_ > 2 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and @test_args = @_[1 .. $#_] and not @test_args % 2
!ll&&!rl&&r
000
@_ > 2 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"") and @test_args = @_[1 .. $#_]
!ll&&!rl&&r
000
@_ > 2 and defined $_[0] and !ref($_[0]) || $self->_can_overload($_[0], "\"\"")
!ll&&!rl&&r
000
@_ > 2 and defined $_[0]
!ll&&!rl&&r
000
not ref $_[0] or $self->_can_overload($_[0], "\"\"")
l!l&&r!l&&!r
000
MC/DC0%0/17
@_ and @_ == 1 && defined $_[0] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) || @_ == 2 && defined $_[0] && defined $_[1] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) && ref $_[1] eq "HASH" || @_ > 2 && defined $_[0] && (!ref($_[0]) || $self->_can_overload($_[0], "\"\"")) && (@test_args = @_[1 .. $#_]) && !(@test_args % 2)
too many conditions
44 (
45 # $self->init( $table_name )
46 (
47 @_ == 1 &&
48 defined( $_[0] ) &&
49 (
50 !ref( $_[0] ) ||
51 $self->_can_overload( $_[0] => '""' )
52 )
53 ) ||
54 # $self->init( $table_name, $opts_hash_ref );
55 (
56 @_ == 2 &&
57 defined( $_[0] ) &&
58 defined( $_[1] ) &&
59 (
60 !ref( $_[0] ) ||
61 $self->_can_overload( $_[0] => '""' )
62 ) &&
63 ref( $_[1] ) eq 'HASH'
64 ) ||
65 # $self->init( $table_name, opt11 => val1, opt2 => val2 );
66 (
67 @_ > 2 &&
68 defined( $_[0] ) &&
69 (
70 !ref( $_[0] ) || $self->_can_overload( $_[0] => '""' )
71 ) &&
72 ( @test_args = @_[1..$#_] ) &&
73 !( @test_args % 2 )
74 )
75 ) )
76 {
77 0 $table = shift( @_ );
78 }
79 0 my $opts = $self->_get_args_as_hash( @_ );
80 0 ▶ unless( defined( $table ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table) 0 0 0
81 {
82 0 ▶ if( !CORE::exists( $opts->{table} ) || !CORE::length( $opts->{table} // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opts->{'table'} && length($opts->{'table'} // '')) { } 0 0 0
Condition0%0/5
exists $opts->{'table'} && length($opts->{'table'} // '')
!ll&&!rl&&r
000
$opts->{"table"} // ""
l!l
00
MC/DC0%0/2
exists $opts->{'table'} && length($opts->{'table'} // '')
exists $opts->{'table'} $opts->{"table"}
Truth table0%0/3
A && B
A= exists $opts->{'table'}B= $opts->{"table"}
ABresult
0X0
100
111
83 {
84 0 return( $self->error( "You must provide a table name to create a table object." ) );
85 }
86 else
87 {
88 0 $table = CORE::delete( $opts->{table} );
89 }
90 }
91 0 $self->{check} = {};
92 0 $self->{dbo} = undef;
93 # $self->{default} = {};
94 # Containing all the table field objects
95 0 $self->{fields} = {};
96 # DB::Object::Fields
97 0 $self->{fields_object} = undef;
98 0 $self->{foreign} = {};
99 0 $self->{indexes} = {};
100 # $self->{null} = {};
101 0 $self->{prefixed} = 0;
102 0 $self->{primary} = [];
103 0 $self->{query_object} = undef;
104 0 $self->{query_reset} = 0;
105 0 $self->{reverse} = 0;
106 # The schema name, if any
107 0 $self->{schema} = undef;
108 0 $self->{structure} = {};
109 0 $self->{table_alias} = undef;
110 # The table type. It could be table or view
111 0 $self->{type} = undef;
112 # $self->{types} = {};
113 # An hash to contain table field to an hash of constant value and constant name:
114 # field => { constant => 12, name => PG_JSONB, type => 'jsonb' };
115 0 $self->{types_const} = {};
116 0 $self->{_init_params_order} = [qw( dbo query_object )];
117 0 $self->{_init_strict_use_sub} = 1;
118 0 $self->{_exception_class} = $EXCEPTION_CLASS;
119 0 ▶ $self->Module::Generic::init( %$opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->Module::Generic::init(%$opts) or return $self->pass_error 0 0 0
120 0 $self->dbo( $opts->{dbo} );
121 0 $self->{table} = $table;
122 0 $self->{_cache_structure} = '';
123 # Load table default, fields, structure informations
124 0 ▶ my $ref = $self->structure || return( $self->pass_error );
Condition0%0/2
$self->structure || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->structure || (return $self->pass_error)
$self->structure
Truth table0%0/2
A
A= $self->structure
Aresult
11
00
125 # return( $self->error( "There is no table by the name of $table" ) ) if( !defined( $ref ) || !%$ref );
126 0 return( $self );
127 }
128  
129 # Get/set alias
130 0 ▶sub alias { return( shift->_method_to_query( 'alias', @_ ) ); }
Subroutine alias: not called CC=1 SCAR=6.9
Pod documented
131  
132 sub alter
133 0 ▶{
Subroutine alter: not called CC=11 SCAR=48.8
Pod documented
134 0 my $self = shift( @_ );
135 # Expecting a reference to an array
136 0 my $spec;
137 0 ▶ if( @_ == 1 && $self->_is_array( $_[0] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and $self->_is_array($_[0])) { } 0 0 0
elsif (@_) { } 0 0 0
Condition0%0/3
@_ == 1 and $self->_is_array($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and $self->_is_array($_[0])
@_ == 1 $self->_is_array($_[0])
Truth table0%0/3
A and B
A= @_ == 1B= $self->_is_array($_[0])
ABresult
0X0
100
111
138 {
139 0 $spec = shift( @_ );
140 }
141 elsif( @_ )
142 {
143 0 $spec = [@_];
144 }
145 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
146 return( $self->error( "No database handle could be found." ) );
147 my $table = $self->{table} ||
148 0 ▶ return( $self->error( "No table was provided." ) );
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided.'))
l!l
00
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided.'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
Aresult
11
00
149 0 ▶ return( $self->error( "No proper ALTER specification was provided." ) ) if( !defined( $spec ) || !@$spec );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec and @$spec 0 0 0
Condition0%0/3
defined $spec and @$spec
!ll&&!rl&&r
000
MC/DC0%0/2
defined $spec and @$spec
defined $spec @$spec
Truth table0%0/3
A and B
A= defined $specB= @$spec
ABresult
0X0
100
111
150 0 my $query = "ALTER TABLE $table " . CORE::join( ', ', @$spec );
151 0 ▶ my $sth = $dbo->prepare( $query ) ||
Condition0%0/2
$dbo->prepare($query) || (return $self->error("Error while preparing ALTER query to modify table '${table}':\n", $dbo->error))
l!l
00
MC/DC0%0/1
$dbo->prepare($query) || (return $self->error("Error while preparing ALTER query to modify table '${table}':\n", $dbo->error))
$dbo->prepare($query)
Truth table0%0/2
A
A= $dbo->prepare($query)
Aresult
11
00
152 return( $self->error( "Error while preparing ALTER query to modify table '$table':\n", $dbo->error ) );
153 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
154 {
155 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to ALTER table '${table}':\n", $self->as_string, $sth->errstr) 0 0 0
156 return( $self->error( "Error while executing query to ALTER table '$table':\n", $self->as_string(), $sth->errstr() ) );
157 }
158 0 return( $sth );
159 }
160  
161 sub as
162 1 ▶{
Subroutine as: called CC=3 SCAR=15.0
Pod documented
163 1 my $self = shift( @_ );
164 1 my $q = $self->_reset_query;
165 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
166 {
167 0 $self->{table_alias} = $_[0];
168 0 ▶ $self->prefixed( length( $_[0] ) > 0 ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] > 0 ? : 0 0 0
169 0 $q->table_alias( $self->{table_alias} );
170 }
171 1 return( $self->{table_alias} );
172 }
173  
174 sub attach
175 0 ▶{
Subroutine attach: not called CC=12 SCAR=50.5
Pod documented
176 0 my $self = shift( @_ );
177 0 ▶ my $dbo = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No DB::Object object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No DB::Object object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
178 return( $self->error( "No DB::Object object was provided." ) );
179 0 my $base_class = $self->base_class;
180 0 ▶ unless( $self->_is_a( $dbo => $base_class ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($dbo, $base_class)) 0 0 0
181 {
182 0 return( $self->error( "Value provided is not a ${base_class} object." ) );
183 }
184 0 ▶ $self->database_object( $dbo ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->database_object($dbo) or return $self->pass_error 0 0 0
185 0 $self->debug( $dbo->debug );
186 0 ▶ if( my $qo = $self->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $qo = $self->query_object) 0 0 0
187 {
188 0 ▶ unless( $self->_is_a( $qo => "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($qo, "${base_class}::Query")) 0 0 0
189 {
190 0 die( "Query object found (", $self->_str_val( $qo ), ") in this statement object is actually not a query object (${base_class}::Query) !" );
191 }
192 0 ▶ $self->_load_class( "${base_class}::Query" ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Query") or return $self->pass_error 0 0 0
193 # The attach method in the query object class can take either a table object, or a database object.
194 0 ▶ $qo->attach( $dbo ) || return( $self->pass_error( $qo->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$qo->attach($dbo) or return $self->pass_error($qo->error) 0 0 0
195 }
196 0 my $fields = $self->{fields};
197 0 ▶ if( $fields && ref( $fields ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if ($fields and ref $fields eq "HASH") 0 0 0
Condition0%0/3
$fields and ref $fields eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$fields and ref $fields eq "HASH"
$fields ref $fields eq "HASH"
Truth table0%0/3
A and B
A= $fieldsB= ref $fields eq "HASH"
ABresult
0X0
100
111
198 {
199 0 foreach my $field ( keys( %$fields ) )
200 {
201 0 my $fo = $fields->{ $field };
202 0 ▶ next unless( $self->_is_a( $fo => 'DB::Object::Fields::Field' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($fo, "DB::Object::Fields::Field") 0 0 0
203 0 $fo->table_object( $self );
204 }
205 }
206 0 return( $self );
207 }
208  
209 0 ▶sub avoid { return( shift->_method_to_query( 'avoid', @_ ) ); }
Subroutine avoid: not called CC=1 SCAR=6.9
Pod documented
210  
211 0 ▶sub check { return( shift->_set_get_hash_as_mix_object( 'check', @_ ) ); }
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
212  
213 sub clone
214 0 ▶{
Subroutine clone: not called CC=7 SCAR=40.3
Pod documented
215 0 my $self = shift( @_ );
216 # We make sure to not clone the DBI database handle object
217 0 my $dbo = CORE::delete( $self->{dbo} );
218 0 my( $qo, $query_dbo );
219 0 ▶ if( $qo = $self->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($qo = $self->query_object) 0 0 0
220 {
221 0 $query_dbo = CORE::delete( $qo->{database_object} );
222 }
223 0 ▶ my $new = $self->Module::Generic::clone ||
Condition0%0/2
$self->Module::Generic::clone || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->Module::Generic::clone || (return $self->pass_error)
$self->Module::Generic::clone
Truth table0%0/2
A
A= $self->Module::Generic::clone
Aresult
11
00
224 return( $self->pass_error );
225 0 ▶ $new->attach( $dbo ) if( defined( $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbo 0 0 0
226 0 ▶ $qo->attach( $query_dbo ) if( defined( $query_dbo ) && ( !$dbo || $query_dbo ne $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $query_dbo and !$dbo || $query_dbo ne $dbo 0 0 0
Condition0%0/6
defined $query_dbo and !$dbo || $query_dbo ne $dbo
!ll&&!rl&&r
000
not $dbo or $query_dbo ne $dbo
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $query_dbo and !$dbo || $query_dbo ne $dbo
defined $query_dbo not $dbo $query_dbo ne $dbo
Truth table0%0/4
A and not(B) or C
A= defined $query_dboB= not $dboC= $query_dbo ne $dbo
ABCresult
0XX0
1000
11X1
1011
227 0 return( $new );
228 }
229  
230 sub columns
231 0 ▶{
Subroutine columns: not called CC=1 SCAR=6.9
Pod documented
232 0 my $self = shift( @_ );
233 0 my $fields = $self->fields;
234 # my $cols = [sort{ $fields->{ $a } <=> $fields->{ $b } } keys( %$fields )];
235 0 my $cols = [sort{ $fields->{ $a }->pos <=> $fields->{ $b }->pos } keys( %$fields )];
236 0 return( $self->new_array( $cols ) );
237 }
238  
239 sub constant
240 0 ▶{
Subroutine constant: not called CC=4 SCAR=30.0
Pod documented
241 0 my $self = shift( @_ );
242 0 my( $pack, $file, $line ) = caller;
243 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
244 return( $self->error( "No database handle could be found." ) );
245 0 my $base_class = $dbo->base_class;
246 # This does not work for calls made internally
247 0 ▶ return( $self ) if( $pack =~ /^${base_class}\b/ );
Branch: 1 branch
BranchTrueFalseTotal
if $pack =~ /^$base_class\b/ 0 0 0
248 0 my $sth = $dbo->constant_queries_cache_get({
249 pack => $pack,
250 file => $file,
251 line => $line,
252 });
253 # $sth returned may be void if no cache was found or if the caller's file mod time has changed
254 0 my $q;
255 0 ▶ if( $sth )
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) { } 0 0 0
256 {
257 0 $q = $sth->query_object;
258 0 $self->query_object( $q );
259 }
260 else
261 {
262 0 $q = $self->_reset_query;
263 }
264 0 $q->constant({
265 sth => $sth,
266 pack => $pack,
267 file => $file,
268 line => $line,
269 });
270 0 return( $self );
271 }
272  
273 # sub create must be superseded by sub classes
274 sub create
275 0 ▶{
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
276 0 my $self = shift( @_ );
277 0 my $class = ref( $self );
278 0 return( $self->error( "create() is not implemented by $class." ) );
279 }
280  
281 sub create_info
282 0 ▶{
Subroutine create_info: not called CC=1 SCAR=6.9
Pod documented
283 0 my $self = shift( @_ );
284 0 my $class = ref( $self );
285 0 return( $self->error( "create_info() is not implemented by $class." ) );
286 }
287  
288 sub database
289 0 ▶{
Subroutine database: not called CC=2 SCAR=17.9
Pod documented
290 0 my $self = shift( @_ );
291 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
292 return( $self->error( "No database handle could be found." ) );
293 0 return( $dbo->database );
294 }
295  
296 22 ▶sub database_object { return( shift->_set_get_object_without_init( 'dbo', 'DB::Object', @_ ) ); }
Subroutine database_object: called CC=1 SCAR=0.0
Pod documented
297  
298 0 ▶sub dbo { return( shift->_set_get_object_without_init( 'dbo', 'DB::Object', @_ ) ); }
Subroutine dbo: not called CC=1 SCAR=6.9
Pod documented
299  
300 sub default
301 0 ▶{
Subroutine default: not called CC=3 SCAR=24.8
Pod documented
302 0 my $self = shift( @_ );
303 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
304 0 my $fields = $self->{fields};
305 0 ▶ my $default = +{ map{ defined( $fields->{ $_ }->default ) ? ( $_ => $fields->{ $_ }->default ) : () } keys( %$fields ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $fields->{$_}->default ? : 0 0 0
306 0 return( $default );
307 }
308  
309 sub delete
310 0 ▶{
Subroutine delete: not called CC=7 SCAR=40.3
Pod documented
311 0 my $self = shift( @_ );
312 0 my $q = $self->_reset_query;
313 # If the user wants to execute this, then we reset the query,
314 # but if the user wants to call other methods chained like as_string we don't do anything
315 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
316 0 ▶ if( want('VOID') || want('OBJECT') )
Branch: 1 branch
BranchTrueFalseTotal
if (want("VOID") or want("OBJECT")) 0 0 0
Condition0%0/3
want("VOID") or want("OBJECT")
l!l&&r!l&&!r
000
MC/DC0%0/2
want("VOID") or want("OBJECT")
want("VOID") want("OBJECT")
Truth table0%0/3
A or B
A= want("VOID")B= want("OBJECT")
ABresult
1X1
011
000
317 {
318 0 ▶ CORE::delete( $self->{query_reset} ) if( want('VOID') );
Branch: 1 branch
BranchTrueFalseTotal
if want("VOID") 0 0 0
319 # return( $q->select( @_ ) );
320 # return( $q->select( @_ ) ) if( !defined( wantarray() ) );
321 0 return( $q->delete( @_ ) );
322 }
323 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
324 # return( $q->delete( @_ ) );
325 # return( $q->delete( @_ ) ) if( !defined( wantarray() ) );
326 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
327 {
328 0 ▶ my( @val ) = $q->delete( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->delete(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->delete(@_) || (return $self->pass_error($q->error))
$q->delete(@_)
Truth table0%0/2
A
A= $q->delete(@_)
Aresult
11
00
329 0 $self->reset;
330 0 return( @val );
331 }
332 else
333 {
334 0 ▶ my $val = $q->delete( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->delete(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->delete(@_) || (return $self->pass_error($q->error))
$q->delete(@_)
Truth table0%0/2
A
A= $q->delete(@_)
Aresult
11
00
335 0 $self->reset;
336 0 return( $val );
337 }
338 }
339  
340 sub drop
341 0 ▶{
Subroutine drop: not called CC=6 SCAR=37.4
Pod documented
342 0 my $self = shift( @_ );
343 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
344 return( $self->error( "No database handle could be found." ) );
345 my $table = $self->{table} ||
346 0 ▶ return( $self->error( "No table was provided to drop." ) );
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to drop.'))
l!l
00
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to drop.'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
Aresult
11
00
347 0 my $query = "DROP TABLE $table";
348 0 ▶ my $sth = $dbo->prepare( $query ) ||
Condition0%0/2
$dbo->prepare($query) || (return $self->error("Error while preparing query to drop table '${table}':\n$query", $dbo->error))
l!l
00
MC/DC0%0/1
$dbo->prepare($query) || (return $self->error("Error while preparing query to drop table '${table}':\n$query", $dbo->error))
$dbo->prepare($query)
Truth table0%0/2
A
A= $dbo->prepare($query)
Aresult
11
00
349 return( $self->error( "Error while preparing query to drop table '$table':\n$query", $dbo->error ) );
350 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
351 {
352 0 ▶ $sth->execute ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to drop table '${table}':\n$query", $sth->errstr) 0 0 0
353 return( $self->error( "Error while executing query to drop table '$table':\n$query", $sth->errstr() ) );
354 }
355 0 return( $sth );
356 }
357  
358 # sub enhance { return( shift->_method_to_query( 'enhance', @_ ) ); }
359 sub enhance
360 0 ▶{
Subroutine enhance: not called CC=2 SCAR=17.9
Pod documented
361 0 my $self = shift( @_ );
362 0 ▶ if( my $dbo = $self->database_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbo = $self->database_object) { } 0 0 0
363 {
364 0 return( $dbo->enhance( @_ ) );
365 }
366 else
367 {
368 0 return( $self->_method_to_query( 'enhance', @_ ) );
369 }
370 }
371  
372 sub exists
373 0 ▶{
Subroutine exists: not called CC=3 SCAR=24.8
Pod documented
374 0 my $self = shift( @_ );
375 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
376 return( $self->error( "No database handle could be found." ) );
377 0 ▶ return( $dbo->table_exists( @_ ? shift( @_ ) : $self->{table} ) );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
378 }
379  
380 sub fields
381 0 ▶{
Subroutine fields: not called CC=8 SCAR=42.8
Pod documented
382 0 my $self = shift( @_ );
383 # The method 'structure' will fetch and cache the table structure, and set the instance property 'fields' containing an hash reference of all table fields to their DB::Object::Fields::Field instance.
384 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
385 0 my $fields = $self->{fields};
386 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
387 {
388 0 my $field = shift( @_ );
389 0 ▶ return( $self->error( "No field name was provided." ) ) if( !CORE::length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
390 0 ▶ my $obj = $fields->{ $field } || return( $self->error( "No field object found for \"", ( $field // 'undef' ), "\"." ) );
Condition0%0/4
$fields->{$field} || (return $self->error('No field object found for "', $field // 'undef', '".'))
l!l
00
$field // "undef"
l!l
00
MC/DC0%0/1
$fields->{$field} || (return $self->error('No field object found for "', $field // 'undef', '".'))
$fields->{$field}
MC/DC0%0/1
$field // "undef"
$field
Truth table0%0/2
A
A= $fields->{$field}
Aresult
11
00
Truth table0%0/2
A
A= $field
Aresult
11
00
391 # NOTE: We return the canonical Field object directly rather than cloning it.
392 # The immediate caller (_initiate_field_object) overwrites table_object,
393 # query_object, prefixed, and debug right after this call, so a full Clone::clone
394 # of all the field data attributes (name, type, pos, is_nullable, etc.) is wasteful.
395 # The data attributes are read-only after structure() populates them.
396 0 return( $obj );
397 }
398 # return( +{ map{ $_ => $fields->{ $_ }->clone } keys( %$fields ) } );
399 0 my $ref = {};
400 # NOTE: Return the canonical Field objects directly rather than cloning each one.
401 # Fields are populated once by structure() and their data attributes (name, type,
402 # pos, is_nullable, etc.) are never modified after that. The mutable attributes
403 # (table_object, query_object, prefixed, debug) are always overwritten by the caller.
404 0 foreach my $f ( keys( %$fields ) )
405 {
406 0 $fields->{ $f }->debug( $self->debug );
407 0 $ref->{ $f } = $fields->{ $f };
408 }
409 0 return( $ref );
410 }
411  
412 sub fields_as_array
413 0 ▶{
Subroutine fields_as_array: not called CC=2 SCAR=17.9
Pod documented
414 0 my $self = shift( @_ );
415 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
416 0 my $fields = $self->{fields};
417 0 return( $self->new_array( [sort{ $fields->{ $a }->pos <=> $fields->{ $b }->pos } keys( %$fields )] ) );
418 }
419  
420 sub field_exists
421 0 ▶{
Subroutine field_exists: not called CC=3 SCAR=24.8
Pod documented
422 0 my $self = shift( @_ );
423 0 ▶ my $field = shift( @_ ) || return( $self->error( "No field was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No field was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No field was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
424 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
425 0 my $fields = $self->{fields};
426 0 return( CORE::exists( $fields->{ $field } ) );
427 }
428  
429 sub fields_object
430 0 ▶{
Subroutine fields_object: not called CC=6 SCAR=37.4
Pod documented
431 0 my $self = shift( @_ );
432 0 my $o = $self->{fields_object};
433 # This will make sure we have a query object which DB::Object::Fields and DB::Object::Field need
434 0 $self->_reset_query;
435 0 my $qo = $self->query_object;
436 0 $qo->table_object( $self );
437 0 ▶ if( $o && $self->_is_object( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($o and $self->_is_object($o)) 0 0 0
Condition0%0/3
$o and $self->_is_object($o)
!ll&&!rl&&r
000
MC/DC0%0/2
$o and $self->_is_object($o)
$o $self->_is_object($o)
Truth table0%0/3
A and B
A= $oB= $self->_is_object($o)
ABresult
0X0
100
111
438 {
439 0 $o->prefixed( $self->{prefixed} );
440 0 $o->query_object( $qo );
441 0 return( $o );
442 }
443 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
444 return( $self->error( "No database handle could be found." ) );
445 0 my $db_name = $dbo->database;
446 0 $db_name =~ tr/-/_/;
447 0 $db_name =~ s/\_{2,}/_/g;
448 0 $db_name = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $db_name ) ) );
449 0 my $name = $self->name;
450 0 my $new_class = $name;
451 0 $new_class =~ tr/-/_/;
452 0 $new_class =~ s/\_{2,}/_/g;
453 0 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
454 0 my $class = ref( $self ) . "\::${db_name}\::${new_class}";
455 0 ▶ if( !$self->_is_class_loaded( $class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_is_class_loaded($class)) { } 0 0 0
456 {
457 0 my $perl = <<EOT;
458 package $class;
459 BEGIN
460 {
461 use strict;
462 use parent qw( DB::Object::Fields );
463 };
464  
465 1;
466  
467 EOT
468 0 my $rc = eval( $perl );
469 0 ▶ die( "Unable to dynamically create module $class: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
470 }
471 else
472 {
473 # Class already exists
474 }
475 $o = $class->new(
476 prefixed => $self->{prefixed},
477 # For table alias
478 # query_object => $self->query_object,
479 # query_object => $qo,
480 0 table_object => $self,
481 debug => $self->debug,
482 );
483 0 $o->prefixed( $self->{prefixed} );
484 0 $self->{fields_object} = $o;
485 0 return( $o );
486 }
487  
488 0 ▶sub fo { return( shift->fields_object( @_ ) ); }
Subroutine fo: not called CC=1 SCAR=6.9
Pod documented
489  
490 0 ▶sub foreign { return( shift->_set_get_hash_as_mix_object( 'foreign', @_ ) ); }
Subroutine foreign: not called CC=1 SCAR=6.9
Pod documented
491  
492 0 ▶sub format_statement($;\%\%@) { return( shift->_method_to_query( 'format_statement', @_ ) ); }
Subroutine format_statement: not called CC=1 SCAR=6.9
Pod documented
493  
494 0 ▶sub format_update($;%) { return( shift->_method_to_query( 'format_update', @_ ) ); }
Subroutine format_update: not called CC=1 SCAR=6.9
Pod documented
495  
496 0 ▶sub from_unixtime { return( shift->_method_to_query( 'from_unixtime', @_ ) ); }
Subroutine from_unixtime: not called CC=1 SCAR=6.9
Pod documented
497  
498 0 ▶sub get_query_object { return( shift->_reset_query ); }
Subroutine get_query_object: not called CC=1 SCAR=6.9
Pod documented
499  
500 0 ▶sub group { return( shift->_method_to_query( 'group', @_ ) ); }
Subroutine group: not called CC=1 SCAR=6.9
Pod documented
501  
502 0 ▶sub having { return( shift->_method_to_query( 'having', @_ ) ); }
Subroutine having: not called CC=1 SCAR=6.9
Pod documented
503  
504 # sub indexes { return( shift->_set_get_class_array_object( 'indexes', {
505 # is_primary => { type => 'boolean' },
506 # is_unique => { type => 'boolean' },
507 # fields => { type => 'array_as_object' },
508 # }, @_ ) ); }
509 0 ▶sub indexes { return( shift->_set_get_hash_as_mix_object( 'indexes', @_ ) ); }
Subroutine indexes: not called CC=1 SCAR=6.9
Pod documented
510  
511 sub insert
512 0 ▶{
Subroutine insert: not called CC=7 SCAR=40.3
Pod documented
513 0 my $self = shift( @_ );
514 0 my $q = $self->_reset_query;
515 # If the user wants to execute this, then we reset the query,
516 # but if the user wants to call other methods chained like as_string we don't do anything
517 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
518 0 ▶ if( want('VOID') || want('OBJECT') )
Branch: 1 branch
BranchTrueFalseTotal
if (want("VOID") or want("OBJECT")) 0 0 0
Condition0%0/3
want("VOID") or want("OBJECT")
l!l&&r!l&&!r
000
MC/DC0%0/2
want("VOID") or want("OBJECT")
want("VOID") want("OBJECT")
Truth table0%0/3
A or B
A= want("VOID")B= want("OBJECT")
ABresult
1X1
011
000
519 {
520 0 ▶ CORE::delete( $self->{query_reset} ) if( want('VOID') );
Branch: 1 branch
BranchTrueFalseTotal
if want("VOID") 0 0 0
521 # return( $q->select( @_ ) );
522 # return( $q->select( @_ ) ) if( !defined( wantarray() ) );
523 0 return( $q->insert( @_ ) );
524 }
525 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
526 # return( $q->insert( @_ ) ) if( !defined( wantarray() ) );
527 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
528 {
529 0 ▶ my( @val ) = $q->insert( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->insert(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->insert(@_) || (return $self->pass_error($q->error))
$q->insert(@_)
Truth table0%0/2
A
A= $q->insert(@_)
Aresult
11
00
530 0 $self->reset;
531 0 return( @val );
532 }
533 else
534 {
535 0 ▶ my $val = $q->insert( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->insert(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->insert(@_) || (return $self->pass_error($q->error))
$q->insert(@_)
Truth table0%0/2
A
A= $q->insert(@_)
Aresult
11
00
536 0 $self->reset;
537 0 return( $val );
538 }
539 }
540  
541 0 ▶sub limit { return( shift->_method_to_query( 'limit', @_ ) ); }
Subroutine limit: not called CC=1 SCAR=6.9
Pod documented
542  
543 0 ▶sub local { return( shift->_method_to_query( 'local', @_ ) ); }
Subroutine local: not called CC=1 SCAR=6.9
Pod documented
544  
545 sub lock
546 0 ▶{
Subroutine lock: not called CC=1 SCAR=6.9
Pod documented
547 0 my $self = shift( @_ );
548 0 my $class = ref( $self );
549 0 return( $self->error( "lock() is not implemented by $class." ) );
550 }
551  
552 sub name
553 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
554 # Read-only
555 0 return( shift->{table} );
556 }
557  
558 sub new_check
559 0 ▶{
Subroutine new_check: not called CC=5 SCAR=34.0
Pod documented
560 0 my $self = shift( @_ );
561 0 my $args = $self->_get_args_as_hash( @_ );
562 0 ▶ $self->_load_class( 'DB::Object::Constraint::Check' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Check") or return $self->pass_error 0 0 0
563 return( $self->pass_error );
564 0 ▶ $args->{debug} = $self->debug if( !CORE::exists( $args->{debug} ) || !defined( $args->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"debug"} and defined $args->{"debug"} 0 0 0
Condition0%0/3
exists $args->{"debug"} and defined $args->{"debug"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args->{"debug"} and defined $args->{"debug"}
exists $args->{"debug"} defined $args->{"debug"}
Truth table0%0/3
A and B
A= exists $args->{"debug"}B= defined $args->{"debug"}
ABresult
0X0
100
111
565 0 ▶ my $this = DB::Object::Constraint::Check->new( %$args ) ||
Condition0%0/2
'DB::Object::Constraint::Check'->new(%$args) || (return $self->pass_error('DB::Object::Constraint::Check'->error))
l!l
00
MC/DC0%0/1
'DB::Object::Constraint::Check'->new(%$args) || (return $self->pass_error('DB::Object::Constraint::Check'->error))
'DB::Object::Constraint::Check'->new(%$args)
Truth table0%0/2
A
A= 'DB::Object::Constraint::Check'->new(%$args)
Aresult
11
00
566 return( $self->pass_error( DB::Object::Constraint::Check->error ) );
567 0 return( $this );
568 }
569  
570 sub new_foreign
571 0 ▶{
Subroutine new_foreign: not called CC=5 SCAR=34.0
Pod documented
572 0 my $self = shift( @_ );
573 0 my $args = $self->_get_args_as_hash( @_ );
574 0 ▶ $self->_load_class( 'DB::Object::Constraint::Foreign' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Foreign") or return $self->pass_error 0 0 0
575 return( $self->pass_error );
576 0 ▶ $args->{debug} = $self->debug if( !CORE::exists( $args->{debug} ) || !defined( $args->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"debug"} and defined $args->{"debug"} 0 0 0
Condition0%0/3
exists $args->{"debug"} and defined $args->{"debug"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args->{"debug"} and defined $args->{"debug"}
exists $args->{"debug"} defined $args->{"debug"}
Truth table0%0/3
A and B
A= exists $args->{"debug"}B= defined $args->{"debug"}
ABresult
0X0
100
111
577 0 ▶ my $this = DB::Object::Constraint::Foreign->new( %$args ) ||
Condition0%0/2
'DB::Object::Constraint::Foreign'->new(%$args) || (return $self->pass_error('DB::Object::Constraint::Foreign'->error))
l!l
00
MC/DC0%0/1
'DB::Object::Constraint::Foreign'->new(%$args) || (return $self->pass_error('DB::Object::Constraint::Foreign'->error))
'DB::Object::Constraint::Foreign'->new(%$args)
Truth table0%0/2
A
A= 'DB::Object::Constraint::Foreign'->new(%$args)
Aresult
11
00
578 return( $self->pass_error( DB::Object::Constraint::Foreign->error ) );
579 0 return( $this );
580 }
581  
582 sub new_index
583 0 ▶{
Subroutine new_index: not called CC=5 SCAR=34.0
Pod documented
584 0 my $self = shift( @_ );
585 0 my $args = $self->_get_args_as_hash( @_ );
586 0 ▶ $self->_load_class( 'DB::Object::Constraint::Index' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DB::Object::Constraint::Index") or return $self->pass_error 0 0 0
587 return( $self->pass_error );
588 0 ▶ $args->{debug} = $self->debug if( !CORE::exists( $args->{debug} ) || !defined( $args->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"debug"} and defined $args->{"debug"} 0 0 0
Condition0%0/3
exists $args->{"debug"} and defined $args->{"debug"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args->{"debug"} and defined $args->{"debug"}
exists $args->{"debug"} defined $args->{"debug"}
Truth table0%0/3
A and B
A= exists $args->{"debug"}B= defined $args->{"debug"}
ABresult
0X0
100
111
589 0 ▶ my $this = DB::Object::Constraint::Index->new( %$args ) ||
Condition0%0/2
'DB::Object::Constraint::Index'->new(%$args) || (return $self->pass_error('DB::Object::Constraint::Index'->error))
l!l
00
MC/DC0%0/1
'DB::Object::Constraint::Index'->new(%$args) || (return $self->pass_error('DB::Object::Constraint::Index'->error))
'DB::Object::Constraint::Index'->new(%$args)
Truth table0%0/2
A
A= 'DB::Object::Constraint::Index'->new(%$args)
Aresult
11
00
590 return( $self->pass_error( DB::Object::Constraint::Index->error ) );
591 0 return( $this );
592 }
593  
594 0 ▶sub no_bind { return( shift->_set_get_boolean({
Subroutine no_bind: not called CC=1 SCAR=6.9
Pod documented
595 field => 'no_bind',
596 callbacks =>
597 {
598 set => sub
599 0 ▶ {
Subroutine __ANON__: not called CC=11 SCAR=48.8
600 0 my $self = shift( @_ );
601 0 my $val = shift( @_ );
602 0 ▶ return if( !defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
603 0 ▶ return( $val ) if( !$val );
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
604 0 my $q = $self->_reset_query;
605 0 my $where = $q->where();
606 0 my $group = $q->group();
607 0 my $order = $q->order();
608 0 my $limit = $q->limit();
609 0 my $binded_where = $q->binded_where;
610 0 my $binded_group = $q->binded_group;
611 0 my $binded_order = $q->binded_order;
612 0 my $binded_limit = $q->binded_limit;
613 # Replace the placeholders by their corresponding value
614 # and have them re-processed by their corresponding method
615 0 ▶ if( $where && @$binded_where )
Branch: 1 branch
BranchTrueFalseTotal
if ($where and @$binded_where) 0 0 0
Condition0%0/3
$where and @$binded_where
!ll&&!rl&&r
000
MC/DC0%0/2
$where and @$binded_where
$where @$binded_where
Truth table0%0/3
A and B
A= $whereB= @$binded_where
ABresult
0X0
100
111
616 {
617 0 $where =~ s/(=\s*\?)/"='" . quotemeta( $binded_where->[ $#+ ] ) . "'"/ge;
618 0 $self->where( $where );
619 }
620 0 ▶ if( $group && @$binded_group )
Branch: 1 branch
BranchTrueFalseTotal
if ($group and @$binded_group) 0 0 0
Condition0%0/3
$group and @$binded_group
!ll&&!rl&&r
000
MC/DC0%0/2
$group and @$binded_group
$group @$binded_group
Truth table0%0/3
A and B
A= $groupB= @$binded_group
ABresult
0X0
100
111
621 {
622 0 $group =~ s/(=\s*\?)/"='" . quotemeta( $binded_group->[ $#+ ] ) . "'"/ge;
623 0 $self->group( $group );
624 }
625 0 ▶ if( $order && @$binded_order )
Branch: 1 branch
BranchTrueFalseTotal
if ($order and @$binded_order) 0 0 0
Condition0%0/3
$order and @$binded_order
!ll&&!rl&&r
000
MC/DC0%0/2
$order and @$binded_order
$order @$binded_order
Truth table0%0/3
A and B
A= $orderB= @$binded_order
ABresult
0X0
100
111
626 {
627 0 $order =~ s/(=\s*\?)/"='" . quotemeta( $binded_order->[ $#+ ] ) . "'"/ge;
628 0 $self->order( $order );
629 }
630 0 ▶ if( $limit && @$binded_limit )
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @$binded_limit) 0 0 0
Condition0%0/3
$limit and @$binded_limit
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and @$binded_limit
$limit @$binded_limit
Truth table0%0/3
A and B
A= $limitB= @$binded_limit
ABresult
0X0
100
111
631 {
632 # $limit =~ s/(=\s*\?)/"='" . quotemeta( $binded_limit[ $#+ ] ) . "'"/ge;
633 0 $self->limit( @$binded_limit );
634 }
635 0 $q->reset_bind;
636 0 return( $val );
637 },
638 }
639 0 }, @_ ) ); }
640  
641 sub null
642 0 ▶{
Subroutine null: not called CC=3 SCAR=24.8
Pod documented
643 0 my $self = shift( @_ );
644 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
645 0 my $fields = $self->fields;
646 # my $null = $self->{null};
647 0 ▶ my $null = +{ map{ $_ => ( $fields->{ $_ }->is_nullable ? 1 : 0 ) } keys( %$fields ) };
Branch: 1 branch
BranchTrueFalseTotal
$fields->{$_}->is_nullable ? : 0 0 0
648 0 return( $self->_clone( $null ) );
649 }
650  
651 0 ▶sub on_conflict { return( shift->error( "The on conflict clause is not supported by this driver." ) ); }
Subroutine on_conflict: not called CC=1 SCAR=6.9
Pod documented
652  
653 sub optimize
654 0 ▶{
Subroutine optimize: not called CC=1 SCAR=6.9
Pod documented
655 0 my $self = shift( @_ );
656 0 my $class = ref( $self );
657 0 return( $self->error( "optimize() is not implemented by $class." ) );
658 }
659  
660 0 ▶sub order { return( shift->_method_to_query( 'order', @_ ) ); }
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
661  
662 0 ▶sub parent { return( shift->error( "The table parent() method is not supported by this driver." ) ); }
Subroutine parent: not called CC=1 SCAR=6.9
Pod documented
663  
664 sub prefix
665 0 ▶{
Subroutine prefix: not called CC=9 SCAR=45.0
Pod documented
666 0 my $self = shift( @_ );
667 0 my @val = ();
668 0 my $alias = $self->query_object->table_alias;
669 0 ▶ return( $alias ) if( $alias && $self->{prefixed} > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $alias and $self->{"prefixed"} > 0 0 0 0
Condition0%0/3
$alias and $self->{"prefixed"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$alias and $self->{"prefixed"} > 0
$alias $self->{"prefixed"} > 0
Truth table0%0/3
A and B
A= $aliasB= $self->{"prefixed"} > 0
ABresult
0X0
100
111
670 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
671 return( $self->error( "No database handle could be found." ) );
672 0 ▶ CORE::push( @val, $dbo->database ) if( $self->{prefixed} > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefixed"} > 2 0 0 0
673 0 ▶ CORE::push( @val, $self->schema ) if( $self->{prefixed} > 1 && $self->schema );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefixed"} > 1 and $self->schema 0 0 0
Condition0%0/3
$self->{"prefixed"} > 1 and $self->schema
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"prefixed"} > 1 and $self->schema
$self->{"prefixed"} > 1 $self->schema
Truth table0%0/3
A and B
A= $self->{"prefixed"} > 1B= $self->schema
ABresult
0X0
100
111
674 0 ▶ CORE::push( @val, $self->name ) if( $self->{prefixed} > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefixed"} > 0 0 0 0
675 0 ▶ return( '' ) if( !scalar( @val ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @val 0 0 0
676 0 return( CORE::join( '.', @val ) );
677 }
678  
679 0 ▶sub prefix_database { return( shift->{prefixed} > 2 ); }
Subroutine prefix_database: not called CC=1 SCAR=6.9
Pod documented
680  
681 0 ▶sub prefix_schema { return( shift->{prefixed} > 1 ); }
Subroutine prefix_schema: not called CC=1 SCAR=6.9
Pod documented
682  
683 0 ▶sub prefix_table { return( shift->{prefixed} > 0 ); }
Subroutine prefix_table: not called CC=1 SCAR=6.9
Pod documented
684  
685 # This the prefix intended for field in query
686 sub prefixed
687 0 ▶{
Subroutine prefixed: not called CC=5 SCAR=34.0
Pod documented
688 0 my $self = shift( @_ );
689 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
690 {
691 0 ▶ $self->{prefixed} = ( $_[0] =~ /^\d+$/ ? $_[0] : ( $_[0] ? 1 : 0 ) );
Branch: 2 branches
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 0 0 0
$_[0] ? : 0 0 0
692 }
693 else
694 {
695 0 $self->{prefixed} = 1;
696 }
697 0 my $fo = $self->{fields_object};
698 0 ▶ $fo->prefixed( $self->{prefixed} ) if( $fo );
Branch: 1 branch
BranchTrueFalseTotal
if $fo 0 0 0
699 # return( want( 'OBJECT' ) ? $self : $self->{prefixed} );
700 0 return( $self->{prefixed} );
701 }
702  
703 sub primary
704 0 ▶{
Subroutine primary: not called CC=2 SCAR=17.9
Pod documented
705 0 my $self = shift( @_ );
706 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
707 0 my $primary = $self->{primary};
708 # return( wantarray() ? () : undef() ) if( !$primary || !@$primary );
709 # return( wantarray() ? @$primary : \@$primary );
710 0 return( $self->_clone( $primary ) );
711 }
712  
713 # In PostgreSQL, Oracle, SQL server this would be schema_name.table_name
714 0 ▶sub qualified_name { return( shift->name ); }
Subroutine qualified_name: not called CC=1 SCAR=6.9
Pod documented
715  
716 46 ▶sub query_object { return( shift->_set_get_object_without_init( 'query_object', 'DB::Object::Query', @_ ) ); }
Subroutine query_object: called CC=1 SCAR=0.0
Pod documented
717  
718 0 ▶sub query_reset { return( shift->_set_get_scalar( 'query_reset', @_ ) ); }
Subroutine query_reset: not called CC=1 SCAR=6.9
Pod documented
719  
720 sub rename
721 0 ▶{
Subroutine rename: not called CC=1 SCAR=6.9
Pod documented
722 0 my $self = shift( @_ );
723 0 my $class = ref( $self );
724 0 return( $self->error( "rename() is not implemented by $class." ) );
725 }
726  
727 sub repair
728 0 ▶{
Subroutine repair: not called CC=1 SCAR=6.9
Pod documented
729 0 my $self = shift( @_ );
730 0 my $class = ref( $self );
731 0 return( $self->error( "repair() is not implemented by $class." ) );
732 }
733  
734 sub replace
735 0 ▶{
Subroutine replace: not called CC=7 SCAR=40.3
Pod documented
736 0 my $self = shift( @_ );
737 0 my $q = $self->_reset_query;
738 # If the user wants to execute this, then we reset the query,
739 # but if the user wants to call other methods chained like as_string we don't do anything
740 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
741 0 ▶ if( want('VOID') || want('OBJECT') )
Branch: 1 branch
BranchTrueFalseTotal
if (want("VOID") or want("OBJECT")) 0 0 0
Condition0%0/3
want("VOID") or want("OBJECT")
l!l&&r!l&&!r
000
MC/DC0%0/2
want("VOID") or want("OBJECT")
want("VOID") want("OBJECT")
Truth table0%0/3
A or B
A= want("VOID")B= want("OBJECT")
ABresult
1X1
011
000
742 {
743 0 ▶ CORE::delete( $self->{query_reset} ) if( want('VOID') );
Branch: 1 branch
BranchTrueFalseTotal
if want("VOID") 0 0 0
744 # return( $q->select( @_ ) );
745 # return( $q->select( @_ ) ) if( !defined( wantarray() ) );
746 0 return( $q->replace( @_ ) );
747 }
748 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
749 # return( $q->replace( @_ ) );
750 # return( $q->replace( @_ ) ) if( !defined( wantarray() ) );
751 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
752 {
753 0 ▶ my( @val ) = $q->replace( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->replace(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->replace(@_) || (return $self->pass_error($q->error))
$q->replace(@_)
Truth table0%0/2
A
A= $q->replace(@_)
Aresult
11
00
754 0 return( @val );
755 }
756 else
757 {
758 0 ▶ my $val = $q->replace( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->replace(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->replace(@_) || (return $self->pass_error($q->error))
$q->replace(@_)
Truth table0%0/2
A
A= $q->replace(@_)
Aresult
11
00
759 0 return( $val );
760 }
761 }
762  
763 sub reset
764 1 ▶{
Subroutine reset: called CC=2 SCAR=7.0
Pod documented
765 1 my $self = shift( @_ );
766 1 CORE::delete( $self->{query_reset} );
767 1 ▶ $self->_reset_query( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_reset_query(@_) or return $self->pass_error 1 0 1
768 1 CORE::delete( $self->{fields_object} );
769 # To allow chaining of commands
770 1 return( $self );
771 }
772  
773 sub reset_structure
774 0 ▶{
Subroutine reset_structure: not called CC=4 SCAR=30.0
Pod documented
775 0 my $self = shift( @_ );
776 0 ▶ if( !CORE::length( $self->{_reset_structure} // '' ) && scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length($self->{"_reset_structure"} // "") and scalar @_) 0 0 0
Condition0%0/4
not length($self->{"_reset_structure"} // "") and scalar @_
!ll
00
$self->{"_reset_structure"} // ""
l!l
00
MC/DC0%0/1
not length($self->{"_reset_structure"} // "") and scalar @_
$self->{"_reset_structure"}
Truth table0%0/2
not(A)
A= $self->{"_reset_structure"}
Aresult
10
01
777 {
778 0 $self->{_reset_structure} = scalar( @_ );
779 }
780 0 return( $self );
781 }
782  
783 # Modelled after PostgreSQL and available since 3.35.0 released 2021-03-12
784 # <https://www.sqlite.org/lang_returning.html>
785 0 ▶sub returning { return( shift->_method_to_query( 'returning', @_ ) ); }
Subroutine returning: not called CC=1 SCAR=6.9
Pod documented
786  
787 sub reverse
788 0 ▶{
Subroutine reverse: not called CC=3 SCAR=24.8
Pod documented
789 0 my $self = shift( @_ );
790 0 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
elsif (Wanted::want('VOID')) { } 0 0 0
791 {
792 0 my $q = $self->_reset_query;
793 0 $self->{reverse} = shift( @_ );
794 0 $q->reverse( $self->{reverse} );
795 }
796 elsif( Wanted::want( 'VOID' ) )
797 {
798 0 my $q = $self->_reset_query;
799 0 $self->{reverse}++;
800 0 $q->reverse( $self->{reverse} );
801 }
802 0 return( $self->{reverse} );
803 }
804  
805 0 ▶sub schema { return( shift->_set_get_scalar( 'schema', @_ ) ); }
Subroutine schema: not called CC=1 SCAR=6.9
Pod documented
806  
807 sub select
808 0 ▶{
Subroutine select: not called CC=7 SCAR=40.3
Pod documented
809 0 my $self = shift( @_ );
810 0 my $q = $self->_reset_query;
811 # If the user wants to execute this, then we reset the query,
812 # but if the user wants to call other methods chained like as_string we don't do anything
813 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
814 0 ▶ if( want('VOID') || want('OBJECT') )
Branch: 1 branch
BranchTrueFalseTotal
if (want("VOID") or want("OBJECT")) 0 0 0
Condition0%0/3
want("VOID") or want("OBJECT")
l!l&&r!l&&!r
000
MC/DC0%0/2
want("VOID") or want("OBJECT")
want("VOID") want("OBJECT")
Truth table0%0/3
A or B
A= want("VOID")B= want("OBJECT")
ABresult
1X1
011
000
815 {
816 0 ▶ CORE::delete( $self->{query_reset} ) if( want('VOID') );
Branch: 1 branch
BranchTrueFalseTotal
if want("VOID") 0 0 0
817 # return( $q->select( @_ ) );
818 # return( $q->select( @_ ) ) if( !defined( wantarray() ) );
819 0 return( $q->select( @_ ) );
820 }
821  
822 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
823 {
824 0 ▶ my( @val ) = $q->select( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->select(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->select(@_) || (return $self->pass_error($q->error))
$q->select(@_)
Truth table0%0/2
A
A= $q->select(@_)
Aresult
11
00
825 # a statement handler is returned and we reset the query so that other calls would not use the previous DB::Object::Query object
826 0 $self->reset;
827 0 return( @val );
828 }
829 else
830 {
831 0 ▶ my $val = $q->select( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->select(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->select(@_) || (return $self->pass_error($q->error))
$q->select(@_)
Truth table0%0/2
A
A= $q->select(@_)
Aresult
11
00
832 0 $self->reset;
833 0 return( $val );
834 }
835 }
836  
837 sub sort
838 0 ▶{
Subroutine sort: not called CC=5 SCAR=34.0
Pod documented
839 0 my $self = shift( @_ );
840 0 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
elsif (Wanted::want('VOID')) { } 0 0 0
841 {
842 0 my $q = $self->_reset_query;
843 0 my $v = shift( @_ );
844 0 ▶ $self->{reverse} = ( ( defined( $v ) && $v > 0 ) ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $v && $v > 0 ? : 0 0 0
Condition0%0/3
defined $v and $v > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and $v > 0
defined $v $v > 0
Truth table0%0/3
A and B
A= defined $vB= $v > 0
ABresult
0X0
100
111
845 0 $q->sort( $self->{reverse} );
846 }
847 elsif( Wanted::want( 'VOID' ) )
848 {
849 0 my $q = $self->_reset_query;
850 0 $self->{reverse} = 0;
851 0 $q->sort( $self->{reverse} );
852 }
853 0 return( $self->{reverse} );
854 }
855  
856 sub stat
857 0 ▶{
Subroutine stat: not called CC=1 SCAR=6.9
Pod documented
858 0 my $self = shift( @_ );
859 0 my $class = ref( $self );
860 0 return( $self->error( "stat() is not implemented by $class." ) );
861 }
862  
863 # sub structure must be superseded by sub classes
864 sub structure
865 0 ▶{
Subroutine structure: not called CC=1 SCAR=6.9
Pod documented
866 0 my $self = shift( @_ );
867 0 my $class = ref( $self );
868 0 return( $self->error( "structure() is not implemented by $class." ) );
869 }
870  
871 0 ▶sub table { return( shift->{table} ); }
Subroutine table: not called CC=1 SCAR=6.9
Pod documented
872  
873 sub tie
874 0 ▶{
Subroutine tie: not called CC=1 SCAR=6.9
Pod documented
875 0 my $self = shift( @_ );
876 0 my $q = $self->_reset_query;
877 0 return( $q->tie( @_ ) );
878 }
879  
880 0 ▶sub type { return( shift->_set_get_scalar( 'type', @_ ) ); }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
881  
882 sub types
883 0 ▶{
Subroutine types: not called CC=2 SCAR=17.9
Pod documented
884 0 my $self = shift( @_ );
885 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
886 # my $types = $self->{types};
887 0 my $fields = $self->fields;
888 0 my $types = +{ map{ $_ => $fields->{ $_ }->type } keys( %$fields ) };
889 # return( $self->_clone( $types ) );
890 0 return( $types );
891 }
892  
893 sub types_const
894 0 ▶{
Subroutine types_const: not called CC=2 SCAR=17.9
Pod documented
895 0 my $self = shift( @_ );
896 0 ▶ $self->structure || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->structure or return $self->pass_error 0 0 0
897 0 my $fields = $self->fields;
898 # my $types = $self->{types_const};
899 0 my $types = +{ map{ $_ => $fields->{ $_ }->datatype } keys( %$fields ) };
900 # return( $self->_clone( $types ) );
901 0 return( $types );
902 }
903  
904 sub unlock
905 0 ▶{
Subroutine unlock: not called CC=1 SCAR=6.9
Pod documented
906 0 my $self = shift( @_ );
907 0 my $class = ref( $self );
908 0 return( $self->error( "unlock() is not implemented by $class." ) );
909 }
910  
911 0 ▶sub unix_timestamp { return( shift->_method_to_query( 'unix_timestamp', @_ ) ); }
Subroutine unix_timestamp: not called CC=1 SCAR=6.9
Pod documented
912  
913 sub update
914 0 ▶{
Subroutine update: not called CC=7 SCAR=40.3
Pod documented
915 0 my $self = shift( @_ );
916 0 my $q = $self->_reset_query;
917 # If the user wants to execute this, then we reset the query,
918 # but if the user wants to call other methods chained like as_string we don't do anything
919 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
920 0 ▶ if( want('VOID') || want('OBJECT') )
Branch: 1 branch
BranchTrueFalseTotal
if (want("VOID") or want("OBJECT")) 0 0 0
Condition0%0/3
want("VOID") or want("OBJECT")
l!l&&r!l&&!r
000
MC/DC0%0/2
want("VOID") or want("OBJECT")
want("VOID") want("OBJECT")
Truth table0%0/3
A or B
A= want("VOID")B= want("OBJECT")
ABresult
1X1
011
000
921 {
922 0 ▶ CORE::delete( $self->{query_reset} ) if( want('VOID') );
Branch: 1 branch
BranchTrueFalseTotal
if want("VOID") 0 0 0
923 # return( $q->select( @_ ) );
924 # return( $q->select( @_ ) ) if( !defined( wantarray() ) );
925 0 return( $q->update( @_ ) );
926 }
927 # CORE::delete( $self->{query_reset} ) if( !defined( wantarray() ) );
928 # return( $q->update( @_ ) );
929 # return( $q->update( @_ ) ) if( !defined( wantarray() ) );
930 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
931 {
932 0 ▶ my( @val ) = $q->update( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->update(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->update(@_) || (return $self->pass_error($q->error))
$q->update(@_)
Truth table0%0/2
A
A= $q->update(@_)
Aresult
11
00
933 0 $self->reset;
934 0 return( @val );
935 }
936 else
937 {
938 0 ▶ my $val = $q->update( @_ ) || return( $self->pass_error( $q->error ) );
Condition0%0/2
$q->update(@_) || (return $self->pass_error($q->error))
l!l
00
MC/DC0%0/1
$q->update(@_) || (return $self->pass_error($q->error))
$q->update(@_)
Truth table0%0/2
A
A= $q->update(@_)
Aresult
11
00
939 0 $self->reset;
940 0 return( $val );
941 }
942 }
943  
944 0 ▶sub where { return( shift->_method_to_query( 'where', @_ ) ); }
Subroutine where: not called CC=1 SCAR=6.9
Pod documented
945  
946 sub _method_to_query
947 0 ▶{
Subroutine _method_to_query: not called CC=4 SCAR=30.0
948 0 my $self = shift( @_ );
949 0 my $meth = shift( @_ );
950 0 my $q = $self->_reset_query;
951 0 ▶ my $code = $q->can( $meth ) || return( $self->error( "Query class '", ref( $q ), "' has no method '$meth'." ) );
Condition0%0/2
$q->can($meth) || (return $self->error(q[Query class '], ref $q, "' has no method '${meth}'."))
l!l
00
MC/DC0%0/1
$q->can($meth) || (return $self->error(q[Query class '], ref $q, "' has no method '${meth}'."))
$q->can($meth)
Truth table0%0/2
A
A= $q->can($meth)
Aresult
11
00
952 0 my $rv = $code->( $q, @_ );
953 0 ▶ return( $self->pass_error( $q->error ) ) if( !defined( $rv ) && $q->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $q->error 0 0 0
Condition0%0/3
not defined $rv and $q->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $rv and $q->error
not defined $rv $q->error
Truth table0%0/3
not(A) and B
A= not defined $rvB= $q->error
ABresult
0X0
100
111
954 0 return( $rv );
955 }
956  
957 sub AUTOLOAD
958 0 ▶{
Subroutine AUTOLOAD: not called CC=4 SCAR=25.6
959 0 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
960 4 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
961 0 my $self = shift( @_ );
962 0 my $fields = $self->fields;
963 # User called a field on a table object, instead of using the method fields_object or its shortcut 'fo'
964 0 ▶ if( CORE::exists( $fields->{ $method } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fields->{$method}) { } 0 0 0
965 {
966 0 ▶ warn( "You have called a field name '$method' using a table object. This practice is discouraged, although it works for now. Best to use something like: \$tbl->fo->$method rather than just \$tbl->$method" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
967 0 return( $self->fields_object->_initiate_field_object( $method ) );
968 }
969 else
970 {
971 0 ▶ warn( "You called table '", $self->name, "' object \$tbl->$method, but no such method exist.\n" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
972 0 return( $self->error( "You called table '", $self->name, "' object \$tbl->$method, but no such method exist." ) );
973 }
974 };
975  
976 # NOTE: DESTROY
977 sub DESTROY
978 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
979 # Do nothing
980 # DB::Object::Tables are never destroyed.
981 # They are just gateway to tables, and they are cached by DB::Object::table()
982 # print( STDERR "DESTROY'ing table $self ($self->{ 'table' })\n" );
983 };
984  
985 # NOTE: For CBOR and Sereal
986 sub FREEZE
987 0 ▶{
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
988 0 my $self = CORE::shift( @_ );
989 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
990 0 my $class = CORE::ref( $self );
991 0 my @props = qw(
992 check fields fields_object foreign indexes parent prefixed primary query_object
993 query_reset reverse schema structure table table_alias type types_const
994 _cache_structure
995 );
996 0 my $hash = {};
997 0 foreach my $prop ( @props )
998 {
999 0 ▶ if( CORE::exists( $self->{ $prop } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE") 0 0 0
Condition0%0/6
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
!ll&&!rl&&r
000
exists $self->{$prop} and defined $self->{$prop}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
exists $self->{$prop} defined $self->{$prop} ref $self->{$prop} ne "CODE"
Truth table0%0/4
A and B and C
A= exists $self->{$prop}B= defined $self->{$prop}C= ref $self->{$prop} ne "CODE"
ABCresult
0XX0
10X0
1100
1111
1000 defined( $self->{ $prop } ) &&
1001 # Because we cannot reliably freeze code reference, and we do not usually need to.
1002 CORE::ref( $self->{ $prop } ) ne 'CODE' )
1003 {
1004 0 $hash->{ $prop } = $self->{ $prop };
1005 }
1006 }
1007 0 $hash->{_serial_version} = $DB::Object::SERIALISATION_VERSION;
1008 # Return an array reference rather than a list so this works with Sereal and CBOR
1009 # Before Sereal version 4.023, Sereal did not support multiple values returned
1010 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
1011 {
1012 0 require Sereal::Encoder;
1013 0 require version;
1014
1015 0 ▶ if( version->parse( Sereal::Encoder->VERSION ) < version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) < "version"->parse("4.023")) 0 0 0
1016 {
1017 0 CORE::return( [$class, $hash] );
1018 }
1019 }
1020 # But Storable want a list with the first element being the serialised element
1021 0 CORE::return( $class, $hash );
1022 }
1023  
1024 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
1025  
1026 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
1027  
1028 sub STORABLE_thaw_post_processing
1029 0 ▶{
Subroutine STORABLE_thaw_post_processing: not called CC=2 SCAR=17.9
Pod undocumented
1030 0 my $obj = shift( @_ );
1031 0 my @keys = %$obj;
1032 0 my $class = ref( $obj );
1033 0 my $hash = {};
1034 0 @$hash{ @keys } = @$obj{ @keys };
1035 0 my $self = bless( $hash => $class );
1036 0 ▶ if( $self->{query_object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"query_object"}) 0 0 0
1037 {
1038 0 $self->{query_object}->attach( $self );
1039 }
1040 0 return( $self );
1041 }
1042  
1043 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
1044 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
1045 sub THAW
1046 0 ▶{
Subroutine THAW: not called CC=22 SCAR=61.3
Pod undocumented
1047 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
1048 # 'CBOR' as the second value.
1049 0 my( $self, undef, @args ) = @_;
1050 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
1051 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
1052 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
1053 0 ▶ if( $class !~ /\A[A-Za-z_]\w*(?:::\w+)*\z/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/) 0 0 0
1054 {
1055 0 die( "THAW: Invalid class name '$class'" );
1056 }
1057  
1058 0 ▶ my $sv = CORE::delete( $hash->{_serial_version} ) // 0;
Condition0%0/2
delete $hash->{"_serial_version"} // 0
l!l
00
MC/DC0%0/1
delete $hash->{"_serial_version"} // 0
delete $hash->{"_serial_version"}
Truth table0%0/2
A
A= delete $hash->{"_serial_version"}
Aresult
11
00
1059 0 ▶ if( $sv != $DB::Object::SERIALISATION_VERSION )
Branch: 1 branch
BranchTrueFalseTotal
if ($sv != $DB::Object::SERIALISATION_VERSION) 0 0 0
1060 {
1061 0 require( $EXCEPTION_CLASS );
1062 0 die( $EXCEPTION_CLASS->new({
1063 code => 409, # Conflict
1064 message => sprintf(
1065 "Serialisation version mismatch in %s: expected %d, got %d. Please purge the cache.",
1066 $class,
1067 $DB::Object::SERIALISATION_VERSION,
1068 $sv,
1069 )
1070 }) );
1071 }
1072  
1073 # Since this class is inherited, we also need to load from which we depend, if necessary.
1074 0 ▶ if( $class ne 'DB::Object::Tables' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class ne "DB::Object::Tables") 0 0 0
1075 {
1076 0 require DB::Object;
1077 0 require DB::Object::Tables;
1078 0 my @supported_classes = CORE::values( %$DB::Object::DRIVER2PACK );
1079 0 push( @supported_classes, 'DB::Object' );
1080 0 my $ok_classes = CORE::join( '|', CORE::map{ CORE::quotemeta( $_ ) } @supported_classes );
1081 0 my $base_class = ( $class =~ /^($ok_classes)/ )[0];
1082 0 eval( "require $base_class;" );
1083 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1084 {
1085 0 require( $EXCEPTION_CLASS );
1086 0 die( $EXCEPTION_CLASS->new( "Failure to load $base_class: $@" ) );
1087 }
1088  
1089 0 eval( "require $class;" );
1090 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1091 {
1092 0 require( $EXCEPTION_CLASS );
1093 0 die( $EXCEPTION_CLASS->new( "Failure to load $class: $@" ) );
1094 }
1095  
1096 # If inheritance is still missing (or incomplete) for any reason, repair it explicitly.
1097 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1098  
1099 0 my $stash = \%{"${class}\::"};
1100 0 my $isa_ref;
1101 # We check if the 'ISA' symbol exists in the stash and its ARRAY slot is defined
1102 0 ▶ if( exists( $stash->{ISA} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $stash->{'ISA'} and defined *{"${class}::ISA";}{'ARRAY'}) { } 0 0 0
Condition0%0/3
exists $stash->{"ISA"} and defined *{"${class}::ISA";}{"ARRAY"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $stash->{"ISA"} and defined *{"${class}::ISA";}{"ARRAY"}
exists $stash->{"ISA"} defined *{"${class}::ISA";}{"ARRAY"}
Truth table0%0/3
A and B
A= exists $stash->{"ISA"}B= defined *{"${class}::ISA";}{"ARRAY"}
ABresult
0X0
100
111
1103 0 defined( *{"${class}\::ISA"}{ARRAY} ) )
1104 {
1105 0 $isa_ref = *{"${class}\::ISA"}{ARRAY};
1106 }
1107 else
1108 {
1109 # # Force creation of @ISA array slot
1110 # @{"${class}::ISA"} = ();
1111 # $isa_ref = *{"${class}::ISA"}{ARRAY};
1112 # But I want it to die, so this can be dealt with, and not swept under the rug.
1113 0 die( "Unable to find the \@ISA value in $class. The package contains the following stashes:\n", $self->Module::Generic::dump( $stash ) );
1114 }
1115  
1116 0 my $has_tble = 0;
1117 0 foreach my $p ( @$isa_ref )
1118 {
1119 # Same as what we can find in modules DB::Object::(Postgres|SQLite|Mysql)::Tables
1120 0 ▶ $has_tble = 1 if( CORE::defined( $p ) && $p eq 'DB::Object::Tables' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and $p eq "DB::Object::Tables" 0 0 0
Condition0%0/3
defined $p and $p eq "DB::Object::Tables"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p and $p eq "DB::Object::Tables"
defined $p $p eq "DB::Object::Tables"
Truth table0%0/3
A and B
A= defined $pB= $p eq "DB::Object::Tables"
ABresult
0X0
100
111
1121 }
1122  
1123 0 ▶ if( !$has_tble )
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_tble) 0 0 0
1124 {
1125 0 @$isa_ref = ( 'DB::Object::Tables' );
1126 }
1127 }
1128 0 my $new;
1129 # Storable pattern requires to modify the object it created rather than returning a new one
1130 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
1131 {
1132 0 foreach( CORE::keys( %$hash ) )
1133 {
1134 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
1135 }
1136 0 $new = $self;
1137 }
1138 else
1139 {
1140 0 $new = CORE::bless( $hash => $class );
1141 }
1142 0 CORE::return( $new );
1143 }
1144  
1145 4 1;
1146 # NOTE: POD
1147 __END__
« blib/lib/DB/Object/Mysql/Query.pm ↑ Summary lib/DB/Object/Fields.pm »