lib/DB/Object/Query/Elements.pm

filter: Statementstmt 58.3% 112 / 192 Branchbran 31.2% 20 / 64 Conditioncond 19.1% 14 / 73 MC/DCmcdc 2.9% 1 / 34 Subroutinesub 62.5% 25 / 40 Podpod 78.2% 18 / 23 totaltotal 44.6% 190 / 426 CC 67 SCAR 31.2
CC
67
Cov
44%
THAW
110.0
FREEZE
72.0
attach
42.0
CRAP 22.6
« blib/lib/DB/Object/SQLite.pm ↑ Summary blib/lib/DB/Object/Query/Element.pm »
1 ##----------------------------------------------------------------------------
2 ## Database Object Interface - ~/lib/DB/Object/Query/Elements.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2023/07/08
7 ## Modified 2026/03/22
8 ## All rights reserved
9 ##
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 package DB::Object::Query::Elements;
15 BEGIN
16 {
17 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶ use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶ use vars qw( $VERSION $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶ our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 our $VERSION = 'v0.2.0';
23 };
24  
25 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub init
29 {
30 28 ▶ my $self = shift( @_ );
Subroutine init: called CC=2 SCAR=6.9
Pod documented
31 28 $self->{elements} = [];
32 28 $self->{query_object} = undef;
33 28 $self->{_init_strict_use_sub} = 1;
34 28 $self->{_exception_class} = $EXCEPTION_CLASS;
35 28 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 28 28
36 28 $self->{_fields} = [qw( elements )];
37 28 $self->{_cache_fields} = '';
38 28 $self->{_cache_formats} = '';
39 28 $self->{_cache_types} = '';
40 28 $self->{_cache_values} = '';
41 28 return( $self );
42 }
43  
44 # We attach this elements collection to its query object
45 sub attach
46 {
47 0 ▶ my $self = shift( @_ );
Subroutine attach: not called CC=6 SCAR=37.4
Pod documented
48 # Query object
49 0 ▶ my $qo = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No DB::Object::Query object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No DB::Object::Query object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
50 return( $self->error( "No DB::Object::Query object was provided." ) );
51 0 ▶ unless( $self->_is_a( $qo => 'DB::Object::Query' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($qo, "DB::Object::Query")) 0 0 0
52 {
53 0 return( $self->error( "Value provided is not a DB::Object::Query object." ) );
54 }
55 0 ▶ $self->query_object( $qo ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->query_object($qo) or return $self->pass_error 0 0 0
56 0 $self->debug( $qo->debug );
57 # We propagate ourself to all the elements in the collection.
58 0 ▶ if( my $elems = $self->elements )
Branch: 1 branch
BranchTrueFalseTotal
if (my $elems = $self->elements) 0 0 0
59 {
60 0 foreach my $elem ( @$elems )
61 {
62 0 $elem->attach( $self );
63 }
64 }
65 0 return( $self );
66 }
67  
68 # This is used to forward unknown method to Module::Generic::Array
69 sub autoload
70 {
71 0 ▶ my $self = shift( @_ );
Subroutine autoload: not called CC=4 SCAR=26.4
Pod undocumented
72 0 ▶ my $meth = shift( @_ ) || return;
Condition0%0/2
shift @_ || (return)
l!l
00
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
73 0 ▶ my $elems = $self->elements || return;
Condition0%0/2
$self->elements || (return)
l!l
00
MC/DC0%0/1
$self->elements || (return)
$self->elements
Truth table0%0/2
A
A= $self->elements
Aresult
11
00
74 0 my $code;
75 0 ▶ if( $code = $elems->can( $meth ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($code = $elems->can($meth)) 0 0 0
76 {
77 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
78 my $sub = sub
79 {
80 0 ▶ my $this = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 return( $code->( $this->elements, @_ ) );
82 0 };
83 0 *$meth = $sub;
84 0 return( $sub );
85 }
86 0 warn( "No method '$meth' supported by this class ", ref( $self ), " or by ", ref( $elems ) );
87 0 return;
88 }
89  
90 # NOTE: sub clone is inherited from Module::Generic
91  
92 107 ▶sub elements { return( shift->reset(@_)->_set_get_object_array_object( 'elements', 'DB::Object::Query::Element', @_ ) ); }
Subroutine elements: called CC=1 SCAR=0.0
Pod documented
93  
94 sub fields
95 {
96 11 ▶ my $self = shift( @_ );
Subroutine fields: called CC=4 SCAR=15.0
Pod documented
97 11 ▶ return( $self->{_cache_fields} ) if( $self->{_cache_fields} && !CORE::length( $self->{_reset} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_fields"} and not CORE::length($self->{"_reset"} // "") 0 11 11
Condition20%1/5
$self->{"_cache_fields"} and not CORE::length($self->{"_reset"} // "")
!ll&&!rl&&r
1100
$self->{"_reset"} // ""
l!l
00
MC/DC0%0/2
$self->{"_cache_fields"} and not CORE::length($self->{"_reset"} // "")
$self->{"_cache_fields"} $self->{"_reset"}
Truth table33%1/3
A and not(B)
A= $self->{"_cache_fields"}B= $self->{"_reset"}
ABresult
0X0
110
101
98 11 my $arr = $self->new_array;
99 11 my $e = $self->elements;
100 $e->foreach(sub
101 {
102 35 ▶ my $o = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=7.2
103 35 ▶ $arr->push( defined( $o ) ? $o->field : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $o ? : 35 0 35
104 11 });
105 11 $self->{_cache_fields} = $arr;
106 11 CORE::delete( $self->{_reset} );
107 11 return( $arr );
108 }
109  
110 0 ▶sub for { return( shift->elements->for( @_ ) ); }
Subroutine for: not called CC=1 SCAR=6.9
Pod documented
111  
112 0 ▶sub foreach { return( shift->elements->foreach( @_ ) ); }
Subroutine foreach: not called CC=1 SCAR=6.9
Pod documented
113  
114 sub formats
115 {
116 2 ▶ my $self = shift( @_ );
Subroutine formats: called CC=4 SCAR=15.0
Pod documented
117 2 ▶ return( $self->{_cache_formats} ) if( $self->{_cache_formats} && !CORE::length( $self->{_reset} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_formats"} and not CORE::length($self->{"_reset"} // "") 0 2 2
Condition20%1/5
$self->{"_cache_formats"} and not CORE::length($self->{"_reset"} // "")
!ll&&!rl&&r
200
$self->{"_reset"} // ""
l!l
00
MC/DC0%0/2
$self->{"_cache_formats"} and not CORE::length($self->{"_reset"} // "")
$self->{"_cache_formats"} $self->{"_reset"}
Truth table33%1/3
A and not(B)
A= $self->{"_cache_formats"}B= $self->{"_reset"}
ABresult
0X0
110
101
118 2 my $arr = $self->new_array;
119 2 my $e = $self->elements;
120 $e->foreach(sub
121 {
122 5 ▶ my $o = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=7.2
123 5 ▶ $arr->push( defined( $o ) ? $o->format : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $o ? : 5 0 5
124 2 });
125 2 $self->{_cache_formats} = $arr;
126 2 CORE::delete( $self->{_reset} );
127 2 return( $arr );
128 }
129  
130 sub generics
131 {
132 2 ▶ my $self = shift( @_ );
Subroutine generics: called CC=4 SCAR=15.0
Pod documented
133 2 ▶ return( $self->{_cache_generics} ) if( $self->{_cache_generics} && !CORE::length( $self->{_reset} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_generics"} and not CORE::length($self->{"_reset"} // "") 0 2 2
Condition20%1/5
$self->{"_cache_generics"} and not CORE::length($self->{"_reset"} // "")
!ll&&!rl&&r
200
$self->{"_reset"} // ""
l!l
00
MC/DC0%0/2
$self->{"_cache_generics"} and not CORE::length($self->{"_reset"} // "")
$self->{"_cache_generics"} $self->{"_reset"}
Truth table33%1/3
A and not(B)
A= $self->{"_cache_generics"}B= $self->{"_reset"}
ABresult
0X0
110
101
134 2 my $arr = $self->new_array;
135 2 my $e = $self->elements;
136 $e->foreach(sub
137 {
138 2 ▶ my $o = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=7.2
139 2 ▶ $arr->push( defined( $o ) ? $o->generic : '?' );
Branch: 1 branch
BranchTrueFalseTotal
defined $o ? : 2 0 2
140 2 });
141 2 $self->{_cache_generics} = $arr;
142 2 CORE::delete( $self->{_reset} );
143 2 return( $arr );
144 }
145  
146 0 ▶sub is_empty { return( shift->elements->is_empty ); }
Subroutine is_empty: not called CC=1 SCAR=6.9
Pod documented
147  
148 0 ▶sub length { return( shift->elements->length ); }
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
149  
150 # This merge one or more objects of the same class into this one
151 sub merge
152 {
153 2 ▶ my $self = shift( @_ );
Subroutine merge: called CC=4 SCAR=14.8
Pod documented
154 2 my $elems = $self->elements;
155 2 CORE::foreach my $this ( @_ )
156 {
157 2 ▶ if( !$self->_is_a( $this => 'DB::Object::Query::Elements' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($this, "DB::Object::Query::Elements")) 0 2 2
158 {
159 0 warn( "Element provided '", overload::StrVal( $this ), "' is not an DB::Object::Query::Elements or DB::Object::Query::Clause object" );
160 0 next;
161 }
162  
163 2 $elems->push( $this->elements->list );
164 }
165 # Make sure our elements are in the right order
166 2 $self->_sort;
167 2 ▶ $self->reset(1) if( scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 2 0 2
168 2 return( $self );
169 }
170  
171 sub new_element
172 {
173 7 ▶ my $self = shift( @_ );
Subroutine new_element: called CC=2 SCAR=7.1
Pod documented
174 7 ▶ my $el = $self->query_object->new_element( @_ ) ||
Condition50%1/2
$self->query_object->new_element(@_) || (return $self->pass_error($self->query_object->error))
l!l
70
MC/DC0%0/1
$self->query_object->new_element(@_) || (return $self->pass_error($self->query_object->error))
$self->query_object->new_element(@_)
Truth table50%1/2
A
A= $self->query_object->new_element(@_)
Aresult
11
00
175 return( $self->pass_error( $self->query_object->error ) );
176 7 return( $el );
177 }
178  
179 sub push
180 {
181 36 ▶ my $self = shift( @_ );
Subroutine push: called CC=8 SCAR=23.7
Pod documented
182 36 my $e = $self->elements;
183 36 CORE::foreach my $elem ( @_ )
184 {
185 36 my( $o );
186 # This works also for DB::Object::Query::Clause that inherits from DB::Object::Query::Elements
187 36 ▶ if( $self->_is_a( $elem => 'DB::Object::Query::Elements' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($elem, 'DB::Object::Query::Elements')) { } 0 36 36
elsif ($self->_is_a($elem, 'DB::Object::Query::Element')) { } 29 7 36
elsif (ref $elem eq 'HASH') { } 7 0 7
188 {
189 0 $self->push( $elem->elements->list );
190 0 next;
191 }
192 elsif( $self->_is_a( $elem => 'DB::Object::Query::Element' ) )
193 {
194 29 $o = $elem;
195 }
196 elsif( ref( $elem ) eq 'HASH' )
197 {
198 7 ▶ $o = $self->new_element( %$elem ) || return( $self->pass_error );
Condition50%1/2
$self->new_element(%$elem) || (return $self->pass_error)
l!l
70
MC/DC0%0/1
$self->new_element(%$elem) || (return $self->pass_error)
$self->new_element(%$elem)
Truth table50%1/2
A
A= $self->new_element(%$elem)
Aresult
11
00
199 }
200 else
201 {
202 0 ▶ return( $self->error( "Unknown value '", ( $elem // 'undef' ), "' to add as element to our clause elements stack." ) );
Condition0%0/2
$elem // "undef"
l!l
00
MC/DC0%0/1
$elem // "undef"
$elem
Truth table0%0/2
A
A= $elem
Aresult
11
00
203 }
204  
205 # Order does not really matter, we just stack them, and after we will sort them by their object property 'index' value, if necessary
206 36 $e->push( $o );
207 }
208 # Make sure our elements are in the right order
209 36 $self->_sort;
210 36 ▶ $self->reset(1) if( scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 36 0 36
211 36 return( $self );
212 }
213  
214 41 ▶sub query_object { return( shift->_set_get_object( 'query_object', 'DB::Object::Query', @_ ) ); }
Subroutine query_object: called CC=1 SCAR=0.0
Pod documented
215  
216 sub reset
217 {
218 145 ▶ my $self = shift( @_ );
Subroutine reset: called CC=4 SCAR=13.9
Pod documented
219 145 ▶ if( !CORE::length( $self->{_reset} // '' ) && scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not CORE::length($self->{"_reset"} // "") and scalar @_) 14 131 145
Condition100%4/4
not CORE::length($self->{"_reset"} // "") and scalar @_
!ll
8560
$self->{"_reset"} // ""
l!l
8560
MC/DC100%1/1
not CORE::length($self->{"_reset"} // "") and scalar @_
$self->{"_reset"}
Truth table100%2/2
not(A)
A= $self->{"_reset"}
Aresult
10
01
220 {
221 14 $self->{_reset} = scalar( @_ );
222 }
223 145 return( $self );
224 }
225  
226 sub sort
227 {
228 0 ▶ my $self = shift( @_ );
Subroutine sort: not called CC=1 SCAR=6.9
Pod documented
229 my $elems = $self->elements->sort(sub
230 {
231 0 ▶ my( $a, $b ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 0 return( $a->index <=> $b->index );
233 0 });
234 0 my $clone = $self->clone;
235 0 $clone->elements( $elems );
236 0 return( $clone );
237 }
238  
239 sub types
240 {
241 0 ▶ my $self = shift( @_ );
Subroutine types: not called CC=4 SCAR=30.0
Pod documented
242 0 ▶ return( $self->{_cache_types} ) if( $self->{_cache_types} && !CORE::length( $self->{_reset} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_types"} and not CORE::length($self->{"_reset"} // "") 0 0 0
Condition0%0/5
$self->{"_cache_types"} and not CORE::length($self->{"_reset"} // "")
!ll&&!rl&&r
000
$self->{"_reset"} // ""
l!l
00
MC/DC0%0/2
$self->{"_cache_types"} and not CORE::length($self->{"_reset"} // "")
$self->{"_cache_types"} $self->{"_reset"}
Truth table0%0/3
A and not(B)
A= $self->{"_cache_types"}B= $self->{"_reset"}
ABresult
0X0
110
101
243 0 my $arr = $self->new_array;
244 0 my $e = $self->elements;
245 $e->foreach(sub
246 {
247 0 ▶ my $o = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
248 0 ▶ $arr->push( defined( $o->type ) ? $o : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $o->type ? : 0 0 0
249 0 });
250 0 $self->{_cache_types} = $arr;
251 0 CORE::delete( $self->{_reset} );
252 0 return( $arr );
253 }
254  
255 sub values
256 {
257 2 ▶ my $self = shift( @_ );
Subroutine values: called CC=4 SCAR=15.0
Pod documented
258 2 ▶ return( $self->{_cache_values} ) if( $self->{_cache_values} && !CORE::length( $self->{_reset} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_values"} and not CORE::length($self->{"_reset"} // "") 0 2 2
Condition20%1/5
$self->{"_cache_values"} and not CORE::length($self->{"_reset"} // "")
!ll&&!rl&&r
200
$self->{"_reset"} // ""
l!l
00
MC/DC0%0/2
$self->{"_cache_values"} and not CORE::length($self->{"_reset"} // "")
$self->{"_cache_values"} $self->{"_reset"}
Truth table33%1/3
A and not(B)
A= $self->{"_cache_values"}B= $self->{"_reset"}
ABresult
0X0
110
101
259 2 my $arr = $self->new_array;
260 2 my $e = $self->elements;
261 $e->foreach(sub
262 {
263 2 ▶ my $o = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=7.2
264 2 ▶ $arr->push( defined( $o ) ? $o->value : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $o ? : 2 0 2
265 2 });
266 2 $self->{_cache_values} = $arr;
267 2 CORE::delete( $self->{_reset} );
268 2 return( $arr );
269 }
270  
271 sub _sort
272 {
273 38 ▶ my $self = shift( @_ );
Subroutine _sort: called CC=5 SCAR=21.7
274 38 my $e = $self->elements;
275 38 my $el;
276 # We check the first element to decide whether the placeholders, if any, are numbered or not.
277 $e->foreach(sub
278 {
279 38 ▶ my $this = shift( @_ );
Subroutine __ANON__: called CC=4 SCAR=19.7
280 38 ▶ if( $self->_is_object( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($this) and $self->_can($this, "is_numbered") and $this->is_numbered) 0 38 38
Condition33%2/6
$self->_is_object($this) and $self->_can($this, "is_numbered") and $this->is_numbered
!ll&&!rl&&r
0380
$self->_is_object($this) and $self->_can($this, "is_numbered")
!ll&&!rl&&r
0038
MC/DC0%0/3
$self->_is_object($this) and $self->_can($this, "is_numbered") and $this->is_numbered
$self->_is_object($this) $self->_can($this, "is_numbered") $this->is_numbered
Truth table25%1/4
A and B and C
A= $self->_is_object($this)B= $self->_can($this, "is_numbered")C= $this->is_numbered
ABCresult
0XX0
10X0
1100
1111
281 $self->_can( $this => 'is_numbered' ) &&
282 $this->is_numbered )
283 {
284 0 $el = $this;
285 0 return(0);
286 }
287 38 });
288 38 ▶ if( $el && $el->placeholder && $el->is_numbered )
Branch: 1 branch
BranchTrueFalseTotal
if ($el and $el->placeholder and $el->is_numbered) 0 38 38
Condition33%2/6
$el and $el->placeholder and $el->is_numbered
!ll&&!rl&&r
3800
$el and $el->placeholder
!ll&&!rl&&r
3800
MC/DC0%0/3
$el and $el->placeholder and $el->is_numbered
$el $el->placeholder $el->is_numbered
Truth table25%1/4
A and B and C
A= $elB= $el->placeholderC= $el->is_numbered
ABCresult
0XX0
10X0
1100
1111
289 {
290 0 my $sorted = $self->sort->elements;
291 0 ▶ $self->elements( $sorted ) if( $sorted );
Branch: 1 branch
BranchTrueFalseTotal
if $sorted 0 0 0
292 }
293 38 return( $self );
294 }
295  
296 sub FREEZE
297 {
298 0 ▶ my $self = CORE::shift( @_ );
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
299 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
300 0 my $class = CORE::ref( $self );
301  
302 # We keep a strict allow-list to avoid accidentally freezing DBI handles or other
303 # process-local state.
304 0 my @props = @{$self->{_fields}};
305  
306 0 my $hash = {};
307 0 foreach my $prop ( @props )
308 {
309 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
310 defined( $self->{ $prop } ) &&
311 CORE::ref( $self->{ $prop } ) ne 'CODE' )
312 {
313 0 $hash->{ $prop } = $self->{ $prop };
314 }
315 }
316  
317 # Return an array reference rather than a list so this works with Sereal and CBOR.
318 # Before Sereal version 4.023, Sereal did not support multiple values returned.
319 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
320 {
321 0 require Sereal::Encoder;
322 0 require version;
323  
324 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
325 {
326 0 CORE::return( [$class, $hash] );
327 }
328 }
329  
330 # But Storable wants a list with the first element being the serialised element
331 0 CORE::return( $class, $hash );
332 }
333  
334 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
335  
336 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
337  
338 sub THAW
339 {
340 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
341 # 'CBOR' as the second value.
342 0 ▶ my( $self, undef, @args ) = @_;
Subroutine THAW: not called CC=10 SCAR=47.0
Pod undocumented
343 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
344 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
345 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
346 0 my $new;
347 # Storable pattern requires to modify the object it created rather than returning a new one
348 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
349 {
350 0 foreach( CORE::keys( %$hash ) )
351 {
352 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
353 }
354 0 $new = $self;
355 }
356 else
357 {
358 0 $new = CORE::bless( $hash => $class );
359 }
360 0 CORE::return( $new );
361 }
362  
363 3 1;
364 # NOTE: POD
365 __END__
366  
367 =encoding utf-8
368  
369 =head1 NAME
370  
371 DB::Object::Query::Elements - Query Elements Manipulation Class
372  
373 =head1 SYNOPSIS
374  
375 use DB::Object::Query::Elements;
376 my $elems = DB::Object::Query::Elements->new( debug => 4 ) ||
377 die( DB::Object::Query::Elements->error );
378 $elems->push( $new_element );
379 $elems->push({
380 field => $some_field_name,
381 value => $some_field_value,
382 type => $sql_type,
383 format => $insert_formatting,
384 # Could also be $1, $2, ?1, ?2, or other variants supported by driver
385 placeholder => '?',
386 });
387 $elems->merge( $other_elements_object );
388 # Clause class inherits from Elements class
389 $elems->merge( $some_clause_object );
390  
391 =head1 VERSION
392  
393 v0.2.0
394  
395 =head1 DESCRIPTION
396  
397 This class represent a query manipulation class designed to access, store and retrieve L<query elements|DB::Object::Query::Element>
398  
399 Elements are stored in an internal array object accessible with L</elements>, and all the other methods are used to access or manipulate those elements data.
400  
401 =head1 CONSTRUCTOR
402  
403 =head2 new
404  
405 Takes an hash or hash reference of key-value pairs matching any of the methods below.
406  
407 Returns a newly instantiated object upon success, or sets an L<error|Module::Generic/error> and return C<undef> or an empty list, depending on the caller's context.
408  
409 =head1 METHODS
410  
411 =head2 attach
412  
413 This takes a query object, and attach it to our current object.
414  
415 In turn, it will also attach it to all the elements, this object holds with the L<elements|/elements> method.
416  
417 This returns the current object upon success, or upon error, it sets an L<error object|DB::Object::Exception>, and returns C<undef> in scalar context, or an empty list in list context.
418  
419 =for Pod::Coverage autoload
420  
421 =head2 elements
422  
423 Sets or gets an L<array object|Module::Generic::Array> of L<DB::Object::Query::Element> objects.
424  
425 =head2 fields
426  
427 Read-only. Returns an L<array object|Module::Generic::Array> of all the elements L<field|DB::Object::Query::Element/field> property.
428  
429 =head2 for
430  
431 This is a shortcut for calling L<Module::Generic::Array/for> on this class L</elements>
432  
433 =head2 foreach
434  
435 This is a shortcut for calling L<Module::Generic::Array/foreach> on this class L</elements>
436  
437 =head2 formats
438  
439 Read-only. Returns an L<array object|Module::Generic::Array> of all the elements L<format|DB::Object::Query::Element/format> property.
440  
441 =head2 generics
442  
443 Read-only. Returns an L<array object|Module::Generic::Array> of all the elements L<generic|DB::Object::Query::Element/generic> representation.
444  
445 =head2 is_empty
446  
447 This is a shortcut for calling L<Module::Generic::Array/is_empty> on this class L</elements>
448  
449 =head2 length
450  
451 This is a shortcut for calling L<Module::Generic::Array/length> on this class L</elements>
452  
453 =head2 merge
454  
455 Provided with one or more L<DB::Object::Query::Elements> objects (including L<DB::Object::Query::Clause> objects that inherit from L<DB::Object::Query::Elements>), and this will merge those objects into this current object.
456  
457 If the underlying elements are numbered placeholders such as C<$1>, C<$2>, or C<?1>, C<?2>, then they will be properly sorted internally.
458  
459 It returns the current object.
460  
461 =head2 new_element
462  
463 Provided with an hash or hash reference of parameter, and this will instantiate a new L<DB::Object::Query::Element> object and return it.
464  
465 If an error occurred, such as if bad parameters were provided, an L<error object|Module::Generic/error> is set and C<undef>, or an empty list depending on the context, is returned.
466  
467 =head2 push
468  
469 Provided with objects of classes L<DB::Object::Query::Elements> or L<DB::Object::Query::Element>, or alternatively an hash reference of property-value pairs needed to instantiate a new L<DB::Object::Query::Element>, and this will add those objects to the stack of elements managed by this class.
470  
471 If the underlying elements are numbered placeholders such as C<$1>, C<$2>, or C<?1>, C<?2>, then they will be properly sorted internally.
472  
473 It returns the current object.
474  
475 =head2 query_object
476  
477 Sets or gets the L<DB::Object::Query> object set for this object.
478  
479 =head2 reset
480  
481 Various methods return cached value once they have been computed for improved performance. Calling C<reset> will force re-computing next time either one is called.
482  
483 Those methods are L</fields>, L</formats>, L</types> and L</values>
484  
485 =head2 sort
486  
487 Returns a new clone of the current L<DB::Object::Query::Elements> object with its elements sorted based on their L<index property|DB::Object::Query::Element/index>
488  
489 =head2 types
490  
491 Read-only. Returns an L<array object|Module::Generic::Array> of all the elements L<type|DB::Object::Query::Element/type> property.
492  
493 =head2 values
494  
495 Read-only. Returns an L<array object|Module::Generic::Array> of all the elements L<value|DB::Object::Query::Element/value> property.
496  
497 =head1 AUTHOR
498  
499 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
500  
501 =head1 SEE ALSO
502  
503 L<DB::Object::Query>, L<DB::Object::Query::Clause>, L<DB::Object::Query::Element>, L<DB::Object>
504  
505 =head1 COPYRIGHT & LICENSE
506  
507 Copyright(c) 2023 DEGUEST Pte. Ltd.
508  
509 All rights reserved.
510  
511 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
512  
513 =cut
« blib/lib/DB/Object/SQLite.pm ↑ Summary blib/lib/DB/Object/Query/Element.pm »