line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EntityModel::Query::Field; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$EntityModel::Query::Field::VERSION = '0.102'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
use EntityModel::Class { |
6
|
16
|
|
|
|
|
185
|
'_isa' => [qw(EntityModel::Query::Base)], |
7
|
|
|
|
|
|
|
'field' => 'EntityModel::Field', |
8
|
|
|
|
|
|
|
'name' => 'string', |
9
|
|
|
|
|
|
|
'sql' => 'string', |
10
|
|
|
|
|
|
|
'alias' => 'string', |
11
|
16
|
|
|
16
|
|
12181
|
}; |
|
16
|
|
|
|
|
40
|
|
12
|
16
|
|
|
16
|
|
10645
|
no if $] >= 5.017011, warnings => "experimental::smartmatch"; |
|
16
|
|
|
|
|
61
|
|
|
16
|
|
|
|
|
131
|
|
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. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
See L. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 new |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
17
|
|
|
17
|
1
|
1811
|
my $class = shift; |
42
|
17
|
|
|
|
|
48
|
my $self = bless { }, $class; |
43
|
17
|
100
|
33
|
|
|
113
|
if(ref $_[0] eq 'HASH') { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
44
|
4
|
|
|
|
|
5
|
my $spec = shift; |
45
|
4
|
|
|
|
|
12
|
my ($k, $v) = %$spec; |
46
|
4
|
|
|
|
|
13
|
$self->alias($k); |
47
|
4
|
50
|
|
|
|
40
|
if(ref $v) { |
48
|
4
|
|
|
|
|
16
|
$self->sql($$v); |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
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')) { |
57
|
0
|
|
|
|
|
0
|
my $spec = shift; |
58
|
0
|
|
|
|
|
0
|
$self->field($spec); |
59
|
|
|
|
|
|
|
# Handle plain value |
60
|
|
|
|
|
|
|
} elsif(@_ == 1 && !ref $_[0]) { |
61
|
13
|
|
|
|
|
18
|
my $v = shift; |
62
|
13
|
|
|
|
|
53
|
$self->name($v); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
17
|
|
|
|
|
213
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 quotedValue |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub quotedValue { |
73
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
74
|
0
|
|
|
|
|
0
|
my $v = $self->value; |
75
|
0
|
0
|
0
|
|
|
0
|
return 'null' unless defined $v && $v ne 'undef'; |
76
|
0
|
0
|
0
|
|
|
0
|
return $v if $self->field && $self->field->type ~~ [qw/int bigint serial bigserial numeric/]; |
77
|
0
|
|
|
|
|
0
|
$v =~ s/'/''/g; |
78
|
0
|
|
|
|
|
0
|
$v =~ s!\\!\\\\!g; |
79
|
0
|
|
|
|
|
0
|
return "E'$v'"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 asString |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub asString { |
87
|
34
|
|
|
34
|
1
|
71
|
my $self = shift; |
88
|
34
|
|
|
|
|
31
|
my $alias; |
89
|
34
|
100
|
|
|
|
100
|
return $self->sql if exists $self->{sql}; |
90
|
26
|
50
|
|
|
|
668
|
return $self->name if exists $self->{name}; |
91
|
0
|
|
|
|
|
|
return $self->field->name; |
92
|
0
|
0
|
|
|
|
|
$alias = $self->table->name if $self->table; |
93
|
0
|
0
|
|
|
|
|
return ($alias ? ($alias . '.') : '') . $self->name; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |