Custom/Constraint.pm

filter: Statementstmt 97.7% 176 / 180 Branchbran 93.2% 125 / 134 Conditioncond 99.1% 116 / 117 MC/DCmcdc 98.4% 65 / 66 Subroutinesub 90.2% 37 / 41 Podpod 0.0% 0 / 34 totaltotal 90.7% 519 / 572 CC 107 SCAR 19.5
CC
107
Cov
97%
datetime_to_timepiece
18.0
date_to_timepiece
12.0
length
11.0
CRAP 7.0
« Custom.pm ↑ Summary Custom/CheckFunction.pm »
1 # Version 0 module
2 package Validator::Custom::Constraint;
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Carp trust relationship
10 5 push @Validator::Custom::CARP_NOT, __PACKAGE__;
11  
12 5 my $NUM_RE = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/;
13  
14 6 ▶sub ascii { defined $_[0] && $_[0] =~ /^[\x21-\x7E]+$/ ? 1 : 0 }
Subroutine ascii: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ /^[\x21-\x7E]+$/ ? : 2 4 6
Condition100%3/3
defined $_[0] and $_[0] =~ /^[\x21-\x7E]+$/
!ll&&!rl&&r
132
MC/DC100%2/2
defined $_[0] and $_[0] =~ /^[\x21-\x7E]+$/
defined $_[0] $_[0] =~ /^[\x21-\x7E]+$/
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ /^[\x21-\x7E]+$/
ABresult
0X0
100
111
15  
16 17 ▶sub between {
Subroutine between: called CC=9 SCAR=22.0
Pod undocumented
17 17 my ($value, $args) = @_;
18 17 my ($start, $end) = @$args;
19  
20
21 17 ▶ croak "Constraint 'between' needs two numeric arguments"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start and $start =~ /$NUM_RE/ and defined $end and $end =~ /$NUM_RE/ 4 13 17
Condition100%9/9
defined $start and $start =~ /$NUM_RE/ and defined $end and $end =~ /$NUM_RE/
!ll&&!rl&&r
3113
defined $start and $start =~ /$NUM_RE/ and defined $end
!ll&&!rl&&r
2114
defined $start and $start =~ /$NUM_RE/
!ll&&!rl&&r
1115
MC/DC100%4/4
defined $start and $start =~ /$NUM_RE/ and defined $end and $end =~ /$NUM_RE/
defined $start $start =~ /$NUM_RE/ defined $end $end =~ /$NUM_RE/
Truth table100%5/5
A and B and C and D
A= defined $startB= $start =~ /$NUM_RE/C= defined $endD= $end =~ /$NUM_RE/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
22 unless defined($start) && $start =~ /$NUM_RE/ && defined($end) && $end =~ /$NUM_RE/;
23
24 13 ▶ return 0 unless defined $value && $value =~ /$NUM_RE/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /$NUM_RE/ 3 10 13
Condition100%3/3
defined $value and $value =~ /$NUM_RE/
!ll&&!rl&&r
1210
MC/DC100%2/2
defined $value and $value =~ /$NUM_RE/
defined $value $value =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /$NUM_RE/
ABresult
0X0
100
111
25 10 ▶ return $value >= $start && $value <= $end ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value >= $start && $value <= $end ? : 8 2 10
Condition100%3/3
$value >= $start and $value <= $end
!ll&&!rl&&r
118
MC/DC100%2/2
$value >= $start and $value <= $end
$value >= $start $value <= $end
Truth table100%3/3
A and B
A= $value >= $startB= $value <= $end
ABresult
0X0
100
111
26 }
27  
28 18 ▶sub blank { defined $_[0] && $_[0] eq '' }
Subroutine blank: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] eq "" 17 1 18
29  
30 20 ▶sub date_to_timepiece {
Subroutine date_to_timepiece: called CC=12 SCAR=24.9
Pod undocumented
31 20 my $value = shift;
32
33 20 require Time::Piece;
34
35 # To Time::Piece object
36 20 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 14 6 20
37 14 my $year = $value->[0];
38 14 my $mon = $value->[1];
39 14 my $mday = $value->[2];
40
41 14 ▶ return [0, undef]
Branch: 1 branch
BranchTrueFalseTotal
unless defined $year and defined $mon and defined $mday 3 11 14
Condition100%6/6
defined $year and defined $mon and defined $mday
!ll&&!rl&&r
2111
defined $year and defined $mon
!ll&&!rl&&r
1112
MC/DC100%3/3
defined $year and defined $mon and defined $mday
defined $year defined $mon defined $mday
Truth table100%4/4
A and B and C
A= defined $yearB= defined $monC= defined $mday
ABCresult
0XX0
10X0
1100
1111
42 unless defined $year && defined $mon && defined $mday;
43
44 11 ▶ unless ($year =~ /^[0-9]{1,4}$/ && $mon =~ /^[0-9]{1,2}$/
Branch: 1 branch
BranchTrueFalseTotal
unless ($year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/) 6 5 11
Condition100%6/6
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
515
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
416
MC/DC100%3/3
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/
$year =~ /^[0-9]{1,4}$/ $mon =~ /^[0-9]{1,2}$/ $mday =~ /^[0-9]{1,2}$/
Truth table100%4/4
A and B and C
A= $year =~ /^[0-9]{1,4}$/B= $mon =~ /^[0-9]{1,2}$/C= $mday =~ /^[0-9]{1,2}$/
ABCresult
0XX0
10X0
1100
1111
45 && $mday =~ /^[0-9]{1,2}$/)
46 {
47 6 return [0, undef];
48 }
49
50 5 my $date = sprintf("%04s%02s%02s", $year, $mon, $mday);
51
52 5 my $tp;
53 5 eval {
54 0 ▶ local $SIG{__WARN__} = sub { die @_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
55 5 $tp = Time::Piece->strptime($date, '%Y%m%d');
56 };
57
58 5 ▶ return $@ ? [0, undef] : [1, $tp];
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 1 4 5
59 }
60 else {
61 6 ▶ $value = '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 5 6
62 6 $value =~ s/[^0-9]//g;
63
64 6 ▶ return [0, undef] unless $value =~ /^[0-9]{8}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[0-9]{8}$/ 2 4 6
65
66 4 my $tp;
67 4 eval {
68 0 ▶ local $SIG{__WARN__} = sub { die @_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
69 4 $tp = Time::Piece->strptime($value, '%Y%m%d');
70 };
71 4 ▶ return $@ ? [0, undef] : [1, $tp];
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 1 3 4
72 }
73 }
74  
75 26 ▶sub datetime_to_timepiece {
Subroutine datetime_to_timepiece: called CC=18 SCAR=28.9
Pod undocumented
76 26 my $value = shift;
77
78 26 require Time::Piece;
79
80 # To Time::Piece object
81 26 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 20 6 26
82 20 my $year = $value->[0];
83 20 my $mon = $value->[1];
84 20 my $mday = $value->[2];
85 20 my $hour = $value->[3];
86 20 my $min = $value->[4];
87 20 my $sec = $value->[5];
88  
89 20 ▶ return [0, undef]
Branch: 1 branch
BranchTrueFalseTotal
unless defined $year and defined $mon and defined $mday and defined $hour and defined $min and defined $sec 6 14 20
Condition100%15/15
defined $year and defined $mon and defined $mday and defined $hour and defined $min and defined $sec
!ll&&!rl&&r
5114
defined $year and defined $mon and defined $mday and defined $hour and defined $min
!ll&&!rl&&r
4115
defined $year and defined $mon and defined $mday and defined $hour
!ll&&!rl&&r
3116
defined $year and defined $mon and defined $mday
!ll&&!rl&&r
2117
defined $year and defined $mon
!ll&&!rl&&r
1118
MC/DC100%6/6
defined $year and defined $mon and defined $mday and defined $hour and defined $min and defined $sec
defined $year defined $mon defined $mday defined $hour defined $min defined $sec
Truth table100%7/7
A and B and C and D and E and F
A= defined $yearB= defined $monC= defined $mdayD= defined $hourE= defined $minF= defined $sec
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
90 unless defined $year && defined $mon && defined $mday
91 && defined $hour && defined $min && defined $sec;
92
93 14 ▶ unless ($year =~ /^[0-9]{1,4}$/ && $mon =~ /^[0-9]{1,2}$/
Branch: 1 branch
BranchTrueFalseTotal
unless ($year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/ and $hour =~ /^[0-9]{1,2}$/ and $min =~ /^[0-9]{1,2}$/ and $sec =~ /^[0-9]{1,2}$/) 9 5 14
Condition100%15/15
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/ and $hour =~ /^[0-9]{1,2}$/ and $min =~ /^[0-9]{1,2}$/ and $sec =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
815
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/ and $hour =~ /^[0-9]{1,2}$/ and $min =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
716
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/ and $hour =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
617
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
518
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/
!ll&&!rl&&r
419
MC/DC100%6/6
$year =~ /^[0-9]{1,4}$/ and $mon =~ /^[0-9]{1,2}$/ and $mday =~ /^[0-9]{1,2}$/ and $hour =~ /^[0-9]{1,2}$/ and $min =~ /^[0-9]{1,2}$/ and $sec =~ /^[0-9]{1,2}$/
$year =~ /^[0-9]{1,4}$/ $mon =~ /^[0-9]{1,2}$/ $mday =~ /^[0-9]{1,2}$/ $hour =~ /^[0-9]{1,2}$/ $min =~ /^[0-9]{1,2}$/ $sec =~ /^[0-9]{1,2}$/
Truth table100%7/7
A and B and C and D and E and F
A= $year =~ /^[0-9]{1,4}$/B= $mon =~ /^[0-9]{1,2}$/C= $mday =~ /^[0-9]{1,2}$/D= $hour =~ /^[0-9]{1,2}$/E= $min =~ /^[0-9]{1,2}$/F= $sec =~ /^[0-9]{1,2}$/
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
94 && $mday =~ /^[0-9]{1,2}$/ && $hour =~ /^[0-9]{1,2}$/
95 && $min =~ /^[0-9]{1,2}$/ && $sec =~ /^[0-9]{1,2}$/)
96 {
97 9 return [0, undef];
98 }
99
100 5 my $date = sprintf("%04s%02s%02s%02s%02s%02s",
101 $year, $mon, $mday, $hour, $min, $sec);
102 5 my $tp;
103 5 eval {
104 0 ▶ local $SIG{__WARN__} = sub { die @_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
105 5 $tp = Time::Piece->strptime($date, '%Y%m%d%H%M%S');
106 };
107
108 5 ▶ return $@ ? [0, undef] : [1, $tp];
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 1 4 5
109 }
110 else {
111 6 ▶ $value = '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 5 6
112 6 $value =~ s/[^0-9]//g;
113
114 6 ▶ return [0, undef] unless $value =~ /^[0-9]{14}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[0-9]{14}$/ 2 4 6
115
116 4 my $tp;
117 4 eval {
118 0 ▶ local $SIG{__WARN__} = sub { die @_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
119 4 $tp = Time::Piece->strptime($value, '%Y%m%d%H%M%S');
120 };
121 4 ▶ return $@ ? [0, undef] : [1, $tp];
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 1 3 4
122 }
123 }
124  
125 16 ▶sub decimal {
Subroutine decimal: called CC=9 SCAR=22.0
Pod undocumented
126 16 my ($value, $digits_tmp) = @_;
127
128 # 桁数情報を整理
129 16 my $digits;
130 16 ▶ if (defined $digits_tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $digits_tmp) { } 13 3 16
131 13 ▶ if (ref $digits_tmp eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $digits_tmp eq 'ARRAY') { } 9 4 13
132 9 $digits = $digits_tmp;
133 }
134 else {
135 4 $digits = [$digits_tmp, undef];
136 }
137 }
138 else {
139 3 $digits = [undef, undef];
140 }
141
142 # 正規表現を作成
143 16 my $re;
144 16 ▶ if (defined $digits->[0] && defined $digits->[1]) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $digits->[0] and defined $digits->[1]) { } 4 12 16
elsif (defined $digits->[0]) { } 7 5 12
elsif (defined $digits->[1]) { } 2 3 5
Condition100%3/3
defined $digits->[0] and defined $digits->[1]
!ll&&!rl&&r
574
MC/DC100%2/2
defined $digits->[0] and defined $digits->[1]
defined $digits->[0] defined $digits->[1]
Truth table100%3/3
A and B
A= defined $digits->[0]B= defined $digits->[1]
ABresult
0X0
100
111
145 4 $re = qr/^[0-9]{1,$digits->[0]}(\.[0-9]{0,$digits->[1]})?$/;
146 }
147 elsif (defined $digits->[0]) {
148 7 $re = qr/^[0-9]{1,$digits->[0]}(\.[0-9]*)?$/;
149 }
150 elsif (defined $digits->[1]) {
151 2 $re = qr/^[0-9]+(\.[0-9]{0,$digits->[1]})?$/;
152 }
153 else {
154 3 $re = qr/^[0-9]+(\.[0-9]*)?$/;
155 }
156
157 # 値をチェック
158 16 ▶ if (defined $value && $value =~ /$re/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value =~ /$re/) { } 6 10 16
Condition100%3/3
defined $value and $value =~ /$re/
!ll&&!rl&&r
196
MC/DC100%2/2
defined $value and $value =~ /$re/
defined $value $value =~ /$re/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /$re/
ABresult
0X0
100
111
159 6 return 1;
160 }
161 else {
162 10 return 0;
163 }
164 }
165  
166 10 ▶sub duplication {
Subroutine duplication: called CC=4 SCAR=13.9
Pod undocumented
167 10 my $values = shift;
168  
169 10 ▶ return 0 unless defined $values->[0] && defined $values->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $values->[0] and defined $values->[1] 4 6 10
Condition100%3/3
defined $values->[0] and defined $values->[1]
!ll&&!rl&&r
316
MC/DC100%2/2
defined $values->[0] and defined $values->[1]
defined $values->[0] defined $values->[1]
Truth table100%3/3
A and B
A= defined $values->[0]B= defined $values->[1]
ABresult
0X0
100
111
170 6 ▶ return $values->[0] eq $values->[1] ? [1, $values->[0]] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$values->[0] eq $values->[1] ? : 5 1 6
171 }
172  
173 9 ▶sub equal_to {
Subroutine equal_to: called CC=6 SCAR=17.9
Pod undocumented
174 9 my ($value, $target) = @_;
175
176 9 ▶ croak "Constraint 'equal_to' needs a numeric argument"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and $target =~ /$NUM_RE/ 2 7 9
Condition100%3/3
defined $target and $target =~ /$NUM_RE/
!ll&&!rl&&r
117
MC/DC100%2/2
defined $target and $target =~ /$NUM_RE/
defined $target $target =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $targetB= $target =~ /$NUM_RE/
ABresult
0X0
100
111
177 unless defined $target && $target =~ /$NUM_RE/;
178
179 7 ▶ return 0 unless defined $value && $value =~ /$NUM_RE/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /$NUM_RE/ 3 4 7
Condition100%3/3
defined $value and $value =~ /$NUM_RE/
!ll&&!rl&&r
124
MC/DC100%2/2
defined $value and $value =~ /$NUM_RE/
defined $value $value =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /$NUM_RE/
ABresult
0X0
100
111
180 4 ▶ return $value == $target ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value == $target ? : 3 1 4
181 }
182  
183 13 ▶sub greater_than {
Subroutine greater_than: called CC=6 SCAR=17.9
Pod undocumented
184 13 my ($value, $target) = @_;
185
186 13 ▶ croak "Constraint 'greater_than' needs a numeric argument"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and $target =~ /$NUM_RE/ 2 11 13
Condition100%3/3
defined $target and $target =~ /$NUM_RE/
!ll&&!rl&&r
1111
MC/DC100%2/2
defined $target and $target =~ /$NUM_RE/
defined $target $target =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $targetB= $target =~ /$NUM_RE/
ABresult
0X0
100
111
187 unless defined $target && $target =~ /$NUM_RE/;
188
189 11 ▶ return 0 unless defined $value && $value =~ /$NUM_RE/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /$NUM_RE/ 3 8 11
Condition100%3/3
defined $value and $value =~ /$NUM_RE/
!ll&&!rl&&r
128
MC/DC100%2/2
defined $value and $value =~ /$NUM_RE/
defined $value $value =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /$NUM_RE/
ABresult
0X0
100
111
190 8 ▶ return $value > $target ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value > $target ? : 4 4 8
191 }
192  
193 5 ▶sub http_url {
Subroutine http_url: called CC=3 SCAR=11.0
Pod undocumented
194 5 ▶ return defined $_[0] && $_[0] =~ /^s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ m[^s?https?://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$] ? : 2 3 5
Condition100%3/3
defined $_[0] and $_[0] =~ m[^s?https?://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$]
!ll&&!rl&&r
122
MC/DC100%2/2
defined $_[0] and $_[0] =~ m[^s?https?://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$]
defined $_[0] $_[0] =~ m[^s?https?://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$]
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ m[^s?https?://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$]
ABresult
0X0
100
111
195 }
196  
197 55 ▶sub int { defined $_[0] && $_[0] =~ /^\-?[0-9]+$/ ? 1 : 0 }
Subroutine int: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ /^\-?[0-9]+$/ ? : 21 34 55
Condition100%3/3
defined $_[0] and $_[0] =~ /^\-?[0-9]+$/
!ll&&!rl&&r
72721
MC/DC100%2/2
defined $_[0] and $_[0] =~ /^\-?[0-9]+$/
defined $_[0] $_[0] =~ /^\-?[0-9]+$/
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ /^\-?[0-9]+$/
ABresult
0X0
100
111
198  
199 6 ▶sub in_array {
Subroutine in_array: called CC=3 SCAR=11.0
Pod undocumented
200 6 my ($value, $args) = @_;
201 6 ▶ $value = '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 4 6
202 6 my $match = grep { $_ eq $value } @$args;
203 6 ▶ return $match > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$match > 0 ? : 2 4 6
204 }
205  
206 21 ▶sub length {
Subroutine length: called CC=11 SCAR=24.0
Pod undocumented
207 21 my ($value, $args) = @_;
208
209 21 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 20 21
210
211 20 my $min;
212 my $max;
213 20 ▶ if(ref $args eq 'ARRAY') { ($min, $max) = @$args }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args eq 'ARRAY') { } 6 14 20
elsif (ref $args eq 'HASH') { } 12 2 14
214 elsif (ref $args eq 'HASH') {
215 12 $min = $args->{min};
216 12 $max = $args->{max};
217 }
218 2 else { $min = $max = $args }
219
220 20 ▶ croak "Constraint 'length' needs one or two arguments"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min or defined $max 1 19 20
Condition100%3/3
defined $min or defined $max
l!l&&r!l&&!r
1541
MC/DC100%2/2
defined $min or defined $max
defined $min defined $max
Truth table100%3/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
221 unless defined $min || defined $max;
222
223 19 my $length = length $value;
224 19 my $is_valid;
225 19 ▶ if (defined $min && defined $max) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $min and defined $max) { } 11 8 19
elsif (defined $min) { } 4 4 8
elsif (defined $max) { } 4 0 4
Condition100%3/3
defined $min and defined $max
!ll&&!rl&&r
4411
MC/DC100%2/2
defined $min and defined $max
defined $min defined $max
Truth table100%3/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
226 11 ▶ $is_valid = $length >= $min && $length <= $max;
Condition100%3/3
$length >= $min && $length <= $max
!ll&&!rl&&r
317
MC/DC100%2/2
$length >= $min && $length <= $max
$length >= $min $length <= $max
Truth table100%3/3
A && B
A= $length >= $minB= $length <= $max
ABresult
0X0
100
111
227 }
228 elsif (defined $min) {
229 4 $is_valid = $length >= $min;
230 }
231 elsif (defined $max) {
232 4 $is_valid =$length <= $max;
233 }
234
235 19 return $is_valid;
236 }
237  
238 11 ▶sub less_than {
Subroutine less_than: called CC=6 SCAR=17.9
Pod undocumented
239 11 my ($value, $target) = @_;
240
241 11 ▶ croak "Constraint 'less_than' needs a numeric argument"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and $target =~ /$NUM_RE/ 2 9 11
Condition100%3/3
defined $target and $target =~ /$NUM_RE/
!ll&&!rl&&r
119
MC/DC100%2/2
defined $target and $target =~ /$NUM_RE/
defined $target $target =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $targetB= $target =~ /$NUM_RE/
ABresult
0X0
100
111
242 unless defined $target && $target =~ /$NUM_RE/;
243
244 9 ▶ return 0 unless defined $value && $value =~ /$NUM_RE/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /$NUM_RE/ 3 6 9
Condition100%3/3
defined $value and $value =~ /$NUM_RE/
!ll&&!rl&&r
126
MC/DC100%2/2
defined $value and $value =~ /$NUM_RE/
defined $value $value =~ /$NUM_RE/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /$NUM_RE/
ABresult
0X0
100
111
245 6 ▶ return $value < $target ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value < $target ? : 4 2 6
246 }
247  
248 3 ▶sub merge {
Subroutine merge: called CC=2 SCAR=6.9
Pod undocumented
249 3 my $values = shift;
250
251 3 ▶ $values = [$values] unless ref $values eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $values eq "ARRAY" 1 2 3
252
253 3 return [1, join('', @$values)];
254 }
255  
256 6 ▶sub string { defined $_[0] && !ref $_[0] }
Subroutine string: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and not ref $_[0] 5 1 6
257 30 ▶sub not_blank { defined $_[0] && $_[0] ne '' }
Subroutine not_blank: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] ne "" 29 1 30
258 2 ▶sub not_defined { !defined $_[0] }
Subroutine not_defined: called CC=1 SCAR=0.0
Pod undocumented
259 8 ▶sub not_space { defined $_[0] && $_[0] !~ '^[ \t\n\r\f]*$' ? 1 : 0 }
Subroutine not_space: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && !($_[0] =~ /^[ \t\n\r\f]*$/) ? : 3 5 8
Condition100%3/3
defined $_[0] and not $_[0] =~ /^[ \t\n\r\f]*$/
!ll&&!rl&&r
143
MC/DC100%2/2
defined $_[0] and not $_[0] =~ /^[ \t\n\r\f]*$/
defined $_[0] not $_[0] =~ /^[ \t\n\r\f]*$/
Truth table100%3/3
A and not(B)
A= defined $_[0]B= not $_[0] =~ /^[ \t\n\r\f]*$/
ABresult
0X0
100
111
260  
261 10 ▶sub uint { defined $_[0] && $_[0] =~ /^[0-9]+$/ ? 1 : 0 }
Subroutine uint: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ /^[0-9]+$/ ? : 4 6 10
Condition100%3/3
defined $_[0] and $_[0] =~ /^[0-9]+$/
!ll&&!rl&&r
154
MC/DC100%2/2
defined $_[0] and $_[0] =~ /^[0-9]+$/
defined $_[0] $_[0] =~ /^[0-9]+$/
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ /^[0-9]+$/
ABresult
0X0
100
111
262  
263 7 ▶sub regex {
Subroutine regex: called CC=3 SCAR=11.0
Pod undocumented
264 7 my ($value, $regex) = @_;
265 7 ▶ defined $value && $value =~ /$regex/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value =~ /$regex/ ? : 3 4 7
Condition100%3/3
defined $value and $value =~ /$regex/
!ll&&!rl&&r
133
MC/DC100%2/2
defined $value and $value =~ /$regex/
defined $value $value =~ /$regex/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /$regex/
ABresult
0X0
100
111
266 }
267  
268 10 ▶sub selected_at_least {
Subroutine selected_at_least: called CC=3 SCAR=11.0
Pod undocumented
269 10 my ($values, $num) = @_;
270
271 10 ▶ my $selected = ref $values ? $values : [$values];
Branch: 1 branch
BranchTrueFalseTotal
ref $values ? : 9 1 10
272 10 $num += 0;
273 10 ▶ return scalar(@$selected) >= $num ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$selected >= $num ? : 8 2 10
274 }
275  
276 2 ▶sub shift_array {
Subroutine shift_array: called CC=2 SCAR=6.9
Pod undocumented
277 2 my $values = shift;
278
279 2 ▶ $values = [$values] unless ref $values eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $values eq "ARRAY" 1 1 2
280
281 2 return [1, shift @$values];
282 }
283  
284 8 ▶sub space { defined $_[0] && $_[0] =~ '^[ \t\n\r\f]*$' ? 1 : 0 }
Subroutine space: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ /^[ \t\n\r\f]*$/ ? : 5 3 8
Condition100%3/3
defined $_[0] and $_[0] =~ /^[ \t\n\r\f]*$/
!ll&&!rl&&r
125
MC/DC100%2/2
defined $_[0] and $_[0] =~ /^[ \t\n\r\f]*$/
defined $_[0] $_[0] =~ /^[ \t\n\r\f]*$/
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ /^[ \t\n\r\f]*$/
ABresult
0X0
100
111
285  
286 8 ▶sub to_array {
Subroutine to_array: called CC=2 SCAR=6.9
Pod undocumented
287 8 my $value = shift;
288
289 8 ▶ $value = [$value] unless ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 4 4 8
290
291 8 return [1, $value];
292 }
293  
294 4 ▶sub to_array_remove_blank {
Subroutine to_array_remove_blank: called CC=3 SCAR=11.0
Pod undocumented
295 4 my $values = shift;
296
297 4 ▶ $values = [$values] unless ref $values eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $values eq "ARRAY" 2 2 4
298 4 ▶ $values = [grep { defined $_ && CORE::length $_} @$values];
Condition66%2/3
defined $_ && CORE::length $_
!ll&&!rl&&r
035
MC/DC50%1/2
defined $_ && CORE::length $_
defined $_ CORE::length $_
Truth table66%2/3
A && B
A= defined $_B= CORE::length $_
ABresult
0X0
100
111
299
300 4 return [1, $values];
301 }
302  
303 3 ▶sub trim {
Subroutine trim: called CC=2 SCAR=7.1
Pod undocumented
304 3 my $value = shift;
305 3 ▶ $value =~ s/^[ \t\n\r\f]*(.*?)[ \t\n\r\f]*$/$1/ms if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 3 0 3
306 3 return [1, $value];
307 }
308  
309 2 ▶sub trim_collapse {
Subroutine trim_collapse: called CC=2 SCAR=7.0
Pod undocumented
310 2 my $value = shift;
311 2 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 0 2
312 2 $value =~ s/[ \t\n\r\f]+/ /g;
313 2 $value =~ s/^[ \t\n\r\f]*(.*?)[ \t\n\r\f]*$/$1/ms;
314 }
315 2 return [1, $value];
316 }
317  
318 2 ▶sub trim_lead {
Subroutine trim_lead: called CC=2 SCAR=7.1
Pod undocumented
319 2 my $value = shift;
320 2 ▶ $value =~ s/^[ \t\n\r\f]+(.*)$/$1/ms if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 2 0 2
321 2 return [1, $value];
322 }
323  
324 2 ▶sub trim_trail {
Subroutine trim_trail: called CC=2 SCAR=7.1
Pod undocumented
325 2 my $value = shift;
326 2 ▶ $value =~ s/^(.*?)[ \t\n\r\f]+$/$1/ms if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 2 0 2
327 2 return [1, $value];
328 }
329  
330 1 ▶sub trim_uni {
Subroutine trim_uni: called CC=2 SCAR=7.1
Pod undocumented
331 1 my $value = shift;
332 1 ▶ $value =~ s/^\s*(.*?)\s*$/$1/ms if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 1 0 1
333 1 return [1, $value];
334 }
335  
336 1 ▶sub trim_uni_collapse {
Subroutine trim_uni_collapse: called CC=2 SCAR=7.0
Pod undocumented
337 1 my $value = shift;
338 1 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 0 1
339 1 $value =~ s/\s+/ /g;
340 1 $value =~ s/^\s*(.*?)\s*$/$1/ms;
341 }
342 1 return [1, $value];
343 }
344  
345 1 ▶sub trim_uni_lead {
Subroutine trim_uni_lead: called CC=2 SCAR=7.1
Pod undocumented
346 1 my $value = shift;
347 1 ▶ $value =~ s/^\s+(.*)$/$1/ms if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 1 0 1
348 1 return [1, $value];
349 }
350  
351 1 ▶sub trim_uni_trail {
Subroutine trim_uni_trail: called CC=2 SCAR=7.1
Pod undocumented
352 1 my $value = shift;
353 1 ▶ $value =~ s/^(.*?)\s+$/$1/ms if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 1 0 1
354 1 return [1, $value];
355 }
356  
357 5 1;
358  
359 =head1 NAME
360  
361 Validator::Custom::Constraint - Constrint functions
« Custom.pm ↑ Summary Custom/CheckFunction.pm »