blib/lib/FormValidator/Lite/Constraint/Default.pm

filter: Statementstmt 100% 73 / 73 Branchbran 73.6% 28 / 38 Conditioncond 66.6% 10 / 15 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 86.1% 131 / 152 SCAR 33.4
CC
27
Cov
88%
__ANON__
6.0
__ANON__
5.2
__ANON__
5.0
CRAP 28.2
« blib/lib/FormValidator/Lite.pm ↑ Summary blib/lib/FormValidator/Lite/Constraint/Time.pm »
1 package FormValidator::Lite::Constraint::Default;
2 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use FormValidator::Lite::Constraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 rule 'NOT_NULL' => sub {
7 38 ▶ return 0 if not defined($_);
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 10 28 38
8 28 ▶ return 0 if $_ eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 3 25 28
9 25 ▶ return 0 if ref($_)eq'ARRAY' && @$_ == 0;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ eq "ARRAY" and @$_ == 0 4 21 25
Condition66%2/3
ref $_ eq "ARRAY" and @$_ == 0
!ll&&!rl&&r
2104
MC/DC50%1/2
ref $_ eq "ARRAY" and @$_ == 0
ref $_ eq "ARRAY" @$_ == 0
Truth table66%2/3
A and B
A= ref $_ eq "ARRAY"B= @$_ == 0
ABresult
0X0
100
111
10 21 return 1;
11 30 };
12 17 ▶rule 'INT' => sub { $_ =~ /\A[+\-]?[0-9]+\z/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
13 4 ▶rule 'UINT' => sub { $_ =~ /\A[0-9]+\z/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
14 30 alias 'NOT_NULL' => 'NOT_BLANK';
15 30 alias 'NOT_NULL' => 'REQUIRED';
16  
17 rule 'ASCII' => sub {
18 2 ▶ $_ =~ /^[\x21-\x7E]+$/
Subroutine __ANON__: called CC=1 SCAR=0.0
19 30 };
20  
21 # {mails => [qw/mail1 mail2/]} => ['DUPLICATION']
22 rule 'DUPLICATION' => sub {
23 5 ▶ defined($_->[0]) && defined($_->[1]) && $_->[0] eq $_->[1]
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[0] and defined $_->[1] and $_->[0] eq $_->[1] 5 0 5
Condition33%1/3
defined $_->[0] and defined $_->[1]
!ll&&!rl&&r
005
MC/DC0%0/2
defined $_->[0] and defined $_->[1]
defined $_->[0] defined $_->[1]
Truth table33%1/3
A and B
A= defined $_->[0]B= defined $_->[1]
ABresult
0X0
100
111
24 30 };
25 30 alias 'DUPLICATION' => 'DUP';
26  
27 # 'name' => [qw/LENGTH 5 20/],
28 rule 'LENGTH' => sub {
29 6 ▶ my $length = length($_);
Subroutine __ANON__: called CC=4 SCAR=14.0
30 6 my $min = shift;
31 6 ▶ my $max = shift || $min;
Condition66%2/3
shift() || $min
l!l&&r!l&&!r
330
MC/DC0%0/2
shift() || $min
shift() $min
Truth table66%2/3
A || B
A= shift()B= $min
ABresult
1X1
011
000
32 6 ▶ Carp::croak("missing \$min") unless defined($min);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 0 6 6
33  
34 6 ▶ ( $min <= $length and $length <= $max )
Branch: 1 branch
BranchTrueFalseTotal
$min <= $length and $length <= $max 5 1 6
35 30 };
36  
37 rule 'EQUAL' => sub {
38 2 ▶ Carp::croak("missing \$argument") if @_ == 0;
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 0 0 2 2
39 2 $_ eq $_[0]
40 30 };
41  
42 rule 'REGEX' => sub {
43 4 ▶ my $regex = shift;
Subroutine __ANON__: called CC=2 SCAR=7.1
44 4 ▶ Carp::croak("missing args at REGEX rule") unless defined $regex;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $regex 0 4 4
45 4 $_ =~ /$regex/
46 30 };
47 30 alias 'REGEX' => 'REGEXP';
48  
49 rule 'CHOICE' => sub {
50 14 ▶ Carp::croak("missing \$choices") if @_ == 0;
Subroutine __ANON__: called CC=6 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 0 0 14 14
51  
52 14 ▶ my @choices = @_==1 && ref$_[0]eq'ARRAY' ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 4 10 14
Condition100%3/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
824
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
53  
54 14 for my $c (@choices) {
55 29 ▶ if ($c eq $_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $_) 8 21 29
56 8 return 1;
57 }
58 }
59 6 return 0;
60 30 };
61 30 alias 'CHOICE' => 'IN';
62  
63 rule 'NOT_IN' => sub {
64 4 ▶ my @choices = @_==1 && ref$_[0]eq'ARRAY' ? @{$_[0]} : @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 3 1 4
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
103
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
65  
66 4 for my $c (@choices) {
67 4 ▶ if ($c eq $_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $_) 1 3 4
68 1 return 0;
69 }
70 }
71 3 return 1;
72 30 };
73  
74 rule 'MATCH' => sub {
75 1 ▶ my $callback = shift;
Subroutine __ANON__: called CC=2 SCAR=7.1
76 1 ▶ Carp::croak("missing \$callback") if ref $callback ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback ne "CODE" 0 1 1
77  
78 1 $callback->($_);
79 30 };
80  
81 our $Filters = {
82 trim => sub {
83 8 ▶ my $value = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
84 8 ▶ return $value unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 8 8
85 8 $value =~ s/^\s+|\s+$//g;
86 8 $value;
87 },
88 30 };
89  
90 rule 'FILTER' => sub {
91 11 ▶ my $filter = shift;
Subroutine __ANON__: called CC=5 SCAR=16.5
92 11 ▶ Carp::croak("missing \$filter") unless $filter;
Branch: 1 branch
BranchTrueFalseTotal
unless $filter 0 11 11
93
94 11 ▶ if (not ref $filter) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $filter) 8 3 11
95 8 ▶ $filter = $Filters->{$filter}
Branch: 1 branch
BranchTrueFalseTotal
$filter = $FormValidator::Lite::Constraint::Default::Filters->{$filter} or Carp::croak("$filter is not defined.") 0 8 8
96 or Carp::croak("$filter is not defined.");
97 }
98
99 11 ▶ Carp::croak("\$filter must be coderef.") if ref $filter ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $filter ne "CODE" 0 11 11
100
101 11 $_ = $filter->($_);
102
103 11 1; # always return true
104 30 };
105  
106 30 1;
107 __END__
« blib/lib/FormValidator/Lite.pm ↑ Summary blib/lib/FormValidator/Lite/Constraint/Time.pm »