lib/DB/Object/Query/Element.pm

filter: Statementstmt 49.5% 61 / 123 Branchbran 13.4% 7 / 52 Conditioncond 8.9% 5 / 56 MC/DCmcdc 3.4% 1 / 29 Subroutinesub 67.8% 19 / 28 Podpod 77.7% 14 / 18 totaltotal 34.9% 107 / 306 CC 49 SCAR 40.3
CC
49
Cov
32%
fo
132.0
THAW
110.0
attach
90.0
CRAP 56.3
« blib/lib/DB/Object/Postgres.pm ↑ Summary lib/DB/Object/Query/Clause.pm »
1 ##----------------------------------------------------------------------------
2 ## Database Object Interface - ~/lib/DB/Object/Query/Element.pm
3 ## Version v0.3.1
4 ## Copyright(c) 2026 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::Element;
15 BEGIN
16 {
17 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶ use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶ use vars qw( $VERSION $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶ our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 our $VERSION = 'v0.3.1';
24 };
25  
26 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 57 ▶ my $self = shift( @_ );
Subroutine init: called CC=2 SCAR=6.9
Pod documented
32 57 $self->{as_is} = undef;
33 57 $self->{field} = undef;
34 57 $self->{format} = undef;
35 57 $self->{index} = undef;
36 57 $self->{is_numbered} = 0;
37 57 $self->{placeholder} = undef;
38 57 $self->{query_object} = undef;
39 57 $self->{type} = undef;
40 57 $self->{value} = undef;
41 57 $self->{_init_strict_use_sub} = 1;
42 57 $self->{_init_params_order} = [qw( query_object field placeholder format type value index )];
43 57 $self->{_exception_class} = $EXCEPTION_CLASS;
44 57 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 57 57
45 57 $self->{_fields} = [qw(
46 as_is field format index is_numbered placeholder type value
47 )];
48 57 return( $self );
49 }
50  
51 0 ▶sub as_is { return( shift->_set_get_boolean( 'as_is', @_ ) ); }
Subroutine as_is: not called CC=1 SCAR=6.9
Pod documented
52  
53 sub attach
54 {
55 0 ▶ my $self = shift( @_ );
Subroutine attach: not called CC=9 SCAR=45.0
Pod documented
56 0 ▶ my $elems = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No DB::Object::Query::Elements object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No DB::Object::Query::Elements object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
57 return( $self->error( "No DB::Object::Query::Elements object was provided." ) );
58 0 ▶ unless( $self->_is_a( $elems => 'DB::Object::Query::Elements' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($elems, "DB::Object::Query::Elements")) 0 0 0
59 {
60 0 return( $self->error( "Value provided is not a DB::Object::Query::Elements object." ) );
61 }
62 0 ▶ $self->elements( $elems ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->elements($elems) or return $self->pass_error 0 0 0
63 0 $self->debug( $elems->debug );
64 0 ▶ if( my $qo = $elems->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $qo = $elems->query_object) 0 0 0
65 {
66 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
67 0 my $tbl = $qo->table_object;
68 0 my $field = $self->fo;
69 0 ▶ if( $field && $tbl )
Branch: 1 branch
BranchTrueFalseTotal
if ($field and $tbl) 0 0 0
Condition0%0/3
$field and $tbl
!ll&&!rl&&r
000
MC/DC0%0/2
$field and $tbl
$field $tbl
Truth table0%0/3
A and B
A= $fieldB= $tbl
ABresult
0X0
100
111
70 {
71 0 ▶ $field->attach( $tbl ) || return( $self->pass_error( $field->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$field->attach($tbl) or return $self->pass_error($field->error) 0 0 0
72 }
73 }
74 0 return( $self );
75 }
76  
77 0 ▶sub elements { return( shift->_set_get_object_without_init( 'elements', 'DB::Object::Query::Elements', @_ ) ); }
Subroutine elements: not called CC=1 SCAR=6.9
Pod documented
78  
79 # The field name
80 82 ▶sub field { return( shift->_set_get_scalar_or_object( 'field', 'DB::Object::Fields::Field', @_ ) ); }
Subroutine field: called CC=1 SCAR=0.0
Pod documented
81  
82 sub fo
83 {
84 0 ▶ my $self = shift( @_ );
Subroutine fo: not called CC=11 SCAR=48.8
Pod documented
85 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
86 {
87 0 ▶ return( $self->error( "Value provided for method fo() in class ", ref( $self ), " is not a DB::Object::Fields::Field object." ) ) if( !$self->_is_a( $_[0] => 'DB::Object::Fields::Field' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($_[0], "DB::Object::Fields::Field") 0 0 0
88 0 $self->{fo} = shift( @_ );
89 }
90 0 ▶ return( $self->{fo} ) if( $self->{fo} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fo"} 0 0 0
91 0 my $f = $self->field;
92 0 my $fo;
93 0 ▶ if( $self->_is_a( $f => 'DB::Object::Fields::Field' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($f, 'DB::Object::Fields::Field')) { } 0 0 0
elsif (defined $f and length($f // '')) { } 0 0 0
94 {
95 0 $fo = $f;
96 }
97 ▶ elsif( defined( $f ) && CORE::length( $f // '' ) )
Condition0%0/5
defined $f and length($f // "")
!ll&&!rl&&r
000
$f // ""
l!l
00
MC/DC0%0/2
defined $f and length($f // "")
defined $f $f
Truth table0%0/3
A and B
A= defined $fB= $f
ABresult
0X0
100
111
98 {
99 0 $fo = $self->query_object->table_object->fields( $f );
100 }
101 0 ▶ $self->{fo} = $fo if( defined( $fo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fo 0 0 0
102 0 ▶ return( $self->new_null ) if( !defined( $fo ) && Wanted::want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $fo and Wanted::want("OBJECT") 0 0 0
Condition0%0/3
not defined $fo and Wanted::want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $fo and Wanted::want("OBJECT")
not defined $fo Wanted::want("OBJECT")
Truth table0%0/3
not(A) and B
A= not defined $foB= Wanted::want("OBJECT")
ABresult
0X0
100
111
103 0 return( $fo );
104 }
105  
106 # The formatting for insert, e.g.: field = value, or possibly field = ?, or even field = $1
107 14 ▶sub format { return( shift->_set_get_scalar_as_object( 'format', @_ ) ); }
Subroutine format: called CC=1 SCAR=0.0
Pod documented
108  
109 # The generic representation of this element if we want to bind data to it
110 2 ▶sub generic { return( shift->_set_get_scalar_as_object( 'generic', @_ ) ); }
Subroutine generic: called CC=1 SCAR=0.0
Pod documented
111  
112 # If this is a numbered placeholder
113 2 ▶sub index { return( shift->_set_get_number( { field => 'index', undef_ok => 1 }, @_ ) ); }
Subroutine index: called CC=1 SCAR=0.0
Pod documented
114  
115 # sub is_numbered { return( shift->_set_get_boolean( 'is_numbered', @_ ) ); }
116 sub is_numbered
117 {
118 38 ▶ my $self = shift( @_ );
Subroutine is_numbered: called CC=4 SCAR=14.8
Pod documented
119 38 my $placeholder = $self->placeholder;
120 38 ▶ return(0) if( !defined( $placeholder ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $placeholder 37 1 38
121 1 my $placeholder_re = $self->query_object->database_object->_placeholder_regexp;
122 1 ▶ if( $placeholder =~ /^$placeholder_re$/ && defined( $+{index} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($placeholder =~ /^$placeholder_re$/ and defined $+{"index"}) 0 1 1
Condition33%1/3
$placeholder =~ /^$placeholder_re$/ and defined $+{"index"}
!ll&&!rl&&r
100
MC/DC0%0/2
$placeholder =~ /^$placeholder_re$/ and defined $+{"index"}
$placeholder =~ /^$placeholder_re$/ defined $+{"index"}
Truth table33%1/3
A and B
A= $placeholder =~ /^$placeholder_re$/B= defined $+{"index"}
ABresult
0X0
100
111
123 {
124 0 return(1);
125 }
126 1 return(0);
127 }
128  
129 # The placeholder, such as ?, $2, ?2, or others supported by the driver
130 sub placeholder { return( shift->_set_get_scalar_as_object({
131 field => 'placeholder',
132 callbacks =>
133 {
134 set => sub
135 {
136 # $val is a scalar object (Module::Generic::Scalar)
137 2 ▶ my( $self, $val ) = @_;
Subroutine __ANON__: called CC=6 SCAR=19.4
138 2 my $placeholder_re = $self->query_object->database_object->_placeholder_regexp;
139 2 ▶ return( $val ) if( $self->_is_scalar( $val ) && $self->_can( $val => 'defined' ) && !$val->defined );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_scalar($val) and $self->_can($val, "defined") and not $val->defined 0 2 2
Condition33%2/6
$self->_is_scalar($val) and $self->_can($val, "defined") and not $val->defined
!ll&&!rl&&r
020
$self->_is_scalar($val) and $self->_can($val, "defined")
!ll&&!rl&&r
002
MC/DC0%0/3
$self->_is_scalar($val) and $self->_can($val, "defined") and not $val->defined
$self->_is_scalar($val) $self->_can($val, "defined") not $val->defined
Truth table25%1/4
A and B and not(C)
A= $self->_is_scalar($val)B= $self->_can($val, "defined")C= not $val->defined
ABCresult
0XX0
10X0
1100
1111
140 2 ▶ if( defined( $val ) && "$val" =~ /^(?:$placeholder_re)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and "$val" =~ /^(?:$placeholder_re)$/) { } 1 1 2
Condition66%2/3
defined $val and "$val" =~ /^(?:$placeholder_re)$/
!ll&&!rl&&r
011
MC/DC50%1/2
defined $val and "$val" =~ /^(?:$placeholder_re)$/
defined $val "$val" =~ /^(?:$placeholder_re)$/
Truth table66%2/3
A and B
A= defined $valB= "$val" =~ /^(?:$placeholder_re)$/
ABresult
0X0
100
111
141 {
142 # Could be undef
143 1 $self->index( $+{index} );
144 }
145 else
146 {
147 1 $self->index( undef );
148 }
149 2 return( $val );
150 }
151 }
152 40 ▶}, @_ ) ); }
Subroutine placeholder: called CC=1 SCAR=0.0
Pod documented
153  
154 59 ▶sub query_object { return( shift->_set_get_object( 'query_object', 'DB::Object::Query', @_ ) ); }
Subroutine query_object: called CC=1 SCAR=0.0
Pod documented
155  
156 # The field data type to be used when binding parameters
157 # sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
158 sub type { return( shift->_set_get_scalar_as_object( { field => 'type', callbacks =>
159 {
160 get => sub
161 {
162 0 ▶ my( $self, $val ) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
163 0 my $field = $self->field;
164 0 ▶ if( ( !defined( $val ) || !$val->defined || !CORE::length( $val // '' ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val && $val->defined && length($val // "") and $self->_is_a($field, "DB::Object::Fields::Field")) 0 0 0
Condition0%0/11
not defined $val && $val->defined && length($val // "") and $self->_is_a($field, "DB::Object::Fields::Field")
!ll&&!rl&&r
000
defined $val && $val->defined && length($val // '')
!ll&&!rl&&r
000
defined $val and $val->defined
!ll&&!rl&&r
000
$val // ""
l!l
00
MC/DC0%0/4
not defined $val && $val->defined && length($val // "") and $self->_is_a($field, "DB::Object::Fields::Field")
defined $val $val->defined $val $self->_is_a($field, "DB::Object::Fields::Field")
Truth table0%0/7
not(A and B && C) and D
A= defined $valB= $val->definedC= $valD= $self->_is_a($field, "DB::Object::Fields::Field")
ABCDresult
111X0
0XX00
10X00
11000
0XX11
10X11
11011
165 $self->_is_a( $field => 'DB::Object::Fields::Field' ) )
166 {
167 0 $val = $field->datatype->constant;
168 }
169 0 return( $val );
170 }
171 2 ▶}}, @_ ) ); }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
172  
173 # The value to bind, if any at all. So could be undef
174 30 ▶sub value { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
175  
176 sub FREEZE
177 {
178 0 ▶ my $self = CORE::shift( @_ );
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
179 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
180 0 my $class = CORE::ref( $self );
181  
182 # We keep a strict allow-list to avoid accidentally freezing DBI handles or other
183 # process-local state.
184 0 my @props = @{$self->{_fields}};
185  
186 0 my $hash = {};
187 0 foreach my $prop ( @props )
188 {
189 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
190 defined( $self->{ $prop } ) &&
191 CORE::ref( $self->{ $prop } ) ne 'CODE' )
192 {
193 0 $hash->{ $prop } = $self->{ $prop };
194 }
195 }
196  
197 # Return an array reference rather than a list so this works with Sereal and CBOR.
198 # Before Sereal version 4.023, Sereal did not support multiple values returned.
199 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
200 {
201 0 require Sereal::Encoder;
202 0 require version;
203  
204 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
205 {
206 0 CORE::return( [$class, $hash] );
207 }
208 }
209  
210 # But Storable wants a list with the first element being the serialised element
211 0 CORE::return( $class, $hash );
212 }
213  
214 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
215  
216 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
217  
218 sub THAW
219 {
220 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
221 # 'CBOR' as the second value.
222 0 ▶ my( $self, undef, @args ) = @_;
Subroutine THAW: not called CC=10 SCAR=47.0
Pod undocumented
223 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
224 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
225 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
226 0 my $new;
227 # Storable pattern requires to modify the object it created rather than returning a new one
228 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
229 {
230 0 foreach( CORE::keys( %$hash ) )
231 {
232 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
233 }
234 0 $new = $self;
235 }
236 else
237 {
238 0 $new = CORE::bless( $hash => $class );
239 }
240 0 CORE::return( $new );
241 }
242  
243 4 1;
244 # NOTE: POD
245 __END__
246  
247 =encoding utf-8
248  
249 =head1 NAME
250  
251 DB::Object::Query::Element - Database Object Interface
252  
253 =head1 SYNOPSIS
254  
255 use DB::Object::Query::Element;
256 my $this = DB::Object::Query::Element->new(
257 # a scalar, or an DB::Object::Fields::Field object
258 field => $some_sql_field,
259 # designed to be used for insert statements
260 format => $some_format,
261 # The position, if any, of this new object
262 # This is used for numbered placeholders only,
263 # such as $1, $2, or ?1, ?2 depending on the driver
264 index => $integer,
265 # Could also be $1, $2, ?1, ?2 depending on the driver
266 placeholder => '?',
267 # a DB::Object::Query object
268 query_object => $object,
269 type => $sql_type,
270 value => $some_value,
271 ) || die( DB::Object::Query::Element->error );
272  
273 =head1 VERSION
274  
275 v0.3.1
276  
277 =head1 DESCRIPTION
278  
279 This class represent a L<query|DB::Object::Query> element as used throughout this API. It can represent the formatting of some part of an insert query, or some placeholder and its type and field, or just a field and its value, or a combination of those.
280  
281 It makes it more efficient to build query with their associated binded values and types in the proper order, possibly using numbered placeholder, if the SQL driver (such as L<PostgreSQL|DBD::Pg> or L<SQLite|DBD::sqlite>) support them.
282  
283 =head1 CONSTRUCTOR
284  
285 =head2 new
286  
287 Takes an hash or hash reference of key-value pairs matching any of the methods below.
288  
289 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.
290  
291 =head1 METHODS
292  
293 =head2 as_is
294  
295 Sets or gets the boolean value. If true, then the format specified will be used as-is during execution. This is aimed for value representing SQL functions or other values passed through that the user wants no optimisation.
296  
297 For example:
298  
299 my $tbl = $dbh->some_table || die( "No table found" );
300 $tbl->where( user_id => '?' );
301 my $sth = $tbl->update( updated => \'NOW()' ) || die( $tbl->error );
302 my $rv = $sth->exec( $user_id ) || die( $sth->error );
303  
304 In the example above, when C<NOW()> was specified as a scalar reference, it indicates we want the value to be used I<as-is>. This would translate to something like:
305  
306 UPDATE some_table SET updated = NOW() WHERE user_id = 'b9c01f91-8094-462c-9f49-a0340dc9fcec'
307  
308 =head2 attach
309  
310 This takes a L<DB::Object::Query::Elements> object, and attach it to our current object.
311  
312 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.
313  
314 =head2 elements
315  
316 Sets or gets an L<DB::Object::Query::Elements> object. By default this is C<undef> and is used when this element represent a sub-query.
317  
318 =head2 field
319  
320 Sets or gets the element SQL field (or column) name. It can also be set to a L<DB::Object::Fields::Field> object.
321  
322 =head2 fo
323  
324 my $field_object = $el->fo;
325 $el->fo( $field_object );
326  
327 Sets or gets a L<table field object|DB::Object::Fields::Field>.
328  
329 If no field is set, then in accessor mode, this will retrieve the L<table field object|DB::Object::Fields::Field> for the L<field|/field> value currently set by calling L<fields|DB::Object::Tables> and passing it the field name set in L</field>, if any.
330  
331 If the value set in L</field> is already a L<table field object|DB::Object::Fields::Field>, then this is used instead of course.
332  
333 If nothing was found, it returns C<undef>, but if this method is called in object context, such as chaining, then a L<null object|Module::Generic::Null> will be returned instead to prevent a hard perl error.
334  
335 For example, assuming no L<field object|DB::Object::Fields::Field> could be found, the call below would normally return an error that C<name> cannot be called on an undefined value, but here it detects the call is in an object context and returns L<null object|Module::Generic::Null> allowing a fake C<name> method to be called and that will return C<undef>
336  
337 $el->fo->name;
338  
339 Once found the value is cached, so if called many times, there is no performance penalty.
340  
341 =head2 format
342  
343 Sets or gets the element formatting. This is used for insert statements.
344  
345 It returns a L<scalar object|Module::Generic::Scalar>
346  
347 =head2 generic
348  
349 Returns a string representing the element with placeholder. This does not mean this element is using a placeholder, but rather provides a generic representation to be used when binding data to it.
350  
351 The string returned is an object of L<Module::Generic::Scalar>
352  
353 =head2 index
354  
355 Sets or gets the placeholder index position.
356  
357 This is used if this element represents a placeholder and it is a numbered one, such as C<$1>, C<$2>, or C<?1>, C<?2> depending on what the driver supports.
358  
359 Returns the current value, which is by default C<undef>, or a L<Module::Generic::Number> object.
360  
361 =head2 is_numbered
362  
363 Read-only. Returns true (C<1>) if the element represent a placeholder and it is a numbered one, such as C<$1>, C<$2>, or C<?1>, C<?2> depending on what the driver supports, or false (C<0>) otherwise.
364  
365 =head2 placeholder
366  
367 Sets or gets the element placeholder, such as C<?>, or C<$1>, C<$2>, or C<?1>, C<?2> depending on what the driver supports.
368  
369 When a value is set, it will check if this is a numbered placeholder and set the value for L</index> accordingly.
370  
371 =head2 query_object
372  
373 Sets or gets the L<DB::Object::Query> object set for this object.
374  
375 =head2 type
376  
377 Sets or gets the field SQL type.
378  
379 Returns a L<scalar object|Module::Generic::Scalar> object.
380  
381 =head2 value
382  
383 Sets or gets the element value.
384  
385 Returns a L<scalar object|Module::Generic::Scalar> object.
386  
387 =head1 AUTHOR
388  
389 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
390  
391 =head1 SEE ALSO
392  
393 L<perl>
394  
395 =head1 COPYRIGHT & LICENSE
396  
397 Copyright(c) 2023 DEGUEST Pte. Ltd.
398  
399 All rights reserved
400 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
401  
402 =cut
« blib/lib/DB/Object/Postgres.pm ↑ Summary lib/DB/Object/Query/Clause.pm »