EntityModel/Query/Field.pm

filter: Statementstmt 64.8% 24 / 37 Branchbran 40.0% 8 / 20 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 4 / 5 Podpod 100% 3 / 3 totaltotal 48.2% 41 / 85 CC 15 SCAR 26.2
CC
15
Cov
49%
quotedValue
30.0
new
9.2
asString
8.8
CRAP 13.7
« EntityModel/EntityCollection.pm ↑ Summary EntityModel/Gather.pm »
1 package EntityModel::Query::Field;
2 {
3 39 $EntityModel::Query::Field::VERSION = '0.102';
4 }
5 39 ▶use EntityModel::Class {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 '_isa' => [qw(EntityModel::Query::Base)],
7 'field' => 'EntityModel::Field',
8 'name' => 'string',
9 'sql' => 'string',
10 'alias' => 'string',
11 39 };
12 39 ▶no if $] >= 5.017011, warnings => "experimental::smartmatch";
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 EntityModel::Query::Field - field wrapper
17  
18 =head1 VERSION
19  
20 version 0.102
21  
22 =head1 SYNOPSIS
23  
24 See L<Entitymodel::Query>.
25  
26 =head1 DESCRIPTION
27  
28 See L<Entitymodel::Query>.
29  
30 =cut
31  
32 =head1 METHODS
33  
34 =cut
35  
36 =head2 new
37  
38 =cut
39  
40 17 ▶sub new {
Subroutine new: called CC=7 SCAR=22.2
Pod documented
41 17 my $class = shift;
42 17 my $self = bless { }, $class;
43 17 ▶ if(ref $_[0] eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 4 13 17
elsif (ref $_[0] and $_[0]->isa('EntityModel::Field')) { } 0 13 13
elsif (@_ == 1 and not ref $_[0]) { } 13 0 13
44 4 my $spec = shift;
45 4 my ($k, $v) = %$spec;
46 4 $self->alias($k);
47 4 ▶ if(ref $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 4 0 4
48 4 $self->sql($$v);
49 } else {
50 0 $self->name($v);
51 }
52  
53 # foreach (qw{name field value alias}) {
54 # $self->$_($spec->{$_}) if exists $spec->{$_};
55 # }
56 ▶ } elsif(ref($_[0]) && $_[0]->isa('EntityModel::Field')) {
Condition33%1/3
ref $_[0] and $_[0]->isa("EntityModel::Field")
!ll&&!rl&&r
1300
MC/DC0%0/2
ref $_[0] and $_[0]->isa("EntityModel::Field")
ref $_[0] $_[0]->isa("EntityModel::Field")
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->isa("EntityModel::Field")
ABresult
0X0
100
111
57 0 my $spec = shift;
58 0 $self->field($spec);
59 # Handle plain value
60 ▶ } elsif(@_ == 1 && !ref $_[0]) {
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
0013
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
61 13 my $v = shift;
62 13 $self->name($v);
63 }
64  
65 17 return $self;
66 }
67  
68 =head2 quotedValue
69  
70 =cut
71  
72 0 ▶sub quotedValue {
Subroutine quotedValue: not called CC=5 SCAR=34.0
Pod documented
73 0 my $self = shift;
74 0 my $v = $self->value;
75 0 ▶ return 'null' unless defined $v && $v ne 'undef';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and $v ne "undef" 0 0 0
Condition0%0/3
defined $v and $v ne "undef"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and $v ne "undef"
defined $v $v ne "undef"
Truth table0%0/3
A and B
A= defined $vB= $v ne "undef"
ABresult
0X0
100
111
76 0 ▶ return $v if $self->field && $self->field->type ~~ [qw/int bigint serial bigserial numeric/];
Branch: 1 branch
BranchTrueFalseTotal
if $self->field and $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"] 0 0 0
Condition0%0/3
$self->field and $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
!ll&&!rl&&r
000
MC/DC0%0/2
$self->field and $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
$self->field $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
Truth table0%0/3
A and B
A= $self->fieldB= $self->field->type ~~ ["int", "bigint", "serial", "bigserial", "numeric"]
ABresult
0X0
100
111
77 0 $v =~ s/'/''/g;
78 0 $v =~ s!\\!\\\\!g;
79 0 return "E'$v'";
80 }
81  
82 =head2 asString
83  
84 =cut
85  
86 34 ▶sub asString {
Subroutine asString: called CC=5 SCAR=21.7
Pod documented
87 34 my $self = shift;
88 34 my $alias;
89 34 ▶ return $self->sql if exists $self->{sql};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"sql"} 8 26 34
90 26 ▶ return $self->name if exists $self->{name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"name"} 26 0 26
91 0 return $self->field->name;
92 0 ▶ $alias = $self->table->name if $self->table;
Branch: 1 branch
BranchTrueFalseTotal
if $self->table 0 0 0
93 0 ▶ return ($alias ? ($alias . '.') : '') . $self->name;
Branch: 1 branch
BranchTrueFalseTotal
$alias ? : 0 0 0
94 }
95  
96 39 1;
97  
98 __END__
« EntityModel/EntityCollection.pm ↑ Summary EntityModel/Gather.pm »