Branch Coverage

blib/lib/CGI/Ex/Validate.pm
Criterion Covered Total %
branch 380 656 57.9


line true false branch
20 199 27 ref $_[0] ? :
26 194 27 UNIVERSAL::isa($_[0], 'CGI::Ex::Validate') ? :
0 221 !ref($_[0]) ? :
31 0 221 unless $form and ref $form
32 2 219 if ref $form ne "HASH"
35 1 219 unless @$fields
37 4 215 if $ARGS->{'validate_if'} and not $self->check_conditional($form, $ARGS->{'validate_if'})
50 0 237 if (not ref $ref and $ref eq "OR")
51 0 0 if $found
60 9 228 if ($key =~ /^(!\s*|)m([^\s\w])(.*)\2([eigsmx]*)$/s) { }
63 0 9 if $opt =~ /e/
65 6 9 if $not and $_key =~ /(?$opt:$pat)/ or not $not || $_key =~ /(?$opt:$pat)/
74 237 0 unless ($checked{$field}++)
81 221 16 if ($ref->{'was_validated'}) { }
82 7 214 if $what_was_validated
88 104 133 if ($err) { }
91 0 104 if ($i < $#$fields and not ref $$fields[$i + 1] and $$fields[$i + 1] eq 'OR') { }
94 0 104 $hold_error ? :
102 0 215 if $hold_error
105 8 207 if ($ARGS->{'no_extra_fields'} or $self->{'no_extra_fields'})
108 8 4 if $keys{$key}
113 107 108 if (@errors)
116 0 107 if $ARGS->{'title'}
118 0 107 if $ARGS->{'raise_error'}
128 1 220 unless $val_hash
129 0 220 if (ref $val_hash ne "HASH")
130 0 0 if ref $val_hash ne "SCALAR" or not ref $val_hash
131 0 0 if ref $val_hash ne "HASH"
136 21 241 /^(?:group|general)\s+(\w+)/ ? :
141 1 219 if (my $ref = $ARGS{'fields'} || $ARGS{'order'})
142 0 1 $ARGS{'fields'} ? :
143 0 1 unless UNIVERSAL::isa($ref, "ARRAY")
145 0 1 unless defined $field
146 0 1 if (ref $field) { }
0 1 elsif ($field eq 'OR') { }
147 0 0 if ref $field ne "HASH"
148 0 0 unless defined $field->{'field'}
153 0 1 unless exists $val_hash->{$field}
154 0 1 if ref $val_hash->{$field} ne "HASH"
156 1 0 unless $val->{'field'}
162 1 0 ref $_ ? :
169 0 240 if ref $val_hash->{$field} ne "HASH"
170 0 240 if (defined $val_hash->{$field}{'field'}) { }
188 0 34 unless $ifs
189 34 0 if not ref $ifs or UNIVERSAL::isa($ifs, "HASH")
198 32 2 unless (ref $ref)
199 0 32 if ($ref eq 'OR') { }
200 0 0 if $found
204 0 32 if ($ref =~ /^function\s*\(/) { }
11 21 elsif ($ref =~ /^(.*?)\s+(was_valid|had_error|was_checked)$/) { }
2 19 elsif ($ref =~ s/^\s*!\s*//) { }
215 0 34 unless $found
219 7 0 defined $ifs_match->[$1] ? :
7 27 if $ifs_match
223 21 13 if $errs
233 0 271 if $self->{'_recurse'} > 10
236 0 271 if ($field_val->{'exclude_cgi'})
242 0 271 if ($field =~ /^(!\s*|)m([^\s\w])(.*)\2([eigsmx]*)$/s)
245 0 0 if $opt =~ /e/
247 0 0 if $not and $_field =~ /(?$opt:$pat)/ or not $not || $_field =~ /(?$opt:$pat)/
249 0 0 if $errs
251 0 0 @errors ? :
254 7 264 if ($field_val->{'was_valid'} and not $self->{'was_valid'}{$field})
255 3 261 if ($field_val->{'had_error'} and not $self->{'had_error'}{$field})
256 0 261 if ($field_val->{'was_checked'} and not $self->{'was_checked'}{$field})
260 1 0 if (defined $field_val->{'default'} and !defined($form->{$field}) || (UNIVERSAL::isa($form->{$field}, 'ARRAY') ? !@{$form->{$field};} : !length($form->{$field})))
266 11 250 UNIVERSAL::isa($form->{$field}, 'ARRAY') ? :
272 60 215 unless defined $value
273 215 0 unless ($field_val->{'do_not_trim'})
274 0 215 if $value =~ s/( ^\s+ | \s+$ )//gx
276 0 215 if ($field_val->{'trim_control_chars'})
277 0 0 if $value =~ tr/\t/ /
278 0 0 if $value =~ tr/\000-\037//d
280 0 215 if ($field_val->{'to_upper_case'}) { }
0 215 elsif ($field_val->{'to_lower_case'}) { }
291 176 635 if /^ (compare|custom|equals|match|max_in_set|min_in_set|replace|required_if|sql|type|validate_if) _?\d* $/x
295 6 255 if ($types{'replace'})
297 0 6 UNIVERSAL::isa($field_val->{$type}, 'ARRAY') ? :
299 0 6 unless ($rx =~ /^\s*s([^\s\w])(.+)\1(.*)\1([eigsmx]*)$/s)
303 0 6 if $opt =~ /e/
310 0 3 $2 > $#$start || $2 == 0 ? :
0 3 $1 ? :
318 1 5 unless defined $value
319 4 1 if ($global) { }
324 5 256 if $modified and $n_values == 1
329 24 237 if ($types{'validate_if'})
333 8 16 if $ret
335 16 245 if (not $needs_val and $n_vif)
342 54 191 $field_val->{'required'} ? :
343 191 54 unless ($is_required)
344 2 189 if ($types{'required_if'})
346 1 1 unless $self->check_conditional($form, $ifs, $ifs_match)
351 28 27 if ($is_required and $n_values == 0 || $n_values == 1 && !(defined $values->[0] && length $values->[0]))
353 10 18 if $self->{'_check_conditional'}
357 5 212 exists $field_val->{'min_values'} ? :
358 3 214 if ($n_values < $n)
359 0 3 if $self->{'_check_conditional'}
363 195 19 unless exists $field_val->{'max_values'}
365 2 212 if ($n_values > $n)
366 0 2 if $self->{'_check_conditional'}
375 0 14 unless $field_val->{$type} =~ /^\s*(\d+)(?i:\s*of)?\s+(.+)\s*$/
379 4 34 UNIVERSAL::isa($form->{$_field}, 'ARRAY') ? :
381 23 19 if defined $_value and length $_value
384 6 8 if ($minmax eq "min" and $n > 0 or $minmax eq "max" and $n < 0)
386 1 5 if $self->{'_check_conditional'}
397 10 204 if (exists $field_val->{'enum'})
398 5 5 ref $field_val->{'enum'} ? :
401 7 23 if defined $value and $_ eq $value
403 3 7 unless ($found)
404 0 3 if $self->{'_check_conditional'}
412 65 146 if (exists $field_val->{'type'})
413 35 30 unless ($self->check_type($value, $field_val->{'type'}, $field, $form))
414 0 35 if $self->{'_check_conditional'}
422 9 167 if ($types{'equals'})
424 0 9 $field2 =~ s/^!\s*// ? :
426 2 7 if ($field2 =~ /^([\"\'])(.*)\1$/) { }
430 2 0 defined $ifs_match->[$1] ? :
2 5 if $ifs_match
431 5 2 if (exists $form->{$field2} and defined $form->{$field2}) { }
1 1 elsif (not defined $value) { }
437 0 9 $not ? :
5 4 if ($not ? $success : !$success)
438 0 5 if $self->{'_check_conditional'}
445 4 167 if (exists $field_val->{'min_len'})
447 3 1 if (not defined $value or length $value < $n)
448 0 3 if $self->{'_check_conditional'}
453 17 154 if (exists $field_val->{'max_len'})
455 1 16 if (defined $value and length $value > $n)
456 0 1 if $self->{'_check_conditional'}
462 17 154 if ($types{'match'})
465 2 13 UNIVERSAL::isa($field_val->{$type}, 'Regexp') ? :
2 15 UNIVERSAL::isa($field_val->{$type}, 'ARRAY') ? :
467 6 15 if (UNIVERSAL::isa($rx, 'Regexp')) { }
468 2 4 unless (defined $value and $value =~ /$rx/)
472 0 15 unless ($rx =~ /^(!\s*|)m([^\s\w])(.*)\2([eigsmx]*)$/s)
477 0 15 if $opt =~ /e/
478 6 9 if ($not and (defined $value and $value =~ /(?$opt:$pat)/) or not $not || defined $value && $value =~ /(?$opt:$pat)/)
480 0 6 if $self->{'_check_conditional'}
489 30 141 if ($types{'compare'})
491 0 30 UNIVERSAL::isa($field_val->{$type}, 'ARRAY') ? :
493 0 30 unless $comp
495 15 15 if ($comp =~ /^\s*(>|<|[>
15 0 elsif ($comp =~ /^\s*(eq|ne|gt|ge|lt|le)\s+(.+?)\s*$/) { }
498 3 12 if ($1 eq '>') { }
3 9 elsif ($1 eq '<') { }
2 7 elsif ($1 eq '>=') { }
2 5 elsif ($1 eq '<=') { }
2 3 elsif ($1 eq '!=') { }
3 0 elsif ($1 eq '==') { }
506 12 3 defined $value ? :
509 3 12 if ($op eq 'gt') { }
3 9 elsif ($op eq 'lt') { }
2 7 elsif ($op eq 'ge') { }
2 5 elsif ($op eq 'le') { }
2 3 elsif ($op eq 'ne') { }
3 0 elsif ($op eq 'eq') { }
519 16 14 unless ($test)
520 0 16 if $self->{'_check_conditional'}
528 0 171 if ($types{'sql'})
530 0 0 $db_type ? :
531 0 0 if (not $dbh) { }
0 0 elsif (UNIVERSAL::isa($dbh, 'CODE')) { }
532 0 0 $db_type ? :
539 0 0 unless defined $$field_val{"${type}_error_if"}
540 0 0 if (not $return and $$field_val{"${type}_error_if"} or $return and not $$field_val{"${type}_error_if"})
542 0 0 if $self->{'_check_conditional'}
549 7 164 if ($types{'custom'})
552 3 4 if (UNIVERSAL::isa($check, 'CODE')) { }
554 1 2 unless eval { do { $ok = &$check($field, $value, $field_val, $type, $form); 1 } }
555 1 2 if $ok
556 1 1 if not ref $@ and defined $err
558 2 2 if $check
560 0 4 if $self->{'_check_conditional'}
561 1 3 defined $err ? :
569 2 204 if ($field_val->{'untaint'} and $#errors == -1)
570 1 1 if (not $content_checked) { }
574 1 0 /(.*)/ ? :
575 1 0 if ($n_values == 1)
582 76 130 @errors ? :
591 0 65 if ($type eq 'email') { }
0 65 elsif ($type eq 'local_part') { }
3 62 elsif ($type eq 'ip') { }
8 54 elsif ($type eq 'domain') { }
0 54 elsif ($type eq 'url') { }
0 54 elsif ($type eq 'uri') { }
19 35 elsif ($type eq 'int') { }
16 19 elsif ($type eq 'uint') { }
19 0 elsif ($type eq 'num') { }
0 0 elsif ($type eq 'cc') { }
592 0 0 unless $value
593 0 0 $value =~ /^(.+)\@(.+?)$/ ? :
594 0 0 if length $local_p > 60
595 0 0 if length $dom > 100
596 0 0 unless $self->check_type($dom, "domain") or $self->check_type($dom, "ip")
597 0 0 unless $self->check_type($local_p, "local_part")
601 0 0 unless defined $value and length $value
603 0 0 if $value =~ /[^\w.~!\#\$%\^&*\-=+?]/
607 0 3 unless $value
608 11 0 if not /\D/
612 0 8 if not $value or length $value > 255
613 4 4 if not $value =~ /^([a-z0-9][a-z0-9\-]{0,62} \.)+ [a-z]{1,63}$/xi or $value =~ /(\.\-|\-\.|\.\.)/
618 0 0 unless $value
619 0 0 unless $value =~ s[^https?://([^/]+)][]i
621 0 0 unless $self->check_type($dom, "domain") or $self->check_type($dom, "ip")
622 0 0 if $value and not $self->check_type($value, "uri")
626 0 0 unless $value
627 0 0 if $value =~ /\s+/
630 9 10 unless $value =~ /^-? (?: 0 | [1-9]\d*) $/x
631 4 6 $value < 0 ? :
2 8 if $value < 0 ? $value < "-2147483648" : $value > 2147483647
633 11 5 unless $value =~ /^ (?: 0 | [1-9]\d*) $/x
634 1 4 if $value > 4294967295
636 7 12 unless $value =~ /^-? (?: 0 | [1-9]\d* (?:\.\d+)? | 0?\.\d+) $/x
639 0 0 unless $value
640 0 0 if $value =~ /[^\d\-\ ]/
642 0 0 if length $value > 16 or length $value < 13
648 0 0 if ++$switch > 2
650 0 0 if $y > 9
653 0 0 if $sum % 10
672 0 0 if ($form)
673 0 0 unless ref $form
674 0 0 if ref $form ne "HASH"
678 0 0 unless @$fields
679 0 0 if $form and $ARGS->{'validate_if'} and not $self->check_conditional($form, $ARGS->{'validate_if'})
687 0 2 if $ENV{'HTTP_USER_AGENT'} and grep {$ENV{'HTTP_USER_AGENT'} =~ /$_/;} @UNSUPPORTED_BROWSERS
691 0 2 if (ref $val_hash ne "HASH")
692 0 0 if ref $val_hash ne "SCALAR" or not ref $val_hash
693 0 0 if ref $val_hash ne "HASH"
697 0 2 unless $_[0]
698 0 2 if (ref $_[0] eq 'HASH') { }
724 0 0 if ref $form_name eq "HASH"
727 0 0 unless $ARGS->{'form_args'}
0 0 unless $args
729 0 0 $args->{'no_inline_error'} || !$args->{'columns'} || $args->{'columns'} != 3 ? :
737 0 0 if $args->{'title'}
744 0 0 $args->{'no_inline_error'} ? :
0 0 $cols == 2 ? :
757 0 0 unless defined $args->{'css'}
759 0 0 $args->{'css'} ? :
764 0 0 $field->{'field'} =~ /^pass(?:|wd|word|\d+|_\w+)$/i ? :
0 0 $field->{'htype'} ? :
765 0 0 if ($type eq 'hidden') { }
0 0 elsif ($type eq 'textarea' or $field->{'rows'} or $field->{'cols'}) { }
0 0 elsif ($type eq 'radio' or $type eq 'checkbox') { }
0 0 elsif ($type eq 'select' or $field->{'enum'} or $field->{'label'}) { }
769 0 0 $field->{'rows'} ? :
770 0 0 $field->{'cols'} ? :
771 0 0 $field->{'wrap'} ? :
776 0 0 @$e > @$l ? :
780 0 0 defined $l->[$i] ? :
787 0 0 @$e > @$l ? :
789 0 0 defined $e->[$i] ? :
0 0 defined $l->[$i] ? :
794 0 0 $field->{'size'} ? :
795 0 0 $m ? :
807 0 0 $n % 2 ? :
811 0 0 if ($js)
829 0 107 if ref $errors ne "ARRAY"
830 0 107 if ref $extra ne "HASH"
842 97 22 defined $extra->{'as_string_join'} ? :
0 119 defined $extra2->{'as_string_join'} ? :
844 0 119 defined $extra->{'as_string_header'} ? :
0 119 defined $extra2->{'as_string_header'} ? :
846 0 119 defined $extra->{'as_string_footer'} ? :
0 119 defined $extra2->{'as_string_footer'} ? :
859 97 22 defined $extra->{'as_array_title'} ? :
0 119 defined $extra2->{'as_array_title'} ? :
863 22 97 if ($title) { }
867 98 0 if ref $_
875 22 97 $has_headings ? :
0 119 defined $extra->{'as_array_prefix'} ? :
0 119 defined $extra2->{'as_array_prefix'} ? :
879 22 97 if length $title
884 0 120 if (not ref $err) { }
889 0 120 if $found{$text}
905 0 2 defined $extra->{'as_hash_suffix'} ? :
4 2 defined $extra2->{'as_hash_suffix'} ? :
907 0 2 defined $extra->{'as_hash_join'} ? :
4 2 defined $extra2->{'as_hash_join'} ? :
912 0 6 unless ref $err
915 0 6 unless $field
916 0 6 if ($field_val->{'delegate_error'})
918 0 0 defined $ifs_match->[$1] ? :
0 0 if $ifs_match
922 0 6 if $found{$field}{$text}
929 6 0 if ($join)
931 0 6 defined $extra->{'as_hash_header'} ? :
0 6 defined $extra2->{'as_hash_header'} ? :
933 0 6 defined $extra->{'as_hash_footer'} ? :
0 6 defined $extra2->{'as_hash_footer'} ? :
948 2 124 if defined $custom_err and length $custom_err
949 0 124 $type =~ s/(_?\d+)$// ? :
953 0 124 if ($field_val->{'delegate_error'})
955 0 0 defined $ifs_match->[$1] ? :
0 0 if $ifs_match
960 8 116 if not $name and $field =~ /\W/ || $field =~ /\d/ && $field =~ /\D/
961 116 8 unless ($name)
966 0 0 defined $ifs_match->[$1] ? :
4 120 if $ifs_match
973 0 124 length $dig ? :
975 0 0 defined $ifs_match->[$1] ? :
0 12 if $ifs_match
978 12 0 if (my $value = $$field_val{"$type$dig"})
979 12 0 unless ref $value
985 112 12 unless ($return)
986 19 93 if ($type eq 'required' or $type eq 'required_if') { }
3 90 elsif ($type eq 'min_values') { }
2 88 elsif ($type eq 'max_values') { }
4 84 elsif ($type eq 'enum') { }
5 79 elsif ($type eq 'equals') { }
3 76 elsif ($type eq 'min_len') { }
1 75 elsif ($type eq 'max_len') { }
2 73 elsif ($type eq 'max_in_set') { }
3 70 elsif ($type eq 'min_in_set') { }
10 60 elsif ($type eq 'match') { }
16 44 elsif ($type eq 'compare') { }
0 44 elsif ($type eq 'sql') { }
3 41 elsif ($type eq 'custom') { }
36 5 elsif ($type eq 'type') { }
1 4 elsif ($type eq 'untaint') { }
4 0 elsif ($type eq 'no_extra_fields') { }
991 0 3 $n == 1 ? :
996 1 1 $n == 1 ? :
1005 1 0 defined $ifs_match->[$1] ? :
1 4 if $ifs_match
1010 0 3 $n == 1 ? :
1015 0 1 $n == 1 ? :
1050 0 124 unless $return