Query/Field/SQL.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 2 / 2 Conditioncond 60.0% 6 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 81.4% 35 / 43 CC 7 SCAR 17.8
CC
7
Cov
88%
BUILD
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 5.9
« Query/Clause.pm ↑ Summary Query/Dialect.pm »
1 package Search::Query::Field::SQL;
2 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 extends 'Search::Query::Field';
4  
5 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 has 'type' => ( is => 'rw' );
8 3 has 'fuzzy_op' => ( is => 'rw' );
9 3 has 'fuzzy_not_op' => ( is => 'rw' );
10 3 has 'is_int' => ( is => 'rw' );
11  
12 3 our $VERSION = '0.306';
13  
14 =head1 NAME
15  
16 Search::Query::Field::SQL - query field representing a database column
17  
18 =head1 SYNOPSIS
19  
20 my $field = Search::Query::Field::SQL->new(
21 name => 'foo',
22 alias_for => [qw( bar bing )],
23 );
24  
25 =head1 DESCRIPTION
26  
27 Search::Query::Field::SQL implements field
28 validation and aliasing in SQL search queries.
29  
30 =head1 METHODS
31  
32 This class is a subclass of Search::Query::Field. Only new or overridden
33 methods are documented here.
34  
35 =head2 BUILD
36  
37 Available params are also standard attribute accessor methods.
38  
39 =over
40  
41 =item type
42  
43 The column type.
44  
45 =item fuzzy_op
46  
47 =item fuzzy_not_op
48  
49 =item is_int
50  
51 Set if C<type> matches m/int|float|bool|time|date/.
52  
53 =back
54  
55 =cut
56  
57 sub BUILD {
58 17 ▶ my $self = shift;
Subroutine BUILD: called CC=7 SCAR=19.9
Pod documented
59  
60 17 ▶ $self->{type} ||= 'char';
Condition100%2/2
$self->{"type"} ||= "char"
l!l
314
MC/DC100%1/1
$self->{"type"} ||= "char"
$self->{"type"}
Truth table100%2/2
A
A= $self->{"type"}
Aresult
11
00
61  
62 # numeric types
63 17 ▶ if ( $self->{type} =~ m/int|float|bool|time|date/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'type'} =~ /int|float|bool|time|date/) { } 2 15 17
64 2 ▶ $self->{fuzzy_op} ||= '>=';
Condition50%1/2
$self->{"fuzzy_op"} ||= ">="
l!l
02
MC/DC0%0/1
$self->{"fuzzy_op"} ||= ">="
$self->{"fuzzy_op"}
Truth table50%1/2
A
A= $self->{"fuzzy_op"}
Aresult
11
00
65 2 ▶ $self->{fuzzy_not_op} ||= '! >=';
Condition50%1/2
$self->{"fuzzy_not_op"} ||= "! >="
l!l
02
MC/DC0%0/1
$self->{"fuzzy_not_op"} ||= "! >="
$self->{"fuzzy_not_op"}
Truth table50%1/2
A
A= $self->{"fuzzy_not_op"}
Aresult
11
00
66 2 $self->{is_int} = 1;
67 }
68  
69 # text types
70 else {
71 15 ▶ $self->{fuzzy_op} ||= 'ILIKE';
Condition50%1/2
$self->{"fuzzy_op"} ||= "ILIKE"
l!l
015
MC/DC0%0/1
$self->{"fuzzy_op"} ||= "ILIKE"
$self->{"fuzzy_op"}
Truth table50%1/2
A
A= $self->{"fuzzy_op"}
Aresult
11
00
72 15 ▶ $self->{fuzzy_not_op} ||= 'NOT ILIKE';
Condition50%1/2
$self->{"fuzzy_not_op"} ||= "NOT ILIKE"
l!l
015
MC/DC0%0/1
$self->{"fuzzy_not_op"} ||= "NOT ILIKE"
$self->{"fuzzy_not_op"}
Truth table50%1/2
A
A= $self->{"fuzzy_not_op"}
Aresult
11
00
73 15 $self->{is_int} = 0;
74 }
75  
76 }
77  
78 3 1;
« Query/Clause.pm ↑ Summary Query/Dialect.pm »