Statement/Operation.pm

filter: Statementstmt 86.3% 171 / 198 Branchbran 63.6% 14 / 22 Conditioncond 46.8% 22 / 47 MC/DCmcdc 37.9% 11 / 29 Subroutinesub 72.5% 45 / 62 Podpod 100% 6 / 6 totaltotal 73.9% 269 / 364 CC 30 SCAR 14.6
CC
30
Cov
78%
operate
30.0
operate
6.1
operate
6.0
CRAP 4.3
« Statement/Term.pm ↑ Summary Statement/Util.pm »
1 package SQL::Statement::Operation;
2  
3 ######################################################################
4 #
5 # This module is copyright (c), 2009-2020 by Jens Rehsack.
6 # All rights reserved.
7 #
8 # It may be freely distributed under the same terms as Perl itself.
9 # See below for help and copyright information (search for SYNOPSIS).
10 #
11 ######################################################################
12  
13 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use warnings FATAL => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 16 ▶use SQL::Statement::Term ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 16 our $VERSION = '1.414';
22  
23 16 @ISA = qw(SQL::Statement::Term);
24  
25 =pod
26  
27 =head1 NAME
28  
29 SQL::Statement::Operation - base class for all operation terms
30  
31 =head1 SYNOPSIS
32  
33 # create an operation with an SQL::Statement object as owner, specifying
34 # the operation name (for error purposes), the left and the right
35 # operand
36 my $term = SQL::Statement::Operation->new( $owner, $op, $left, $right );
37 # access the result of that operation
38 $term->value( $eval );
39  
40 =head1 DESCRIPTION
41  
42 SQL::Statement::Operation is an abstract base class providing the interface
43 for all operation terms.
44  
45 =head1 INHERITANCE
46  
47 SQL::Statement::Operation
48 ISA SQL::Statement::Term
49  
50 =head1 METHODS
51  
52 =head2 new
53  
54 Instantiates new operation term.
55  
56 =head2 value
57  
58 Return the result of the operation of the term by calling L<operate>
59  
60 =head2 operate
61  
62 I<Abstract> method which will do the operation of the term. Must be
63 overridden by derived classes.
64  
65 =head2 op
66  
67 Returns the name of the executed operation.
68  
69 =head2 left
70  
71 Returns the left operand (if any).
72  
73 =head2 right
74  
75 Returns the right operand (if any).
76  
77 =head2 DESTROY
78  
79 Destroys the term and undefines the weak reference to the owner as well
80 as the stored operation, the left and the right operand.
81  
82 =cut
83  
84 sub new
85 297 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
86 297 my ( $class, $owner, $operation, $leftTerm, $rightTerm ) = @_;
87  
88 297 my $self = $class->SUPER::new($owner);
89 297 $self->{OP} = $operation;
90 297 $self->{LEFT} = $leftTerm;
91 297 $self->{RIGHT} = $rightTerm;
92  
93 297 return $self;
94 }
95  
96 1 ▶sub op { return $_[0]->{OP}; }
Subroutine op: called CC=1 SCAR=0.0
Pod documented
97 0 ▶sub left { return $_[0]->{LEFT}; }
Subroutine left: not called CC=1 SCAR=6.9
Pod documented
98 0 ▶sub right { return $_[0]->{RIGHT}; }
Subroutine right: not called CC=1 SCAR=6.9
Pod documented
99  
100 sub operate($)
101 0 ▶{
Subroutine operate: not called CC=2 SCAR=17.9
Pod documented
102 0 ▶ Carp::confess( sprintf( q{pure virtual function 'operate' called on %s for %s}, ref( $_[0] ) || __PACKAGE__, $_[0]->{OP} ) );
Condition0%0/2
ref $_[0] || __PACKAGE__
l!l
00
MC/DC0%0/1
ref $_[0] || __PACKAGE__
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
Aresult
11
00
103 }
104  
105 sub DESTROY
106 297 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
107 297 my $self = $_[0];
108  
109 297 undef $self->{OP};
110 297 undef $self->{LEFT};
111 297 undef $self->{RIGHT};
112  
113 297 $self->SUPER::DESTROY();
114 }
115  
116 1204 ▶sub value($) { return $_[0]->operate( $_[1] ); }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
117  
118 package SQL::Statement::Operation::Neg;
119  
120 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
121 16 @ISA = qw(SQL::Statement::Operation);
122  
123 =pod
124  
125 =head1 NAME
126  
127 SQL::Statement::Operation::Neg - negate operation
128  
129 =head1 SYNOPSIS
130  
131 # create an <not> operation with an SQL::Statement object as owner,
132 # specifying the operation name, the left and B<no> right operand
133 my $term = SQL::Statement::Neg->new( $owner, $op, $left, undef );
134 # access the result of that operation
135 $term->value( $eval );
136  
137 =head1 DESCRIPTION
138  
139 SQL::Statement::Operation::Neg
140  
141 =head1 INHERITANCE
142  
143 SQL::Statement::Operation::Neg
144 ISA SQL::Statement::Operation
145 ISA SQL::Statement::Term
146  
147 =head1 METHODS
148  
149 =head2 operate
150  
151 Return the logical negated value of the left operand.
152  
153 =cut
154  
155 sub operate($)
156 72 ▶{
Subroutine operate: called CC=1 SCAR=0.0
157 72 return !$_[0]->{LEFT}->value( $_[1] );
158 }
159  
160 package SQL::Statement::Operation::And;
161  
162 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
163 16 @ISA = qw(SQL::Statement::Operation);
164  
165 =pod
166  
167 =head1 NAME
168  
169 SQL::Statement::Operation::And - and operation
170  
171 =head1 SYNOPSIS
172  
173 # create an C<and> operation with an SQL::Statement object as owner,
174 # specifying the operation name, the left and the right operand
175 my $term = SQL::Statement::And->new( $owner, $op, $left, $right );
176 # access the result of that operation
177 $term->value( $eval );
178  
179 =head1 DESCRIPTION
180  
181 SQL::Statement::Operation::And implements the logical C<and> operation
182 between two terms.
183  
184 =head1 INHERITANCE
185  
186 SQL::Statement::Operation::And
187 ISA SQL::Statement::Operation
188 ISA SQL::Statement::Term
189  
190 =head1 METHODS
191  
192 =head2 operate
193  
194 Return the result of the logical C<and> operation for the L<value>s of the
195 left and right operand.
196  
197 =cut
198  
199 sub operate($)
200 326 ▶{
Subroutine operate: called CC=2 SCAR=6.9
201 326 my $left = $_[0]->{LEFT}->value( $_[1] );
202 326 my $right = $_[0]->{RIGHT}->value( $_[1] );
203  
204 326 ▶ return $left && $right;
Condition100%3/3
$left && $right
!ll&&!rl&&r
8195150
MC/DC100%2/2
$left && $right
$left $right
Truth table100%3/3
A && B
A= $leftB= $right
ABresult
0X0
100
111
205 }
206  
207 package SQL::Statement::Operation::Or;
208  
209 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
210 16 @ISA = qw(SQL::Statement::Operation);
211  
212 =pod
213  
214 =head1 NAME
215  
216 SQL::Statement::Operation::Or - or operation
217  
218 =head1 SYNOPSIS
219  
220 # create an C<or> operation with an SQL::Statement object as owner,
221 # specifying the operation name, the left and the right operand
222 my $term = SQL::Statement::Or->new( $owner, $op, $left, $right );
223 # access the result of that operation
224 $term->value( $eval );
225  
226 =head1 DESCRIPTION
227  
228 SQL::Statement::Operation::Or implements the logical C<or> operation
229 between two terms.
230  
231 =head1 INHERITANCE
232  
233 SQL::Statement::Operation::Or
234 ISA SQL::Statement::Operation
235 ISA SQL::Statement::Term
236  
237 =head1 METHODS
238  
239 =head2 operate
240  
241 Return the result of the logical C<or> operation for the L<value>s of the
242 left and right operand.
243  
244 =cut
245  
246 sub operate($)
247 11 ▶{
Subroutine operate: called CC=2 SCAR=6.9
248 11 my $left = $_[0]->{LEFT}->value( $_[1] );
249 11 my $right = $_[0]->{RIGHT}->value( $_[1] );
250  
251 11 ▶ return $left || $right;
Condition100%3/3
$left || $right
l!l&&r!l&&!r
515
MC/DC100%2/2
$left || $right
$left $right
Truth table100%3/3
A || B
A= $leftB= $right
ABresult
1X1
011
000
252 }
253  
254 package SQL::Statement::Operation::Is;
255  
256 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
257 16 @ISA = qw(SQL::Statement::Operation);
258  
259 =pod
260  
261 =head1 NAME
262  
263 SQL::Statement::Operation::Is - is operation
264  
265 =head1 SYNOPSIS
266  
267 # create an C<is> operation with an SQL::Statement object as owner,
268 # specifying the operation name, the left and the right operand
269 my $term = SQL::Statement::Is->new( $owner, $op, $left, $right );
270 # access the result of that operation
271 $term->value( $eval );
272  
273 =head1 DESCRIPTION
274  
275 SQL::Statement::Operation::Is supports: C<IS NULL>, C<IS TRUE> and C<IS FALSE>.
276 The right operand is always evaluated in boolean context in case of C<IS TRUE>
277 and C<IS FALSE>. C<IS NULL> returns I<true> even if the left term is an empty
278 string (C<''>).
279  
280 =head1 INHERITANCE
281  
282 SQL::Statement::Operation::Is
283 ISA SQL::Statement::Operation
284 ISA SQL::Statement::Term
285  
286 =head1 METHODS
287  
288 =head2 operate
289  
290 Returns true when the left term is null, true or false - based on the
291 requested right value.
292  
293 =cut
294  
295 sub operate($)
296 0 ▶{
Subroutine operate: not called CC=5 SCAR=34.0
297 0 my $self = $_[0];
298 0 my $left = $self->{LEFT}->value( $_[1] );
299 0 my $right = $self->{RIGHT}->value( $_[1] );
300 0 my $expr;
301  
302 0 ▶ if ( defined($right) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $right) { } 0 0 0
303 {
304 0 ▶ $expr = defined($left) ? $left && $right : 0; # is true / is false
Branch: 1 branch
BranchTrueFalseTotal
defined $left ? : 0 0 0
Condition0%0/3
$left and $right
!ll&&!rl&&r
000
MC/DC0%0/2
$left and $right
$left $right
Truth table0%0/3
A and B
A= $leftB= $right
ABresult
0X0
100
111
305 }
306 else
307 {
308 0 ▶ $expr = !defined($left) || ( $left eq '' ); # FIXME I don't like that '' IS NULL
Condition0%0/3
!defined($left) || $left eq ''
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($left) || $left eq ''
!defined($left) $left eq ''
Truth table0%0/3
not(A) || B
A= !defined($left)B= $left eq ''
ABresult
1X1
011
000
309 }
310  
311 0 return $expr;
312 }
313  
314 package SQL::Statement::Operation::ANSI::Is;
315  
316 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
317 16 @ISA = qw(SQL::Statement::Operation);
318  
319 =pod
320  
321 =head1 NAME
322  
323 SQL::Statement::Operation::ANSI::Is - is operation
324  
325 =head1 SYNOPSIS
326  
327 # create an C<is> operation with an SQL::Statement object as owner,
328 # specifying the operation name, the left and the right operand
329 my $term = SQL::Statement::Is->new( $owner, $op, $left, $right );
330 # access the result of that operation
331 $term->value( $eval );
332  
333 =head1 DESCRIPTION
334  
335 SQL::Statement::Operation::ANSI::Is supports: C<IS NULL>, C<IS TRUE> and C<IS FALSE>.
336 The right operand is always evaluated in boolean context in case of C<IS TRUE>
337 and C<IS FALSE>. C<IS NULL> returns I<true> if the right term is not defined,
338 I<false> otherwise.
339  
340 =head1 INHERITANCE
341  
342 SQL::Statement::Operation::Is
343 ISA SQL::Statement::Operation
344 ISA SQL::Statement::Term
345  
346 =head1 METHODS
347  
348 =head2 operate
349  
350 Returns true when the left term is null, true or false - based on the
351 requested right value.
352  
353 =cut
354  
355 sub operate($)
356 3 ▶{
Subroutine operate: called CC=4 SCAR=17.3
357 3 my $self = $_[0];
358 3 my $left = $self->{LEFT}->value( $_[1] );
359 3 my $right = $self->{RIGHT}->value( $_[1] );
360 3 my $expr;
361  
362 3 ▶ if ( defined($right) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $right) { } 0 3 3
363 {
364 0 ▶ $expr = defined($left) ? $left && $right : 0; # is true / is false
Branch: 1 branch
BranchTrueFalseTotal
defined $left ? : 0 0 0
Condition0%0/3
$left and $right
!ll&&!rl&&r
000
MC/DC0%0/2
$left and $right
$left $right
Truth table0%0/3
A and B
A= $leftB= $right
ABresult
0X0
100
111
365 }
366 else
367 {
368 3 $expr = !defined($left);
369 }
370  
371 3 return $expr;
372 }
373  
374 package SQL::Statement::Operation::Contains;
375  
376 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
377 16 @ISA = qw(SQL::Statement::Operation);
378 16 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
379  
380 =pod
381  
382 =head1 NAME
383  
384 SQL::Statement::Operation::Contains - in operation
385  
386 =head1 SYNOPSIS
387  
388 # create an C<in> operation with an SQL::Statement object as owner,
389 # specifying the operation name, the left and the right operand
390 my $term = SQL::Statement::Contains->new( $owner, $op, $left, $right );
391 # access the result of that operation
392 $term->value( $eval );
393  
394 =head1 DESCRIPTION
395  
396 SQL::Statement::Operation::Contains expects the right operand is an array
397 of L<SQL::Statement::Term> instances. It checks whether the left operand
398 is in the list of the right operands or not like:
399  
400 $left->value($eval) ~~ map { $_->value($eval) } @{$right}
401  
402 =head1 INHERITANCE
403  
404 SQL::Statement::Operation::Contains
405 ISA SQL::Statement::Operation
406 ISA SQL::Statement::Term
407  
408 =head1 METHODS
409  
410 =head2 operate
411  
412 Returns true when the left term is equal to any of the right terms
413  
414 =cut
415  
416 sub operate($)
417 71 ▶{
Subroutine operate: called CC=5 SCAR=16.1
418 71 my ( $self, $eval ) = @_;
419 71 my $left = $self->{LEFT}->value($eval);
420 71 my @right = map { $_->value($eval); } @{ $self->{RIGHT} };
421 71 my $expr = 0;
422  
423 71 foreach my $r (@right)
424 {
425 last
426 228 ▶ if $expr |= ( looks_like_number($left) && looks_like_number($r) ) ? $left == $r : $left eq $r;
Branch: 2 branches
BranchTrueFalseTotal
if $expr |= &looks_like_number($left) && &looks_like_number($r) ? $left == $r : $left eq $r 29 199 228
&looks_like_number($left) && &looks_like_number($r) ? : 123 105 228
Condition66%2/3
&looks_like_number($left) and &looks_like_number($r)
!ll&&!rl&&r
1050123
MC/DC50%1/2
&looks_like_number($left) and &looks_like_number($r)
&looks_like_number($left) &looks_like_number($r)
Truth table66%2/3
A and B
A= &looks_like_number($left)B= &looks_like_number($r)
ABresult
0X0
100
111
427 }
428  
429 71 return $expr;
430 }
431  
432 package SQL::Statement::Operation::Between;
433  
434 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
435 16 @ISA = qw(SQL::Statement::Operation);
436 16 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
437  
438 =pod
439  
440 =head1 NAME
441  
442 SQL::Statement::Operation::Between - between operation
443  
444 =head1 SYNOPSIS
445  
446 # create an C<between> operation with an SQL::Statement object as owner,
447 # specifying the operation name, the left and the right operand
448 my $term = SQL::Statement::Between->new( $owner, $op, $left, $right );
449 # access the result of that operation
450 $term->value( $eval );
451  
452 =head1 DESCRIPTION
453  
454 SQL::Statement::Operation::Between expects the right operand is an array
455 of 2 L<SQL::Statement::Term> instances. It checks whether the left operand
456 is between the right operands like:
457  
458 ( $left->value($eval) >= $right[0]->value($eval) )
459 && ( $left->value($eval) <= $right[1]->value($eval) )
460  
461 =head1 INHERITANCE
462  
463 SQL::Statement::Operation::Between
464 ISA SQL::Statement::Operation
465 ISA SQL::Statement::Term
466  
467 =head1 METHODS
468  
469 =head2 operate
470  
471 Returns true when the left term is between both right terms
472  
473 =cut
474  
475 sub operate($)
476 71 ▶{
Subroutine operate: called CC=6 SCAR=18.0
477 71 my ( $self, $eval ) = @_;
478 71 my $left = $self->{LEFT}->value($eval);
479 71 my @right = map { $_->value($eval); } @{ $self->{RIGHT} };
480 71 my $expr = 0;
481  
482 71 ▶ if ( looks_like_number($left)
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($left) and &looks_like_number($right[0]) and &looks_like_number($right[1])) { } 44 27 71
Condition66%4/6
&looks_like_number($left) and &looks_like_number($right[0]) and &looks_like_number($right[1])
!ll&&!rl&&r
27044
&looks_like_number($left) and &looks_like_number($right[0])
!ll&&!rl&&r
27044
MC/DC33%1/3
&looks_like_number($left) and &looks_like_number($right[0]) and &looks_like_number($right[1])
&looks_like_number($left) &looks_like_number($right[0]) &looks_like_number($right[1])
Truth table50%2/4
A and B and C
A= &looks_like_number($left)B= &looks_like_number($right[0])C= &looks_like_number($right[1])
ABCresult
0XX0
10X0
1100
1111
483 && looks_like_number( $right[0] )
484 && looks_like_number( $right[1] ) )
485 {
486 44 ▶ $expr = ( $left >= $right[0] ) && ( $left <= $right[1] );
Condition100%3/3
$left >= $right[0] && $left <= $right[1]
!ll&&!rl&&r
22616
MC/DC100%2/2
$left >= $right[0] && $left <= $right[1]
$left >= $right[0] $left <= $right[1]
Truth table100%3/3
A && B
A= $left >= $right[0]B= $left <= $right[1]
ABresult
0X0
100
111
487 }
488 else
489 {
490 27 ▶ $expr = ( $left ge $right[0] ) && ( $left le $right[1] );
Condition66%2/3
$left ge $right[0] && $left le $right[1]
!ll&&!rl&&r
01215
MC/DC50%1/2
$left ge $right[0] && $left le $right[1]
$left ge $right[0] $left le $right[1]
Truth table66%2/3
A && B
A= $left ge $right[0]B= $left le $right[1]
ABresult
0X0
100
111
491 }
492  
493 71 return $expr;
494 }
495  
496 package SQL::Statement::Operation::Equality;
497  
498 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
499 16 @ISA = qw(SQL::Statement::Operation);
500  
501 16 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
502 16 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
503  
504 =pod
505  
506 =head1 NAME
507  
508 SQL::Statement::Operation::Equality - abstract base class for comparisons
509  
510 =head1 SYNOPSIS
511  
512 # create an C<equality> operation with an SQL::Statement object as owner,
513 # specifying the operation name, the left and the right operand
514 my $term = SQL::Statement::Equality->new( $owner, $op, $left, $right );
515 # access the result of that operation
516 $term->value( $eval );
517  
518 =head1 DESCRIPTION
519  
520 SQL::Statement::Operation::Equality implements compare operations between
521 two terms - choosing either numerical comparison or string comparison,
522 depending whether both operands are numeric or not.
523  
524 =head1 INHERITANCE
525  
526 SQL::Statement::Operation::Equality
527 ISA SQL::Statement::Operation
528 ISA SQL::Statement::Term
529  
530 =head1 METHODS
531  
532 =head2 operate
533  
534 Return the result of the comparison.
535  
536 =head2 numcmp
537  
538 I<Abstract> method which will do the numeric comparison of both terms. Must be
539 overridden by derived classes.
540  
541 =head2 strcmp
542  
543 I<Abstract> method which will do the string comparison of both terms. Must be
544 overridden by derived classes.
545  
546 =cut
547  
548 sub operate($)
549 569 ▶{
Subroutine operate: called CC=5 SCAR=16.2
550 569 my $self = $_[0];
551 569 my $left = $self->{LEFT}->value( $_[1] );
552 569 my $right = $self->{RIGHT}->value( $_[1] );
553 569 ▶ return 0 unless ( defined($left) && defined($right) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left and defined $right 2 567 569
Condition66%2/3
defined $left and defined $right
!ll&&!rl&&r
20567
MC/DC50%1/2
defined $left and defined $right
defined $left defined $right
Truth table66%2/3
A and B
A= defined $leftB= defined $right
ABresult
0X0
100
111
554 567 ▶ return ( looks_like_number($left) && looks_like_number($right) )
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($left) && &looks_like_number($right) ? : 505 62 567
Condition66%2/3
&looks_like_number($left) and &looks_like_number($right)
!ll&&!rl&&r
620505
MC/DC50%1/2
&looks_like_number($left) and &looks_like_number($right)
&looks_like_number($left) &looks_like_number($right)
Truth table66%2/3
A and B
A= &looks_like_number($left)B= &looks_like_number($right)
ABresult
0X0
100
111
555 ? $self->numcmp( $left, $right )
556 : $self->strcmp( $left, $right );
557 }
558  
559 sub numcmp($)
560 0 ▶{
Subroutine numcmp: not called CC=2 SCAR=17.9
561 0 ▶ Carp::confess( sprintf( q{pure virtual function 'numcmp' called on %s for %s}, ref( $_[0] ) || __PACKAGE__, $_[0]->{OP} ) );
Condition0%0/2
ref $_[0] || __PACKAGE__
l!l
00
MC/DC0%0/1
ref $_[0] || __PACKAGE__
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
Aresult
11
00
562 }
563  
564 sub strcmp($)
565 0 ▶{
Subroutine strcmp: not called CC=2 SCAR=17.9
566 0 ▶ Carp::confess( sprintf( q{pure virtual function 'strcmp' called on %s for %s}, ref( $_[0] ) || __PACKAGE__, $_[0]->{OP} ) );
Condition0%0/2
ref $_[0] || __PACKAGE__
l!l
00
MC/DC0%0/1
ref $_[0] || __PACKAGE__
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
Aresult
11
00
567 }
568  
569 package SQL::Statement::Operation::Equal;
570  
571 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
572 16 @ISA = qw(SQL::Statement::Operation::Equality);
573  
574 =pod
575  
576 =head1 NAME
577  
578 SQL::Statement::Operation::Equal - implements equal operation
579  
580 =head1 SYNOPSIS
581  
582 # create an C<equal> operation with an SQL::Statement object as owner,
583 # specifying the operation name, the left and the right operand
584 my $term = SQL::Statement::Equal->new( $owner, $op, $left, $right );
585 # access the result of that operation
586 $term->value( $eval );
587  
588 =head1 DESCRIPTION
589  
590 SQL::Statement::Operation::Equal implements compare operations between
591 two numbers and two strings.
592  
593 =head1 INHERITANCE
594  
595 SQL::Statement::Operation::Equal
596 ISA SQL::Statement::Operation::Equality
597 ISA SQL::Statement::Operation
598 ISA SQL::Statement::Term
599  
600 =head1 METHODS
601  
602 =head2 numcmp
603  
604 Return true when C<$left == $right>
605  
606 =head2 strcmp
607  
608 Return true when C<$left eq $right>
609  
610 =cut
611  
612 444 ▶sub numcmp($$) { return $_[1] == $_[2]; }
Subroutine numcmp: called CC=1 SCAR=0.0
613 62 ▶sub strcmp($$) { return $_[1] eq $_[2]; }
Subroutine strcmp: called CC=1 SCAR=0.0
614  
615 package SQL::Statement::Operation::NotEqual;
616  
617 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
618 16 @ISA = qw(SQL::Statement::Operation::Equality);
619  
620 =pod
621  
622 =head1 NAME
623  
624 SQL::Statement::Operation::NotEqual - implements not equal operation
625  
626 =head1 SYNOPSIS
627  
628 # create an C<not equal> operation with an SQL::Statement object as owner,
629 # specifying the operation name, the left and the right operand
630 my $term = SQL::Statement::NotEqual->new( $owner, $op, $left, $right );
631 # access the result of that operation
632 $term->value( $eval );
633  
634 =head1 DESCRIPTION
635  
636 SQL::Statement::Operation::NotEqual implements negated compare operations
637 between two numbers and two strings.
638  
639 =head1 INHERITANCE
640  
641 SQL::Statement::Operation::NotEqual
642 ISA SQL::Statement::Operation::Equality
643 ISA SQL::Statement::Operation
644 ISA SQL::Statement::Term
645  
646 =head1 METHODS
647  
648 =head2 numcmp
649  
650 Return true when C<$left != $right>
651  
652 =head2 strcmp
653  
654 Return true when C<$left ne $right>
655  
656 =cut
657  
658 0 ▶sub numcmp($$) { return $_[1] != $_[2]; }
Subroutine numcmp: not called CC=1 SCAR=6.9
659 0 ▶sub strcmp($$) { return $_[1] ne $_[2]; }
Subroutine strcmp: not called CC=1 SCAR=6.9
660  
661 package SQL::Statement::Operation::Lower;
662  
663 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
664 16 @ISA = qw(SQL::Statement::Operation::Equality);
665  
666 =pod
667  
668 =head1 NAME
669  
670 SQL::Statement::Operation::Lower - implements lower than operation
671  
672 =head1 SYNOPSIS
673  
674 # create an C<lower than> operation with an SQL::Statement object as owner,
675 # specifying the operation name, the left and the right operand
676 my $term = SQL::Statement::Lower->new( $owner, $op, $left, $right );
677 # access the result of that operation
678 $term->value( $eval );
679  
680 =head1 DESCRIPTION
681  
682 SQL::Statement::Operation::Lower implements lower than compare operations
683 between two numbers and two strings.
684  
685 =head1 INHERITANCE
686  
687 SQL::Statement::Operation::Lower
688 ISA SQL::Statement::Operation::Equality
689 ISA SQL::Statement::Operation
690 ISA SQL::Statement::Term
691  
692 =head1 METHODS
693  
694 =head2 numcmp
695  
696 Return true when C<$left < $right>
697  
698 =head2 strcmp
699  
700 Return true when C<$left lt $right>
701  
702 =cut
703  
704 39 ▶sub numcmp($$) { return $_[1] < $_[2]; }
Subroutine numcmp: called CC=1 SCAR=0.0
705 0 ▶sub strcmp($$) { return $_[1] lt $_[2]; }
Subroutine strcmp: not called CC=1 SCAR=6.9
706  
707 package SQL::Statement::Operation::Greater;
708  
709 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
710 16 @ISA = qw(SQL::Statement::Operation::Equality);
711  
712 =pod
713  
714 =head1 NAME
715  
716 SQL::Statement::Operation::Greater - implements greater than operation
717  
718 =head1 SYNOPSIS
719  
720 # create an C<greater than> operation with an SQL::Statement object as owner,
721 # specifying the operation name, the left and the right operand
722 my $term = SQL::Statement::Greater->new( $owner, $op, $left, $right );
723 # access the result of that operation
724 $term->value( $eval );
725  
726 =head1 DESCRIPTION
727  
728 SQL::Statement::Operation::Greater implements greater than compare operations
729 between two numbers and two strings.
730  
731 =head1 INHERITANCE
732  
733 SQL::Statement::Operation::Greater
734 ISA SQL::Statement::Operation::Equality
735 ISA SQL::Statement::Operation
736 ISA SQL::Statement::Term
737  
738 =head1 METHODS
739  
740 =head2 numcmp
741  
742 Return true when C<$left > $right>
743  
744 =head2 strcmp
745  
746 Return true when C<$left gt $right>
747  
748 =cut
749  
750 22 ▶sub numcmp($$) { return $_[1] > $_[2]; }
Subroutine numcmp: called CC=1 SCAR=0.0
751 0 ▶sub strcmp($$) { return $_[1] gt $_[2]; }
Subroutine strcmp: not called CC=1 SCAR=6.9
752  
753 package SQL::Statement::Operation::LowerEqual;
754  
755 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
756 16 @ISA = qw(SQL::Statement::Operation::Equality);
757  
758 =pod
759  
760 =head1 NAME
761  
762 SQL::Statement::Operation::LowerEqual - implements lower equal operation
763  
764 =head1 SYNOPSIS
765  
766 # create an C<lower equal> operation with an SQL::Statement object as owner,
767 # specifying the operation name, the left and the right operand
768 my $term = SQL::Statement::LowerEqual->new( $owner, $op, $left, $right );
769 # access the result of that operation
770 $term->value( $eval );
771  
772 =head1 DESCRIPTION
773  
774 SQL::Statement::Operation::LowerEqual implements lower equal compare operations
775 between two numbers and two strings.
776  
777 =head1 INHERITANCE
778  
779 SQL::Statement::Operation::LowerEqual
780 ISA SQL::Statement::Operation::Equality
781 ISA SQL::Statement::Operation
782 ISA SQL::Statement::Term
783  
784 =head1 METHODS
785  
786 =head2 numcmp
787  
788 Return true when C<$left <= $right>
789  
790 =head2 strcmp
791  
792 Return true when C<$left le $right>
793  
794 =cut
795  
796 0 ▶sub numcmp($$) { return $_[1] <= $_[2]; }
Subroutine numcmp: not called CC=1 SCAR=6.9
797 0 ▶sub strcmp($$) { return $_[1] le $_[2]; }
Subroutine strcmp: not called CC=1 SCAR=6.9
798  
799 package SQL::Statement::Operation::GreaterEqual;
800  
801 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
802 16 @ISA = qw(SQL::Statement::Operation::Equality);
803  
804 =pod
805  
806 =head1 NAME
807  
808 SQL::Statement::Operation::GreaterEqual - implements greater equal operation
809  
810 =head1 SYNOPSIS
811  
812 # create an C<greater equal> operation with an SQL::Statement object as owner,
813 # specifying the operation name, the left and the right operand
814 my $term = SQL::Statement::GreaterEqual->new( $owner, $op, $left, $right );
815 # access the result of that operation
816 $term->value( $eval );
817  
818 =head1 DESCRIPTION
819  
820 SQL::Statement::Operation::GreaterEqual implements greater equal compare operations
821 between two numbers and two strings.
822  
823 =head1 INHERITANCE
824  
825 SQL::Statement::Operation::GreaterEqual
826 ISA SQL::Statement::Operation::Equality
827 ISA SQL::Statement::Operation
828 ISA SQL::Statement::Term
829  
830 =head1 METHODS
831  
832 =head2 numcmp
833  
834 Return true when C<$left >= $right>
835  
836 =head2 strcmp
837  
838 Return true when C<$left ge $right>
839  
840 =cut
841  
842 0 ▶sub numcmp($$) { return $_[1] >= $_[2]; }
Subroutine numcmp: not called CC=1 SCAR=6.9
843 0 ▶sub strcmp($$) { return $_[1] ge $_[2]; }
Subroutine strcmp: not called CC=1 SCAR=6.9
844  
845 package SQL::Statement::Operation::Regexp;
846  
847 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
848 16 @ISA = qw(SQL::Statement::Operation);
849  
850 =pod
851  
852 =head1 NAME
853  
854 SQL::Statement::Operation::Regexp - abstract base class for comparisons based on regular expressions
855  
856 =head1 SYNOPSIS
857  
858 # create an C<regexp> operation with an SQL::Statement object as owner,
859 # specifying the operation name, the left and the right operand
860 my $term = SQL::Statement::Regexp->new( $owner, $op, $left, $right );
861 # access the result of that operation
862 $term->value( $eval );
863  
864 =head1 DESCRIPTION
865  
866 SQL::Statement::Operation::Regexp implements the comparisons for the C<LIKE>
867 operation family.
868  
869 =head1 INHERITANCE
870  
871 SQL::Statement::Operation::Regexp
872 ISA SQL::Statement::Operation
873 ISA SQL::Statement::Term
874  
875 =head1 METHODS
876  
877 =head2 operate
878  
879 Return the result of the comparison.
880  
881 =head2 right
882  
883 Returns the regular expression based on the right term. The right term
884 is expected to be constant - so C<a LIKE b> in not supported.
885  
886 =head2 regexp
887  
888 I<Abstract> method which must return a regular expression (C<qr//>) from
889 the given string. Must be overridden by derived classes.
890  
891 =cut
892  
893 sub right($)
894 81 ▶{
Subroutine right: called CC=2 SCAR=6.9
895 81 my $self = $_[0];
896 81 my $right = $self->{RIGHT}->value( $_[1] );
897  
898 81 ▶ unless ( defined( $self->{PATTERNS}->{$right} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"PATTERNS"}{$right}) 5 76 81
899 {
900 5 $self->{PATTERNS}->{$right} = $right;
901 5 $self->{PATTERNS}->{$right} =~ s/%/.*/g;
902 5 $self->{PATTERNS}->{$right} = $self->regexp( $self->{PATTERNS}->{$right} );
903 }
904  
905 81 return $self->{PATTERNS}->{$right};
906 }
907  
908 sub regexp($)
909 0 ▶{
Subroutine regexp: not called CC=2 SCAR=17.9
910 0 ▶ Carp::confess( sprintf( q{pure virtual function 'regexp' called on %s for %s}, ref( $_[0] ) || __PACKAGE__, $_[0]->{OP} ) );
Condition0%0/2
ref $_[0] || __PACKAGE__
l!l
00
MC/DC0%0/1
ref $_[0] || __PACKAGE__
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
Aresult
11
00
911 }
912  
913 sub operate($)
914 81 ▶{
Subroutine operate: called CC=3 SCAR=11.8
915 81 my $self = $_[0];
916 81 my $left = $self->{LEFT}->value( $_[1] );
917 81 my $right = $self->right( $_[1] );
918  
919 81 ▶ return 0 unless ( defined($left) && defined($right) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left and defined $right 0 81 81
Condition33%1/3
defined $left and defined $right
!ll&&!rl&&r
0081
MC/DC0%0/2
defined $left and defined $right
defined $left defined $right
Truth table33%1/3
A and B
A= defined $leftB= defined $right
ABresult
0X0
100
111
920 81 return $left =~ m/^$right$/s;
921 }
922  
923 package SQL::Statement::Operation::Like;
924  
925 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
926 16 @ISA = qw(SQL::Statement::Operation::Regexp);
927  
928 =pod
929  
930 =head1 NAME
931  
932 SQL::Statement::Operation::Like - implements the like operation
933  
934 =head1 SYNOPSIS
935  
936 # create an C<like> operation with an SQL::Statement object as owner,
937 # specifying the operation name, the left and the right operand
938 my $term = SQL::Statement::Like->new( $owner, $op, $left, $right );
939 # access the result of that operation
940 $term->value( $eval );
941  
942 =head1 DESCRIPTION
943  
944 SQL::Statement::Operation::Like is used to the comparisons for the C<LIKE>
945 operation.
946  
947 =head1 INHERITANCE
948  
949 SQL::Statement::Operation::Like
950 ISA SQL::Statement::Operation::Regexp
951 ISA SQL::Statement::Operation
952 ISA SQL::Statement::Term
953  
954 =head1 METHODS
955  
956 =head2 regexp
957  
958 Returns C<qr/^$right$/s>
959  
960 =cut
961  
962 sub regexp($)
963 5 ▶{
Subroutine regexp: called CC=1 SCAR=0.0
964 5 my $right = $_[1];
965 5 return qr/^$right$/s;
966 }
967  
968 package SQL::Statement::Operation::Clike;
969  
970 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
971 16 @ISA = qw(SQL::Statement::Operation::Regexp);
972  
973 =pod
974  
975 =head1 NAME
976  
977 SQL::Statement::Operation::Clike - implements the clike operation
978  
979 =head1 SYNOPSIS
980  
981 # create an C<clike> operation with an SQL::Statement object as owner,
982 # specifying the operation name, the left and the right operand
983 my $term = SQL::Statement::Clike->new( $owner, $op, $left, $right );
984 # access the result of that operation
985 $term->value( $eval );
986  
987 =head1 DESCRIPTION
988  
989 SQL::Statement::Operation::Clike is used to the comparisons for the C<CLIKE>
990 operation.
991  
992 =head1 INHERITANCE
993  
994 SQL::Statement::Operation::Clike
995 ISA SQL::Statement::Operation::Regexp
996 ISA SQL::Statement::Operation
997 ISA SQL::Statement::Term
998  
999 =head1 METHODS
1000  
1001 =head2 regexp
1002  
1003 Returns C<qr/^$right$/si>
1004  
1005 =cut
1006  
1007 sub regexp($)
1008 0 ▶{
Subroutine regexp: not called CC=1 SCAR=6.9
1009 0 my $right = $_[1];
1010 0 return qr/^$right$/si;
1011 }
1012  
1013 package SQL::Statement::Operation::Rlike;
1014  
1015 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
1016 16 @ISA = qw(SQL::Statement::Operation::Regexp);
1017  
1018 =pod
1019  
1020 =head1 NAME
1021  
1022 SQL::Statement::Operation::RLike - implements the rlike operation
1023  
1024 =head1 SYNOPSIS
1025  
1026 # create an C<rlike> operation with an SQL::Statement object as owner,
1027 # specifying the operation name, the left and the right operand
1028 my $term = SQL::Statement::RLike->new( $owner, $op, $left, $right );
1029 # access the result of that operation
1030 $term->value( $eval );
1031  
1032 =head1 DESCRIPTION
1033  
1034 SQL::Statement::Operation::RLike is used to the comparisons for the C<RLIKE>
1035 operation.
1036  
1037 =head1 INHERITANCE
1038  
1039 SQL::Statement::Operation::RLike
1040 ISA SQL::Statement::Operation::Regexp
1041 ISA SQL::Statement::Operation
1042 ISA SQL::Statement::Term
1043  
1044 =head1 METHODS
1045  
1046 =head2 regexp
1047  
1048 Returns C<qr/$right$/s>
1049  
1050 =cut
1051  
1052 sub regexp($)
1053 0 ▶{
Subroutine regexp: not called CC=1 SCAR=6.9
1054 0 my $right = $_[1];
1055 0 return qr/$right$/;
1056 }
1057  
1058 =head1 AUTHOR AND COPYRIGHT
1059  
1060 Copyright (c) 2009-2020 by Jens Rehsack: rehsackATcpan.org
1061  
1062 All rights reserved.
1063  
1064 You may distribute this module under the terms of either the GNU
1065 General Public License or the Artistic License, as specified in
1066 the Perl README file.
1067  
1068 =cut
1069  
1070 16 1;
« Statement/Term.pm ↑ Summary Statement/Util.pm »