Branch Coverage

blib/lib/Respite/Validate.pm
Criterion Covered Total %
branch 365 560 65.1


line true false branch
15 251 3 @_ == 3 ? :
16 0 254 if ref $form ne "HASH"
18 0 254 unless @$fields
19 4 250 if $ARGS->{'validate_if'} and not $self->check_conditional($form, $ARGS->{'validate_if'})
30 0 268 if (not ref $ref and $ref eq "OR")
31 0 0 if $found
40 9 259 if ($key =~ /^(!\s*|)m([^\s\w])(.*)\2([eigsmx]*)$/s) { }
43 0 9 if $opt =~ /e/
45 6 9 if $not and $_key =~ /(?$opt:$pat)/ or not $not || $_key =~ /(?$opt:$pat)/
54 268 0 unless ($checked{$field}++)
61 17 251 unless ($ref->{'was_validated'})
66 114 154 if ($err) { }
69 0 114 if ($i < $fields->$#* and not ref $$fields[$i + 1] and $$fields[$i + 1] eq 'OR') { }
72 0 114 $hold_error ? :
80 0 250 if $hold_error
82 16 234 if $ARGS->{'no_extra_fields'} or $self->{'no_extra_fields'}
84 130 120 unless @errors
90 0 121 unless $field
91 0 121 if ($fv->{'delegate_error'})
93 0 0 defined $ifs_match->[$1] ? :
0 0 if $ifs_match
96 121 0 unless $uniq{$field}{$text}++
99 0 120 if $ARGS->{'raise_error'}
107 0 26 if $self->{'_recurse'} > 10
111 5 21 if (ref $form->{$key} eq 'HASH') { }
3 18 elsif (ref $form->{$key} eq 'ARRAY') { }
113 1 4 if (not defined $field_type) { }
0 4 elsif (ref $field_type ne 'HASH') { }
125 0 3 if (not defined $field_type) { }
2 1 elsif (ref $field_type eq 'HASH') { }
130 6 0 if ref $form->{$key}[$i]
134 19 7 if $keys{$key}
141 0 254 if not $val_hash or ref $val_hash ne "HASH"
143 29 272 /^group\s+(\w+)/ ? :
147 1 253 if (my $ref = $ARGS{'fields'} || $ARGS{'order'})
148 0 1 $ARGS{'fields'} ? :
149 0 1 if ref $ref ne "ARRAY"
151 0 1 unless defined $field
152 0 1 if (ref $field) { }
0 1 elsif ($field eq 'OR') { }
153 0 0 if ref $field ne "HASH"
154 0 0 unless defined $field->{'field'}
159 0 1 unless exists $val_hash->{$field}
160 0 1 if ref $val_hash->{$field} ne "HASH"
162 1 0 unless $val->{'field'}
168 1 0 ref $_ ? :
175 0 271 if ref $val_hash->{$field} ne "HASH"
176 0 271 if (defined $val_hash->{$field}{'field'}) { }
189 0 40 unless $ifs
190 40 0 if not ref $ifs or ref $ifs eq "HASH"
199 38 2 unless (ref $ref)
200 0 38 if ($ref eq 'OR') { }
201 0 0 if $found
205 0 38 if ($ref =~ /^function\s*\(/) { }
11 27 elsif ($ref =~ /^(.*?)\s+(was_valid|had_error|was_checked)$/) { }
2 25 elsif ($ref =~ s/^\s*!\s*//) { }
216 0 40 unless $found
220 7 0 defined $ifs_match->[$1] ? :
7 33 if $ifs_match
223 2 38 if ref $form->{$field} eq "ARRAY"
227 22 18 if $errs
238 0 335 if $self->{'_recurse'} > 10
241 0 335 if ($fv->{'exclude_cgi'})
247 0 335 if ($field =~ /^(!\s*|)m([^\s\w])(.*)\2([eigsmx]*)$/s)
250 0 0 if $opt =~ /e/
252 0 0 if $not and $_field =~ /(?$opt:$pat)/ or not $not || $_field =~ /(?$opt:$pat)/
254 0 0 if $errs
256 0 0 @errors ? :
261 1 334 if ($fv->{'canonical'})
267 7 328 if ($fv->{'was_valid'} and not $self->{'was_valid'}{$field})
268 3 325 if ($fv->{'had_error'} and not $self->{'had_error'}{$field})
269 0 325 if ($fv->{'was_checked'} and not $self->{'was_checked'}{$field})
271 2 69 if (not exists $form->{$field} and $fv->{'alias'})
272 0 2 ref $fv->{'alias'} ? :
273 1 1 unless exists $form->{$alias}
280 5 2 if (defined $fv->{'default'} and !defined($form->{$field}) || (ref $form->{$field} eq 'ARRAY' ? !@{$form->{$field};} : !length($form->{$field})))
285 25 300 ref $form->{$field} eq 'ARRAY' ? :
291 65 289 unless defined $value
292 289 0 unless ($fv->{'do_not_trim'})
293 0 289 if $value =~ s/( ^\s+ | \s+$ )//gx
295 0 289 if ($fv->{'trim_control_chars'})
296 0 0 if $value =~ tr/\t/ /
297 0 0 if $value =~ tr/\000-\037//d
299 0 289 if ($fv->{'to_upper_case'}) { }
0 289 elsif ($fv->{'to_lower_case'}) { }
310 229 758 if /^ (compare|custom|equals|match|max_in_set|min_in_set|replace|required_if|sql|type|validate_if) _?\d* $/x
314 5 320 if ($types{'replace'})
316 0 5 ref $fv->{$type} eq 'ARRAY' ? :
318 0 5 unless ($rx =~ /^\s*s([^\s\w])(.+)\1(.*)\1([eigsmx]*)$/s)
322 0 5 if $opt =~ /e/
329 0 3 $2 > $start->$#* || $2 == 0 ? :
0 3 if ($1) { }
337 0 5 unless defined $value
338 4 1 if ($global) { }
343 5 320 if $modified and $n_values == 1
348 30 295 if ($types{'validate_if'})
352 13 17 if $ret
354 17 308 if (not $needs_val and $n_vif)
361 59 249 $fv->{'required'} ? :
362 249 59 unless ($is_required)
363 2 247 if ($types{'required_if'})
365 1 1 unless $self->check_conditional($form, $ifs, $ifs_match)
370 24 36 if ($is_required and $n_values == 0 || $n_values == 1 && !(defined $values->[0] && length $values->[0]))
372 11 13 if $self->{'_check_conditional'}
376 5 279 exists $fv->{'min_values'} ? :
377 3 281 if ($n_values < $n)
378 0 3 if $self->{'_check_conditional'}
382 228 53 unless exists $fv->{'max_values'}
384 4 277 if ($n_values > $n)
385 0 4 if $self->{'_check_conditional'}
394 0 14 unless $fv->{$type} =~ /^\s*(\d+)(?i:\s*of)?\s+(.+)\s*$/
398 4 34 ref $form->{$_field} eq 'ARRAY' ? :
400 23 19 if defined $_value and length $_value
403 6 8 if ($minmax eq "min" and $n > 0 or $minmax eq "max" and $n < 0)
405 1 5 if $self->{'_check_conditional'}
416 10 270 if (exists $fv->{'enum'})
417 5 5 ref $fv->{'enum'} ? :
420 7 23 if defined $value and $_ eq $value
422 3 7 unless ($found)
423 0 3 if $self->{'_check_conditional'}
431 103 174 if (exists $fv->{'type'})
432 45 58 unless ($self->check_type($value, $fv->{'type'}, $field, $form))
433 0 45 if $self->{'_check_conditional'}
436 17 0 if (ref $fv->{'type'} eq "HASH" and $form->{$field})
439 8 9 ref $form->{$field} eq 'ARRAY' ? :
441 3 24 if $errs
444 3 14 @errors ? :
450 9 206 if ($types{'equals'})
452 0 9 $field2 =~ s/^!\s*// ? :
454 2 7 if ($field2 =~ /^([\"\'])(.*)\1$/) { }
457 2 0 defined $ifs_match->[$1] ? :
2 5 if $ifs_match
458 5 2 if (exists $form->{$field2} and defined $form->{$field2}) { }
1 1 elsif (not defined $value) { }
464 0 9 $not ? :
5 4 if ($not ? $success : !$success)
465 0 5 if $self->{'_check_conditional'}
472 4 206 if (exists $fv->{'min_len'})
474 3 1 if (not defined $value or length $value < $n)
475 0 3 if $self->{'_check_conditional'}
480 27 183 if (exists $fv->{'max_len'})
482 1 26 if (defined $value and length $value > $n)
483 0 1 if $self->{'_check_conditional'}
489 15 195 if ($types{'match'})
492 2 11 ref $fv->{$type} eq 'Regexp' ? :
2 13 ref $fv->{$type} eq 'ARRAY' ? :
494 6 13 if (ref $rx eq 'Regexp') { }
495 2 4 unless (defined $value and $value =~ /$rx/)
499 0 13 unless ($rx =~ /^(!\s*|)m([^\s\w])(.*)\2([eigsmx]*)$/s)
504 0 13 if $opt =~ /e/
505 6 7 if ($not and (defined $value and $value =~ /(?$opt:$pat)/) or not $not || defined $value && $value =~ /(?$opt:$pat)/)
507 0 6 if $self->{'_check_conditional'}
516 38 172 if ($types{'compare'})
517 0 38 ref $fv->{$type} eq 'ARRAY' ? :
519 0 38 unless $comp
521 19 19 if ($comp =~ /^\s*(>|<|[>
19 0 elsif ($comp =~ /^\s*(eq|ne|gt|ge|lt|le)\s+(field:(.+)|.+?)\s*$/) { }
523 4 15 if ($field2)
524 0 0 defined $ifs_match->[$1] ? :
0 4 if $ifs_match
525 2 2 exists $form->{$field2} ? :
529 3 16 if ($op eq '>') { }
3 13 elsif ($op eq '<') { }
2 11 elsif ($op eq '>=') { }
6 5 elsif ($op eq '<=') { }
2 3 elsif ($op eq '!=') { }
3 0 elsif ($op eq '==') { }
537 16 3 defined $value ? :
539 4 15 if ($field2) { }
540 0 0 defined $ifs_match->[$1] ? :
0 4 if $ifs_match
541 2 2 defined $form->{$field2} ? :
545 3 16 if ($op eq 'gt') { }
3 13 elsif ($op eq 'lt') { }
2 11 elsif ($op eq 'ge') { }
6 5 elsif ($op eq 'le') { }
2 3 elsif ($op eq 'ne') { }
3 0 elsif ($op eq 'eq') { }
555 20 18 unless ($test)
556 0 20 if $self->{'_check_conditional'}
564 0 210 if ($types{'sql'})
566 0 0 $db_type ? :
567 0 0 if (not $dbh) { }
0 0 elsif (ref $dbh eq 'CODE') { }
568 0 0 $db_type ? :
575 0 0 unless defined $$fv{"${type}_error_if"}
576 0 0 if (not $return and $$fv{"${type}_error_if"} or $return and not $$fv{"${type}_error_if"})
578 0 0 if $self->{'_check_conditional'}
585 7 203 if ($types{'custom'})
588 3 4 if (ref $check eq 'CODE') { }
590 1 2 unless eval { do { $ok = &$check($field, $value, $fv, $type, $form); 1 } }
591 1 2 if $ok
592 1 1 if not ref $@ and defined $err
594 2 2 if $check
596 0 4 if $self->{'_check_conditional'}
597 1 3 defined $err ? :
605 0 254 if ($fv->{'untaint'} and $#errors == -1)
606 0 0 if (not $content_checked) { }
610 0 0 /(.*)/ ? :
611 0 0 if ($n_values == 1)
617 89 165 @errors ? :
622 18 85 ref $type eq 'HASH' ? :
623 0 103 unless defined $value
624 0 103 if ($type eq 'email') { }
18 85 elsif ($type eq 'hash') { }
0 85 elsif ($type eq 'local_part') { }
3 82 elsif ($type eq 'ip') { }
9 73 elsif ($type eq 'domain') { }
0 73 elsif ($type eq 'url') { }
0 73 elsif ($type eq 'uri') { }
19 54 elsif ($type eq 'int') { }
17 37 elsif ($type eq 'uint') { }
19 18 elsif ($type eq 'num') { }
18 0 elsif ($type eq 'unum') { }
0 0 elsif ($type eq 'cc') { }
625 0 0 unless $value
626 0 0 $value =~ /^(.+)\@(.+?)$/ ? :
627 0 0 if length $local_p > 60
628 0 0 if length $dom > 100
629 0 0 unless $self->check_type($dom, "domain") or $self->check_type($dom, "ip")
630 0 0 unless $self->check_type($local_p, "local_part")
632 1 17 if ref $value ne "HASH"
634 0 0 unless length $value
636 0 0 if $value =~ /[^\w.~!\#\$%\^&*\-=+?]/
638 0 3 unless $value
639 11 0 if /^\d+$/
641 0 9 if not $value or length $value > 255
642 4 5 if not $value =~ /^(?:[a-z0-9][a-z0-9\-]{0,62} \.)+ [a-z0-9][a-z0-9\-]{0,62}$/xi or $value =~ /(?:\.\-|\-\.|\.\.)/
645 0 0 unless $value
646 0 0 unless $value =~ s[^https?://([^/]+)][]i
648 0 0 unless $self->check_type($dom, "domain") or $self->check_type($dom, "ip")
649 0 0 if $value and not $self->check_type($value, "uri")
651 0 0 unless $value
652 0 0 if $value =~ /\s+/
654 9 10 unless $value =~ /^-? (?: 0 | [1-9]\d*) $/x
655 4 6 $value < 0 ? :
2 8 if $value < 0 ? $value < "-2147483648" : $value > 2147483647
657 11 6 unless $value =~ /^ (?: 0 | [1-9]\d*) $/x
658 1 5 if $value > 4294967295
660 7 12 unless $value =~ /^-? (?: 0 | [1-9]\d* (?:\.\d+)? | 0?\.\d+) $/x
662 9 9 unless $value =~ /^ (?: 0 | [1-9]\d* (?:\.\d+)? | 0?\.\d+) $/x
664 0 0 unless $value
665 0 0 if $value =~ /[^\d\-\ ]/
667 0 0 if length $value > 16 or length $value < 13
672 0 0 if ++$switch > 2
674 0 0 if $y > 9
677 0 0 if $sum % 10
686 1 120 if defined $custom_err and length $custom_err
687 0 120 $type =~ s/(_?\d+)$// ? :
689 0 120 if $fv->{'delegate_error'}
691 0 0 defined $ifs_match->[$1] ? :
7 113 if ($ifs_match)
696 0 120 length $dig ? :
698 0 0 defined $ifs_match->[$1] ? :
0 0 if $ifs_match
701 0 0 if (my $value = $$fv{"$type$dig"})
702 0 0 unless ref $value
707 13 107 if ($type eq 'required' or $type eq 'required_if') { }
3 104 elsif ($type eq 'min_values') { }
4 100 elsif ($type eq 'max_values') { }
3 97 elsif ($type eq 'enum') { }
5 92 elsif ($type eq 'equals') { }
3 89 elsif ($type eq 'min_len') { }
1 88 elsif ($type eq 'max_len') { }
2 86 elsif ($type eq 'max_in_set') { }
3 83 elsif ($type eq 'min_in_set') { }
8 75 elsif ($type eq 'match') { }
20 55 elsif ($type eq 'compare') { }
0 55 elsif ($type eq 'sql') { }
3 52 elsif ($type eq 'custom') { }
45 7 elsif ($type eq 'type') { }
0 7 elsif ($type eq 'untaint') { }
7 0 elsif ($type eq 'no_extra_fields') { }
711 0 3 $n == 1 ? :
715 1 3 $n == 1 ? :
722 1 0 defined $ifs_match->[$1] ? :
1 4 if $ifs_match
726 0 3 $n == 1 ? :
730 0 1 $n == 1 ? :
748 1 44 if ref $_type eq "HASH"