line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::DBI::Filter::Boolean; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
74
|
|
4
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
328
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
11
|
use base 'Jifty::DBI::Filter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
393
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
8
|
use constant TRUE_VALUES => qw(1 t true y yes TRUE); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
119
|
|
9
|
1
|
|
|
1
|
|
8
|
use constant FALSE_VALUES => ('', qw(0 f false n no FALSE)); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
114
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _is_true { |
12
|
151
|
|
|
151
|
|
252
|
my $self = shift; |
13
|
151
|
|
|
|
|
243
|
my $value = shift; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
883
|
|
16
|
|
|
|
|
|
|
|
17
|
151
|
|
|
|
|
763
|
for ($self->TRUE_VALUES, map { "'$_'" } $self->TRUE_VALUES) { |
|
906
|
|
|
|
|
2343
|
|
18
|
1072
|
100
|
|
|
|
2815
|
return 1 if $value eq $_; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
77
|
|
|
|
|
450
|
return 0; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _is_false { |
25
|
77
|
|
|
77
|
|
227
|
my $self = shift; |
26
|
77
|
|
|
|
|
120
|
my $value = shift; |
27
|
|
|
|
|
|
|
|
28
|
77
|
100
|
|
|
|
477
|
return 1 if not defined $value; |
29
|
|
|
|
|
|
|
|
30
|
76
|
|
|
|
|
308
|
for ($self->FALSE_VALUES, map { "'$_'" } $self->FALSE_VALUES) { |
|
532
|
|
|
|
|
1082
|
|
31
|
244
|
100
|
|
|
|
729
|
return 1 if $value eq $_; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
return 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Jifty::DBI::Filter::Boolean - Encodes booleans |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 decode |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Transform the value into 1 or 0 so Perl's concept of the value agrees |
46
|
|
|
|
|
|
|
with the database's concept of the value. (For example, 't' and 'f' |
47
|
|
|
|
|
|
|
might be used in the database, but 'f' is true in Perl) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub decode { |
52
|
56
|
|
|
56
|
1
|
90
|
my $self = shift; |
53
|
56
|
|
|
|
|
521
|
my $value_ref = $self->value_ref; |
54
|
|
|
|
|
|
|
|
55
|
56
|
100
|
|
|
|
451
|
return unless defined $$value_ref; |
56
|
|
|
|
|
|
|
|
57
|
43
|
100
|
|
|
|
157
|
if ($self->_is_true($$value_ref)) { |
|
|
50
|
|
|
|
|
|
58
|
21
|
|
|
|
|
116
|
$$value_ref = 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ($self->_is_false($$value_ref)) { |
61
|
22
|
|
|
|
|
155
|
$$value_ref = 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
0
|
$self->handle->log("The value '$$value_ref' does not look like a boolean. Defaulting to false."); |
65
|
0
|
|
|
|
|
0
|
$$value_ref = 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 encode |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Transform the value to the canonical true or false value as expected by the |
72
|
|
|
|
|
|
|
database. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub encode { |
77
|
122
|
|
|
122
|
1
|
431
|
my $self = shift; |
78
|
122
|
|
|
|
|
380
|
my $value_ref = $self->value_ref; |
79
|
|
|
|
|
|
|
|
80
|
122
|
100
|
100
|
|
|
965
|
return unless defined($$value_ref) or $self->column->mandatory; |
81
|
108
|
50
|
100
|
|
|
579
|
return if uc($$value_ref||'') eq "NULL" and not $self->column->mandatory; |
|
|
|
33
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
108
|
100
|
|
|
|
273
|
if ($self->_is_true($$value_ref)) { |
|
|
50
|
|
|
|
|
|
84
|
53
|
|
|
|
|
172
|
$$value_ref = $self->handle->canonical_true; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ($self->_is_false($$value_ref)) { |
87
|
55
|
|
|
|
|
175
|
$$value_ref = $self->handle->canonical_false; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
0
|
|
|
|
|
|
$self->handle->log("The value '$$value_ref' does not look like a boolean. Defaulting to false."); |
91
|
0
|
|
|
|
|
|
$$value_ref = $self->handle->canonical_false; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |