Simple/Validator.pm

filter: Statementstmt 14.5% 33 / 227 Branchbran 0.0% 0 / 128 Conditioncond 0.0% 0 / 66 MC/DCmcdc 0.0% 0 / 39 Subroutinesub 27.0% 10 / 37 Podpod 0.0% 0 / 26 totaltotal 8.2% 43 / 523 CC 92 SCAR 38.6
CC
92
Cov
8%
DATETIME
182.0
DATE
90.0
BETWEEN
72.0
CRAP 47.5
« Simple/Messages.pm ↑ Summary Simple.pm »
1 package FormValidator::Simple::Validator;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use base qw/Class::Data::Inheritable/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use FormValidator::Simple::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use FormValidator::Simple::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Email::Valid;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Email::Valid::Loose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Date::Calc;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use List::MoreUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 11 __PACKAGE__->mk_classdata( options => { } );
15  
16 0 ▶sub SP {
Subroutine SP: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ($self, $params, $args) = @_;
18 0 my $data = $params->[0];
19 0 ▶ return $data =~ /\s/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /\s/ ? : 0 0 0
20 }
21  
22 11 *SPACE = \&SP;
23  
24 0 ▶sub INT {
Subroutine INT: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my ($self, $params, $args) = @_;
26 0 my $data = $params->[0];
27 0 ▶ return $data =~ /^\-?[\d]+$/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^\-?[\d]+$/ ? : 0 0 0
28 }
29  
30 0 ▶sub UINT {
Subroutine UINT: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my ($self, $params, $args) = @_;
32 0 my $data = $params->[0];
33 0 ▶ return $data =~ /^\d+$/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^\d+$/ ? : 0 0 0
34 }
35  
36 0 ▶sub ASCII {
Subroutine ASCII: not called CC=2 SCAR=17.9
Pod undocumented
37 0 my ($self, $params, $args) = @_;
38 0 my $data = $params->[0];
39 0 ▶ return $data =~ /^[\x21-\x7E]+$/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^[\x21-\x7E]+$/ ? : 0 0 0
40 }
41  
42 0 ▶sub DUPLICATION {
Subroutine DUPLICATION: not called CC=4 SCAR=30.0
Pod undocumented
43 0 my ($self, $params, $args) = @_;
44 0 my $data1 = $params->[0];
45 0 my $data2 = $params->[1];
46 0 ▶ unless (defined $data1 && defined $data2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data1 and defined $data2) 0 0 0
Condition0%0/3
defined $data1 and defined $data2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data1 and defined $data2
defined $data1 defined $data2
Truth table0%0/3
A and B
A= defined $data1B= defined $data2
ABresult
0X0
100
111
47 0 FormValidator::Simple::Exception->throw(
48 qq/validation "DUPLICATION" needs two keys of data./
49 );
50 }
51 0 ▶ return $data1 eq $data2 ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data1 eq $data2 ? : 0 0 0
52 }
53  
54 0 ▶sub LENGTH {
Subroutine LENGTH: not called CC=5 SCAR=34.0
Pod undocumented
55 0 my ($self, $params, $args) = @_;
56 0 ▶ unless ( scalar(@$args) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$args > 0) 0 0 0
57 0 FormValidator::Simple::Exception->throw(
58 qq/validation "LENGTH" needs one or two arguments./
59 );
60 }
61 0 my $data = $params->[0];
62 0 my $length = length $data;
63 0 my $min = $args->[0];
64 0 ▶ my $max = $args->[1] || $min;
Condition0%0/3
$args->[1] || $min
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->[1] || $min
$args->[1] $min
Truth table0%0/3
A || B
A= $args->[1]B= $min
ABresult
1X1
011
000
65 0 $min += 0;
66 0 $max += 0;
67 0 ▶ return $min <= $length && $length <= $max ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$min <= $length && $length <= $max ? : 0 0 0
Condition0%0/3
$min <= $length and $length <= $max
!ll&&!rl&&r
000
MC/DC0%0/2
$min <= $length and $length <= $max
$min <= $length $length <= $max
Truth table0%0/3
A and B
A= $min <= $lengthB= $length <= $max
ABresult
0X0
100
111
68 }
69  
70 0 ▶sub REGEX {
Subroutine REGEX: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my ($self, $params, $args) = @_;
72 0 my $data = $params->[0];
73 0 my $regex = $args->[0];
74 0 ▶ return $data =~ /$regex/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /$regex/ ? : 0 0 0
75 }
76  
77 0 ▶sub EMAIL {
Subroutine EMAIL: not called CC=3 SCAR=24.8
Pod undocumented
78 0 my ($self, $params, $args) = @_;
79 0 my $data = $params->[0];
80 0 ▶ return FALSE unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
81 0 ▶ return Email::Valid->address(-address => $data) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
'Email::Valid'->address('-address', $data) ? : 0 0 0
82 }
83  
84 0 ▶sub EMAIL_MX {
Subroutine EMAIL_MX: not called CC=3 SCAR=24.8
Pod undocumented
85 0 my ($self, $params, $args) = @_;
86 0 my $data = $params->[0];
87 0 ▶ return FALSE unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
88 0 ▶ return Email::Valid->address(-address => $data, -mxcheck => 1) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
'Email::Valid'->address('-address', $data, '-mxcheck', 1) ? : 0 0 0
89 }
90  
91 0 ▶sub EMAIL_LOOSE {
Subroutine EMAIL_LOOSE: not called CC=3 SCAR=24.8
Pod undocumented
92 0 my ($self, $params, $args) = @_;
93 0 my $data = $params->[0];
94 0 ▶ return FALSE unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
95 0 ▶ return Email::Valid::Loose->address($data) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
'Email::Valid::Loose'->address($data) ? : 0 0 0
96 }
97  
98 0 ▶sub EMAIL_LOOSE_MX {
Subroutine EMAIL_LOOSE_MX: not called CC=3 SCAR=24.8
Pod undocumented
99 0 my ($self, $params, $args) = @_;
100 0 my $data = $params->[0];
101 0 ▶ return FALSE unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
102 0 ▶ return Email::Valid::Loose->address(-address => $data, -mxcheck => 1) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
'Email::Valid::Loose'->address('-address', $data, '-mxcheck', 1) ? : 0 0 0
103 }
104  
105 0 ▶sub DATE {
Subroutine DATE: not called CC=9 SCAR=45.0
Pod undocumented
106 0 my ($self, $params, $args) = @_;
107 0 my ($year, $month, $day ) = @$params;
108 0 ▶ my $result = Date::Calc::check_date($year, $month, $day) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
Date::Calc::check_date($year, $month, $day) ? : 0 0 0
109 0 my $data;
110 0 ▶ if ($result) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) 0 0 0
111 0 ▶ my $class = $self->options->{datetime_class} || '';
Condition0%0/2
$self->options->{'datetime_class'} || ''
l!l
00
MC/DC0%0/1
$self->options->{'datetime_class'} || ''
$self->options->{'datetime_class'}
Truth table0%0/2
A
A= $self->options->{'datetime_class'}
Aresult
11
00
112 0 ▶ if ($class eq 'DateTime') {
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq 'DateTime') { } 0 0 0
elsif ($class eq 'Time::Piece') { } 0 0 0
113 0 $class->require;
114 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
115 0 FormValidator::Simple::Exception->throw(
116 qq/Validation DATE: failed to require $class. "$@"./
117 );
118 }
119 0 my %date = (
120 year => $year,
121 month => $month,
122 day => $day,
123 );
124 0 ▶ if ($self->options->{time_zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{"time_zone"}) 0 0 0
125 0 $date{time_zone} = $self->options->{time_zone};
126 }
127 0 $data = $class->new(%date);
128 }
129 elsif ($class eq 'Time::Piece') {
130 0 $data = sprintf "%04d-%02d-%02d 00:00:00", $year, $month, $day;
131 0 $class->require;
132 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
133 0 FormValidator::Simple::Exception->throw(
134 qq/Validation DATE: failed to require $class. "$@"./
135 );
136 }
137 0 $data = $class->strptime($data, "%Y-%m-%d %H:%M:%S");
138 }
139 else {
140 0 $data = sprintf "%04d-%02d-%02d 00:00:00", $year, $month, $day;
141 }
142 }
143 0 return ($result, $data);
144 }
145  
146 0 ▶sub TIME {
Subroutine TIME: not called CC=6 SCAR=37.4
Pod undocumented
147 0 my ($self, $params, $args) = @_;
148 0 my ($hour, $min, $sec ) = @$params;
149 0 ▶ $hour ||= 0;
Condition0%0/2
$hour ||= 0
l!l
00
MC/DC0%0/1
$hour ||= 0
$hour
Truth table0%0/2
A
A= $hour
Aresult
11
00
150 0 ▶ $min ||= 0;
Condition0%0/2
$min ||= 0
l!l
00
MC/DC0%0/1
$min ||= 0
$min
Truth table0%0/2
A
A= $min
Aresult
11
00
151 0 ▶ $sec ||= 0;
Condition0%0/2
$sec ||= 0
l!l
00
MC/DC0%0/1
$sec ||= 0
$sec
Truth table0%0/2
A
A= $sec
Aresult
11
00
152 0 ▶ my $result = Date::Calc::check_time($hour, $min, $sec) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
Date::Calc::check_time($hour, $min, $sec) ? : 0 0 0
153 0 ▶ my $time = $result ? sprintf("%02d:%02d:%02d", $hour, $min, $sec) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$result ? : 0 0 0
154 0 return ($result, $time);
155 }
156  
157 0 ▶sub DATETIME {
Subroutine DATETIME: not called CC=13 SCAR=52.0
Pod undocumented
158 0 my ($self, $params, $args) = @_;
159 0 my ($year, $month, $day, $hour, $min, $sec) = @$params;
160 0 ▶ $hour ||= 0;
Condition0%0/2
$hour ||= 0
l!l
00
MC/DC0%0/1
$hour ||= 0
$hour
Truth table0%0/2
A
A= $hour
Aresult
11
00
161 0 ▶ $min ||= 0;
Condition0%0/2
$min ||= 0
l!l
00
MC/DC0%0/1
$min ||= 0
$min
Truth table0%0/2
A
A= $min
Aresult
11
00
162 0 ▶ $sec ||= 0;
Condition0%0/2
$sec ||= 0
l!l
00
MC/DC0%0/1
$sec ||= 0
$sec
Truth table0%0/2
A
A= $sec
Aresult
11
00
163 0 ▶ my $result = Date::Calc::check_date($year, $month, $day)
Branch: 1 branch
BranchTrueFalseTotal
Date::Calc::check_date($year, $month, $day) && Date::Calc::check_time($hour, $min, $sec) ? : 0 0 0
Condition0%0/3
Date::Calc::check_date($year, $month, $day) and Date::Calc::check_time($hour, $min, $sec)
!ll&&!rl&&r
000
MC/DC0%0/2
Date::Calc::check_date($year, $month, $day) and Date::Calc::check_time($hour, $min, $sec)
Date::Calc::check_date($year, $month, $day) Date::Calc::check_time($hour, $min, $sec)
Truth table0%0/3
A and B
A= Date::Calc::check_date($year, $month, $day)B= Date::Calc::check_time($hour, $min, $sec)
ABresult
0X0
100
111
164 && Date::Calc::check_time($hour, $min, $sec) ? TRUE : FALSE;
165 0 my $data;
166 0 ▶ if ($result) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) 0 0 0
167 0 ▶ my $class = $self->options->{datetime_class} || '';
Condition0%0/2
$self->options->{'datetime_class'} || ''
l!l
00
MC/DC0%0/1
$self->options->{'datetime_class'} || ''
$self->options->{'datetime_class'}
Truth table0%0/2
A
A= $self->options->{'datetime_class'}
Aresult
11
00
168 0 ▶ if ($class eq 'DateTime') {
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq 'DateTime') { } 0 0 0
elsif ($class eq 'Time::Piece') { } 0 0 0
169 0 $class->require;
170 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
171 0 FormValidator::Simple::Exception->throw(
172 qq/Validation DATETIME: failed to require $class. "$@"./
173 );
174 }
175 0 my %date = (
176 year => $year,
177 month => $month,
178 day => $day,
179 hour => $hour,
180 minute => $min,
181 second => $sec,
182 );
183 0 ▶ if ($self->options->{time_zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{"time_zone"}) 0 0 0
184 0 $date{time_zone} = $self->options->{time_zone};
185 }
186 0 $data = $class->new(%date);
187 }
188 elsif ($class eq 'Time::Piece') {
189 0 $data = sprintf "%04d-%02d-%02d %02d:%02d:%02d",
190 $year, $month, $day, $hour, $min, $sec;
191 0 $class->require;
192 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
193 0 FormValidator::Simple::Exception->throw(
194 qq/Validation DATETIME: failed to require $class. "$@"./
195 );
196 }
197 0 $data = $class->strptime($data, "%Y-%m-%d %H:%M:%S");
198 }
199 else {
200 0 $data = sprintf "%04d-%02d-%02d %02d:%02d:%02d",
201 $year, $month, $day, $hour, $min, $sec;
202 }
203 }
204 0 return ($result, $data);
205 }
206  
207 0 ▶sub ANY {
Subroutine ANY: not called CC=4 SCAR=30.0
Pod undocumented
208 0 my ($self, $params, $args) = @_;
209 0 foreach my $param ( @$params ) {
210 0 ▶ return TRUE if ( defined $param && $param ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $param and $param ne "" 0 0 0
Condition0%0/3
defined $param and $param ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $param and $param ne ""
defined $param $param ne ""
Truth table0%0/3
A and B
A= defined $paramB= $param ne ""
ABresult
0X0
100
111
211 }
212 0 return FALSE;
213 }
214  
215 0 ▶sub HTTP_URL {
Subroutine HTTP_URL: not called CC=2 SCAR=17.9
Pod undocumented
216 0 my ($self, $params, $args) = @_;
217 0 my $data = $params->[0];
218 0 ▶ return $data =~ /^s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+$/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ m[^s?https?://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$] ? : 0 0 0
219 }
220  
221 0 ▶sub SELECTED_AT_LEAST {
Subroutine SELECTED_AT_LEAST: not called CC=3 SCAR=24.8
Pod undocumented
222 0 my ($self, $params, $args) = @_;
223 0 my $data = $params->[0];
224 0 ▶ my $selected = ref $data ? $data : [$data];
Branch: 1 branch
BranchTrueFalseTotal
ref $data ? : 0 0 0
225 0 my $num = $args->[0] + 0;
226 0 ▶ return scalar(@$selected) >= $num ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$selected >= $num ? : 0 0 0
227 }
228  
229 0 ▶sub GREATER_THAN {
Subroutine GREATER_THAN: not called CC=5 SCAR=34.0
Pod undocumented
230 0 my ($self, $params, $args) = @_;
231 0 my $data = $params->[0];
232 0 my $target = $args->[0];
233 0 my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/;
234 0 ▶ unless ( defined $target && $target =~ /$regex/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target and $target =~ /$regex/) 0 0 0
Condition0%0/3
defined $target and $target =~ /$regex/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $target and $target =~ /$regex/
defined $target $target =~ /$regex/
Truth table0%0/3
A and B
A= defined $targetB= $target =~ /$regex/
ABresult
0X0
100
111
235 0 FormValidator::Simple::Exception->throw(
236 qq/Validation GREATER_THAN needs a numeric argument./
237 );
238 }
239 0 ▶ return FALSE unless $data =~ /$regex/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /$regex/ 0 0 0
240 0 ▶ return ( $data > $target ) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data > $target ? : 0 0 0
241 }
242  
243 0 ▶sub LESS_THAN {
Subroutine LESS_THAN: not called CC=5 SCAR=34.0
Pod undocumented
244 0 my ($self, $params, $args) = @_;
245 0 my $data = $params->[0];
246 0 my $target = $args->[0];
247 0 my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/;
248 0 ▶ unless ( defined $target && $target =~ /$regex/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target and $target =~ /$regex/) 0 0 0
Condition0%0/3
defined $target and $target =~ /$regex/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $target and $target =~ /$regex/
defined $target $target =~ /$regex/
Truth table0%0/3
A and B
A= defined $targetB= $target =~ /$regex/
ABresult
0X0
100
111
249 0 FormValidator::Simple::Exception->throw(
250 qq/Validation LESS_THAN needs a numeric argument./
251 );
252 }
253 0 ▶ return FALSE unless $data =~ /$regex/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /$regex/ 0 0 0
254 0 ▶ return ( $data < $target ) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data < $target ? : 0 0 0
255 }
256  
257 0 ▶sub EQUAL_TO {
Subroutine EQUAL_TO: not called CC=5 SCAR=34.0
Pod undocumented
258 0 my ($self, $params, $args) = @_;
259 0 my $data = $params->[0];
260 0 my $target = $args->[0];
261 0 my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/;
262 0 ▶ unless ( defined $target && $target =~ /$regex/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target and $target =~ /$regex/) 0 0 0
Condition0%0/3
defined $target and $target =~ /$regex/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $target and $target =~ /$regex/
defined $target $target =~ /$regex/
Truth table0%0/3
A and B
A= defined $targetB= $target =~ /$regex/
ABresult
0X0
100
111
263 0 FormValidator::Simple::Exception->throw(
264 qq/Validation EQUAL_TO needs a numeric argument./
265 );
266 }
267 0 ▶ return FALSE unless $data =~ /$regex/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /$regex/ 0 0 0
268 0 ▶ return ( $data == $target ) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data == $target ? : 0 0 0
269 }
270  
271 0 ▶sub BETWEEN {
Subroutine BETWEEN: not called CC=8 SCAR=42.8
Pod undocumented
272 0 my ($self, $params, $args) = @_;
273 0 my $data = $params->[0];
274 0 my $start = $args->[0];
275 0 my $end = $args->[1];
276 0 my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/;
277 0 ▶ unless ( defined($start) && $start =~ /$regex/ && defined($end) && $end =~ /$regex/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $start and $start =~ /$regex/ and defined $end and $end =~ /$regex/) 0 0 0
Condition0%0/9
defined $start and $start =~ /$regex/ and defined $end and $end =~ /$regex/
!ll&&!rl&&r
000
defined $start and $start =~ /$regex/ and defined $end
!ll&&!rl&&r
000
defined $start and $start =~ /$regex/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $start and $start =~ /$regex/ and defined $end and $end =~ /$regex/
defined $start $start =~ /$regex/ defined $end $end =~ /$regex/
Truth table0%0/5
A and B and C and D
A= defined $startB= $start =~ /$regex/C= defined $endD= $end =~ /$regex/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
278 0 FormValidator::Simple::Exception->throw(
279 qq/Validation BETWEEN needs two numeric arguments./
280 );
281 }
282 0 ▶ return FALSE unless $data =~ /$regex/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /$regex/ 0 0 0
283 0 ▶ return ( $data >= $start && $data <= $end ) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data >= $start && $data <= $end ? : 0 0 0
Condition0%0/3
$data >= $start and $data <= $end
!ll&&!rl&&r
000
MC/DC0%0/2
$data >= $start and $data <= $end
$data >= $start $data <= $end
Truth table0%0/3
A and B
A= $data >= $startB= $data <= $end
ABresult
0X0
100
111
284 }
285  
286 0 ▶sub DECIMAL {
Subroutine DECIMAL: not called CC=7 SCAR=40.3
Pod undocumented
287 0 my ($self, $params, $args) = @_;
288 0 my $data = $params->[0];
289 0 ▶ unless ( scalar(@$args) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$args > 0) 0 0 0
290 0 FormValidator::Simple::Exception->throw(
291 qq/Validation DECIMAL needs one or two numeric arguments./
292 );
293 }
294 0 my $digit1 = $args->[0];
295 0 ▶ my $digit2 = $args->[1] || 0;
Condition0%0/2
$args->[1] || 0
l!l
00
MC/DC0%0/1
$args->[1] || 0
$args->[1]
Truth table0%0/2
A
A= $args->[1]
Aresult
11
00
296 0 ▶ unless ( $digit1 =~ /^\d+$/ && $digit2 =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($digit1 =~ /^\d+$/ and $digit2 =~ /^\d+$/) 0 0 0
Condition0%0/3
$digit1 =~ /^\d+$/ and $digit2 =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$digit1 =~ /^\d+$/ and $digit2 =~ /^\d+$/
$digit1 =~ /^\d+$/ $digit2 =~ /^\d+$/
Truth table0%0/3
A and B
A= $digit1 =~ /^\d+$/B= $digit2 =~ /^\d+$/
ABresult
0X0
100
111
297 0 FormValidator::Simple::Exception->throw(
298 qq/Validation DECIMAL needs one or two numeric arguments./
299 );
300 }
301 0 ▶ return FALSE unless $data =~ /^\d+(\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /^\d+(\.\d+)?$/ 0 0 0
302 0 my $reg = qr/^\d{1,$digit1}(\.\d{0,$digit2})?$/;
303 0 ▶ return $data =~ /$reg/ ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /$reg/ ? : 0 0 0
304 }
305  
306 0 ▶sub ALL {
Subroutine ALL: not called CC=4 SCAR=30.0
Pod undocumented
307 0 my ($self, $params, $args) = @_;
308 0 foreach my $param ( @$params ) {
309 0 ▶ unless ( defined $param && $param ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $param and $param ne "") 0 0 0
Condition0%0/3
defined $param and $param ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $param and $param ne ""
defined $param $param ne ""
Truth table0%0/3
A and B
A= defined $paramB= $param ne ""
ABresult
0X0
100
111
310 0 return FALSE;
311 }
312 }
313 0 return TRUE;
314 }
315  
316 0 ▶sub IN_ARRAY {
Subroutine IN_ARRAY: not called CC=3 SCAR=24.8
Pod undocumented
317 0 my ($class, $params, $args) = @_;
318 0 ▶ my $data = defined $params->[0] ? $params->[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $params->[0] ? : 0 0 0
319 0 ▶ return (List::MoreUtils::any { $_ eq $data } @$args) ? TRUE : FALSE;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&List::MoreUtils::any(sub { $_ eq $data; } , @$args) ? : 0 0 0
320 }
321  
322 0 ▶sub DATETIME_FORMAT {
Subroutine DATETIME_FORMAT: not called CC=7 SCAR=40.3
Pod undocumented
323 0 my ( $self, $params, $args ) = @_;
324 0 my $date = $params->[0];
325 0 my $format = $args->[0];
326 0 ▶ FormValidator::Simple::Exception->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $format 0 0 0
327 qq/Validation DATETIME_FORMAT needs a format argument./)
328 unless $format;
329  
330 0 my $module;
331 0 ▶ if ( ref $format ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $format) { } 0 0 0
332 0 $module = $format;
333 }
334 else {
335 0 $module = "DateTime::Format::$format";
336 0 ▶ $module->require
Branch: 1 branch
BranchTrueFalseTotal
$module->require or "FormValidator::Simple::Exception"->throw(qq[Validation DATETIME_FORMAT: failed to require $module. "$@"]) 0 0 0
337 or FormValidator::Simple::Exception->throw(
338 qq/Validation DATETIME_FORMAT: failed to require $module. "$@"/ );
339 }
340 0 my $dt;
341 0 eval {
342 0 $dt = $module->parse_datetime($date);
343 };
344 0 ▶ my $result = $dt ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$dt ? : 0 0 0
345  
346 0 ▶ if ( $dt && $self->options->{time_zone} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt and $self->options->{"time_zone"}) 0 0 0
Condition0%0/3
$dt and $self->options->{"time_zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
$dt and $self->options->{"time_zone"}
$dt $self->options->{"time_zone"}
Truth table0%0/3
A and B
A= $dtB= $self->options->{"time_zone"}
ABresult
0X0
100
111
347 0 $dt->set_time_zone( $self->options->{time_zone} );
348 }
349 0 return ($result, $dt);
350 }
351  
352 0 ▶sub DATETIME_STRPTIME {
Subroutine DATETIME_STRPTIME: not called CC=5 SCAR=34.0
Pod undocumented
353 0 my ( $self, $params, $args ) = @_;
354 0 my $date = $params->[0];
355 0 my $format = $args->[0];
356 0 ▶ FormValidator::Simple::Exception->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $format 0 0 0
357 qq/Validation DATETIME_STRPTIME needs a format argument./)
358 unless $format;
359  
360 0 my $dt;
361 0 eval{
362 0 my $strp = DateTime::Format::Strptime->new(
363 pattern => $format,
364 on_error => 'croak'
365 );
366 0 $dt = $strp->parse_datetime($date);
367 };
368  
369 0 ▶ my $result = $dt ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$dt ? : 0 0 0
370  
371 0 ▶ if ( $dt && $self->options->{time_zone} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt and $self->options->{"time_zone"}) 0 0 0
Condition0%0/3
$dt and $self->options->{"time_zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
$dt and $self->options->{"time_zone"}
$dt $self->options->{"time_zone"}
Truth table0%0/3
A and B
A= $dtB= $self->options->{"time_zone"}
ABresult
0X0
100
111
372 0 $dt->set_time_zone( $self->options->{time_zone} );
373 }
374 0 return ($result, $dt);
375 }
376  
377 11 1;
378 __END__
« Simple/Messages.pm ↑ Summary Simple.pm »