blib/lib/DBIx/Class/Validation/Structure.pm

filter: Statementstmt 83.7% 139 / 166 Branchbran 71.3% 77 / 108 Conditioncond 71.9% 77 / 107 MC/DCmcdc 54.2% 32 / 59 Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 5 totaltotal 74.0% 343 / 463 CC 96 SCAR 42.9
CC
96
Cov
77%
validate
209.6
check_uniques
15.1
_val_password
10.2
CRAP 72.7
↑ Summary
1 package DBIx::Class::Validation::Structure;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 our $VERSION = '0.15';
7  
8 3 ▶use Email::Valid;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use HTML::TagFilter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use base qw/DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶sub validate {
Subroutine validate: called CC=36 SCAR=53.5
Pod undocumented
16 6 my $self = shift;
17 6 my @check_columns = @_;
18  
19 0 ▶ my $check_columns = { map{ $_ => 1 } @check_columns } || {};
Condition50%1/2
{map({$_, 1;} @check_columns)} || {}
l!l
60
MC/DC0%0/1
{map({$_, 1;} @check_columns)} || {}
{map({$_, 1;} @check_columns)}
Truth table50%1/2
A
A= {map({$_, 1;} @check_columns)}
Aresult
11
00
20  
21 6 my $source = $self->result_source;
22 6 my %data = $self->get_columns;
23 6 my $columns = $source->columns_info;
24  
25 6 my ($error, @error_list, $stmt);
26  
27 6 for my $column ( keys %$columns ) {
28  
29 36 ▶ if ( ( not keys %$check_columns ) or $check_columns->{$column} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not keys %$check_columns or $check_columns->{$column}) 36 0 36
Condition33%1/3
not keys %$check_columns or $check_columns->{$column}
l!l&&r!l&&!r
3600
MC/DC0%0/2
not keys %$check_columns or $check_columns->{$column}
not keys %$check_columns $check_columns->{$column}
Truth table33%1/3
not(A) or B
A= not keys %$check_columnsB= $check_columns->{$column}
ABresult
1X1
011
000
30  
31 36 ▶ if ($columns->{$column}{validation_function} and ref $columns->{$column}{validation_function} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns->{$column}{'validation_function'} and ref $columns->{$column}{'validation_function'} eq 'CODE') { } 0 36 36
Condition33%1/3
$columns->{$column}{"validation_function"} and ref $columns->{$column}{"validation_function"} eq "CODE"
!ll&&!rl&&r
3600
MC/DC0%0/2
$columns->{$column}{"validation_function"} and ref $columns->{$column}{"validation_function"} eq "CODE"
$columns->{$column}{"validation_function"} ref $columns->{$column}{"validation_function"} eq "CODE"
Truth table33%1/3
A and B
A= $columns->{$column}{"validation_function"}B= ref $columns->{$column}{"validation_function"} eq "CODE"
ABresult
0X0
100
111
32 ($data{$column}, $error) = $columns->{$column}{validation_function}(
33 info => $columns->{$column},
34 0 value => $data{$column},
35 data => \%data,
36 self => $self,
37 );
38 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
39 } else {
40 36 ▶ my $mand = (defined $columns->{$column}{is_nullable} and $columns->{$column}{is_nullable} == 1 or ( defined $columns->{$column}{is_auto_increment} and $columns->{$column}{is_auto_increment} == 1 ) ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $columns->{$column}{'is_nullable'} && $columns->{$column}{'is_nullable'} == 1 || defined $columns->{$column}{'is_auto_increment'} && $columns->{$column}{'is_auto_increment'} == 1 ? : 18 18 36
Condition77%7/9
defined $columns->{$column}{"is_nullable"} and $columns->{$column}{"is_nullable"} == 1 or defined $columns->{$column}{"is_auto_increment"} and $columns->{$column}{"is_auto_increment"} == 1
l!l&&r!l&&!r
12618
defined $columns->{$column}{"is_nullable"} and $columns->{$column}{"is_nullable"} == 1
!ll&&!rl&&r
24012
defined $columns->{$column}{"is_auto_increment"} and $columns->{$column}{"is_auto_increment"} == 1
!ll&&!rl&&r
1806
MC/DC50%2/4
defined $columns->{$column}{"is_nullable"} and $columns->{$column}{"is_nullable"} == 1 or defined $columns->{$column}{"is_auto_increment"} and $columns->{$column}{"is_auto_increment"} == 1
defined $columns->{$column}{"is_nullable"} $columns->{$column}{"is_nullable"} == 1 defined $columns->{$column}{"is_auto_increment"} $columns->{$column}{"is_auto_increment"} == 1
Truth table42%3/7
A and B or C and D
A= defined $columns->{$column}{"is_nullable"}B= $columns->{$column}{"is_nullable"} == 1C= defined $columns->{$column}{"is_auto_increment"}D= $columns->{$column}{"is_auto_increment"} == 1
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
41 36 ▶ my $val_type = (defined $columns->{$column}{val_override}) ? $columns->{$column}{val_override} : $columns->{$column}{data_type};
Branch: 1 branch
BranchTrueFalseTotal
defined $columns->{$column}{'val_override'} ? : 6 30 36
42  
43 36 ▶ if ($val_type eq 'email') {
Branch: 6 branches
BranchTrueFalseTotal
if ($val_type eq 'email') { } 6 30 36
elsif ($val_type eq 'varchar' or $val_type eq 'text') { } 24 6 30
elsif ($val_type eq 'password') { } 0 6 6
elsif ($val_type eq 'selected') { } 0 6 6
elsif ($val_type eq 'integer' or $val_type =~ /int/g) { } 6 0 6
elsif ($val_type eq 'number') { } 0 0 0
44 6 ($data{$column}, $error) = _val_email( $mand, $data{$column} );
45 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 6 6
46 ▶ } elsif ($val_type eq 'varchar' or $val_type eq 'text') {
Condition66%2/3
$val_type eq "varchar" or $val_type eq "text"
l!l&&r!l&&!r
2406
MC/DC50%1/2
$val_type eq "varchar" or $val_type eq "text"
$val_type eq "varchar" $val_type eq "text"
Truth table66%2/3
A or B
A= $val_type eq "varchar"B= $val_type eq "text"
ABresult
1X1
011
000
47 24 ($data{$column}, $error) = _val_text( $mand, $columns->{$column}{size}, $data{$column} );
48 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 24 24
49 } elsif ($val_type eq 'password') {
50 0 ($data{$column}, $error) = _val_password( $mand, $columns->{$column}{size}, $data{$column} );
51 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
52 } elsif ($val_type eq 'selected') {
53 0 ▶ if ($columns->{$column}{data_type} eq 'varchar' or $columns->{$column}{data_type} eq 'text') {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns->{$column}{'data_type'} eq 'varchar' or $columns->{$column}{'data_type'} eq 'text') { } 0 0 0
Condition0%0/3
$columns->{$column}{"data_type"} eq "varchar" or $columns->{$column}{"data_type"} eq "text"
l!l&&r!l&&!r
000
MC/DC0%0/2
$columns->{$column}{"data_type"} eq "varchar" or $columns->{$column}{"data_type"} eq "text"
$columns->{$column}{"data_type"} eq "varchar" $columns->{$column}{"data_type"} eq "text"
Truth table0%0/3
A or B
A= $columns->{$column}{"data_type"} eq "varchar"B= $columns->{$column}{"data_type"} eq "text"
ABresult
1X1
011
000
54 0 ($data{$column}, $error) = _val_text( 0, $columns->{$column}{size}, $data{$column} );
55 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
56 } else {
57 0 ($data{$column}, $error) = _val_int( 0, $data{$column} );
58 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
59 }
60 0 ($data{$column}, $error) = _val_selected( $data{$column} );
61 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
62 ▶ } elsif ($val_type eq 'integer' or $val_type =~ /int/g) {
Condition33%1/3
$val_type eq "integer" or $val_type =~ /int/g
l!l&&r!l&&!r
600
MC/DC0%0/2
$val_type eq "integer" or $val_type =~ /int/g
$val_type eq "integer" $val_type =~ /int/g
Truth table33%1/3
A or B
A= $val_type eq "integer"B= $val_type =~ /int/g
ABresult
1X1
011
000
63 6 ($data{$column}, $error) = _val_int( $mand, $data{$column} );
64 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 6 6
65 } elsif ($val_type eq 'number') {
66 0 ($data{$column}, $error) = _val_number( $mand, $columns->{$column}{size}, $data{$column} );
67 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
68 } else {
69 0 ($data{$column}, $error) = _val_text( $mand, $columns->{$column}{size}, $data{$column} );
70 0 ▶ if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"msg"}) 0 0 0
71 }
72  
73 # If the column is auto_increment and there is no value set, set it to undef
74 # @TODO decide if this should be deleted all together
75 36 ▶ $data{$column} = undef if $columns->{$column}{is_auto_increment} and not $data{$column};
Branch: 1 branch
BranchTrueFalseTotal
if $columns->{$column}{"is_auto_increment"} and not $data{$column} 4 32 36
Condition100%3/3
$columns->{$column}{"is_auto_increment"} and not $data{$column}
!ll&&!rl&&r
3024
MC/DC100%2/2
$columns->{$column}{"is_auto_increment"} and not $data{$column}
$columns->{$column}{"is_auto_increment"} not $data{$column}
Truth table100%3/3
A and not(B)
A= $columns->{$column}{"is_auto_increment"}B= not $data{$column}
ABresult
0X0
100
111
76 }
77 }
78 }
79  
80 6 ▶ unless (@error_list) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@error_list) 6 0 6
81 # Check the unique constraints
82 6 @error_list = check_uniques($self, \%data, $check_columns);
83 }
84  
85 6 $self->set_columns(\%data);
86  
87 6 ▶ if (@error_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@error_list) 4 2 6
88 4 return { 'errors' => \@error_list };
89 }
90 2 return {};
91 }
92  
93 # Returns whether any of the primary columns have changed
94 # @TODO Write tests for this function
95 1 ▶sub primary_cols_have_changed {
Subroutine primary_cols_have_changed: called CC=3 SCAR=11.1
Pod undocumented
96 1 my $self = shift;
97 1 foreach ( $self->result_source->primary_columns ) {
98 1 ▶ return 1 if $self->is_column_changed($_);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_column_changed($_) 0 1 1
99 }
100  
101 1 return 0;
102 }
103  
104 6 ▶sub check_uniques {
Subroutine check_uniques: called CC=15 SCAR=27.1
Pod undocumented
105 6 my $self = shift;
106 6 my $data = shift;
107 6 my $check_columns = shift;
108 6 my $source = $self->result_source;
109 6 my %unique_constraints = $source->unique_constraints();
110  
111 6 my %errors;
112  
113 6 foreach my $constraint ( sort keys %unique_constraints ) {
114  
115 # Skip the primary constraint uniqueness test if self is in_storage
116 # and the primary columns haven't changed
117 24 ▶ next if $constraint eq 'primary' and $self->in_storage and not primary_cols_have_changed($self);
Branch: 1 branch
BranchTrueFalseTotal
if $constraint eq "primary" and $self->in_storage and not primary_cols_have_changed($self) 1 23 24
Condition83%5/6
$constraint eq "primary" and $self->in_storage and not primary_cols_have_changed($self)
!ll&&!rl&&r
2301
$constraint eq "primary" and $self->in_storage
!ll&&!rl&&r
1851
MC/DC66%2/3
$constraint eq "primary" and $self->in_storage and not primary_cols_have_changed($self)
$constraint eq "primary" $self->in_storage not primary_cols_have_changed($self)
Truth table75%3/4
A and B and not(C)
A= $constraint eq "primary"B= $self->in_storageC= not primary_cols_have_changed($self)
ABCresult
0XX0
10X0
1100
1111
118  
119 my $search = {
120 map {
121 41 ▶ next unless ( not keys %$check_columns ) or $check_columns->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless not keys %$check_columns or $check_columns->{$_} 0 41 41
Condition33%1/3
not keys %$check_columns or $check_columns->{$_}
l!l&&r!l&&!r
4100
MC/DC0%0/2
not keys %$check_columns or $check_columns->{$_}
not keys %$check_columns $check_columns->{$_}
Truth table33%1/3
not(A) or B
A= not keys %$check_columnsB= $check_columns->{$_}
ABresult
1X1
011
000
122 23 ($_ => $data->{$_}) } @{ $unique_constraints{$constraint} }
123 };
124  
125 # Exclude this entries primary keys to the search for dupes
126 # to not detect itself when updating.
127 23 ▶ unless ( $constraint eq 'primary' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($constraint eq "primary") 18 5 23
128 18 for my $column ( $source->primary_columns ) {
129 $search->{$column} = {
130 18 '!=' => $data->{$column},
131 };
132 }
133 }
134  
135 # If there is an entry with the combined value defined above...
136 23 ▶ if ( $source->resultset->count($search) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->resultset->count($search)) 5 18 23
137 5 foreach my $key ( @{ $unique_constraints{$constraint} } ) {
138 10 ▶ $errors{$key} = [] unless defined $errors{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $errors{$key} 9 1 10
139 10 my @other_fields = @{ $unique_constraints{$constraint} };
140 # Remove the field so we get a list of other fields in the
141 # combination
142 10 my $index = 0;
143 10 ▶ $index++ until $other_fields[$index] eq $key;
Branch: 1 branch
BranchTrueFalseTotal
$other_fields[$index] eq $key or do { ++$index } 10 7 17
144 10 splice(@other_fields, $index, 1);
145 # If there are no keys other than the key that isnt unique,
146 # then write the error as singular else explain the combination.
147 10 ▶ if ( $#other_fields >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#other_fields >= 0) { } 8 2 10
148 8 push @{$errors{$key}}, { $key => 'must be unique when combined with '.join(', ',@other_fields) };
149 } else {
150 2 push @{$errors{$key}}, { $key => 'must be unique' };
151 }
152 }
153 }
154 }
155  
156 6 ▶ if ( %errors ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%errors) { } 4 2 6
157 # Convert hash into the array of hashrefs like the validate returns
158 4 return map { { $_ => join( ' and ', map { values %$_ } @{ $errors{$_} } ) } } keys %errors;
159 } else {
160 2 return ();
161 }
162 }
163  
164 5 ▶sub insert {
Subroutine insert: called CC=2 SCAR=6.9
Pod undocumented
165 5 my $self = shift;
166 5 my $result = $self->validate;
167 # If errors return the result
168 5 ▶ if ($result->{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'errors'}) { } 4 1 5
169 4 return $result;
170 } else {
171 # Else do the normal insert
172 1 $self->next::method(@_);
173 }
174 }
175  
176 1 ▶sub update {
Subroutine update: called CC=3 SCAR=11.6
Pod undocumented
177 1 my $self = shift;
178 1 my $columns = shift;
179  
180 1 ▶ $self->set_inflated_columns($columns) if $columns;
Branch: 1 branch
BranchTrueFalseTotal
if $columns 1 0 1
181  
182 1 my $result = $self->validate;
183 # If errors return the result
184 1 ▶ if ($result->{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'errors'}) { } 0 1 1
185 0 return $result;
186 } else {
187 # Else do the normal update
188 1 $self->next::method(@_);
189 }
190 }
191  
192 # =============== Validatators ===============
193  
194 11 ▶sub _val_email {
Subroutine _val_email: called CC=6 SCAR=17.9
195 11 my ($mand, $value) = @_;
196 11 ▶ if (not defined $value) { $value = ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 1 10 11
197 11 ▶ if ( !Email::Valid->address($value) && $mand ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not 'Email::Valid'->address($value) and $mand) { } 1 10 11
elsif (not 'Email::Valid'->address($value) and $value) { } 1 9 10
Condition100%3/3
not "Email::Valid"->address($value) and $mand
!ll&&!rl&&r
731
MC/DC100%2/2
not "Email::Valid"->address($value) and $mand
not "Email::Valid"->address($value) $mand
Truth table100%3/3
not(A) and B
A= not "Email::Valid"->address($value)B= $mand
ABresult
0X0
100
111
198 1 return ( undef, { msg => 'address is blank or not valid' } );
199 ▶ } elsif ( !Email::Valid->address($value) && $value ) {
Condition100%3/3
not "Email::Valid"->address($value) and $value
!ll&&!rl&&r
721
MC/DC100%2/2
not "Email::Valid"->address($value) and $value
not "Email::Valid"->address($value) $value
Truth table100%3/3
not(A) and B
A= not "Email::Valid"->address($value)B= $value
ABresult
0X0
100
111
200 1 return ( undef, { msg => 'address is blank or not valid' } );
201 } else {
202 9 return $value;
203 }
204 }
205  
206 31 ▶sub _val_text {
Subroutine _val_text: called CC=10 SCAR=23.1
207 31 my ($mand, $len, $value) = @_;
208  
209 31 ▶ if ($mand && ( not( defined $value ) or $value eq '' )) {
Branch: 3 branches
BranchTrueFalseTotal
if ($mand and !defined($value) || $value eq '') { } 1 30 31
elsif ($len and length $value and length $value > $len) { } 1 29 30
elsif (defined $value and not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}) { } 1 28 29
Condition83%5/6
$mand and !defined($value) || $value eq ""
!ll&&!rl&&r
18121
not defined $value or $value eq ""
l!l&&r!l&&!r
0112
MC/DC66%2/3
$mand and !defined($value) || $value eq ""
$mand not defined $value $value eq ""
Truth table75%3/4
A and not(B) or C
A= $mandB= not defined $valueC= $value eq ""
ABCresult
0XX0
1000
11X1
1011
210 1 return (undef, { msg => 'cannot be blank' });
211 ▶ } elsif ($len && length($value) && (length($value) > $len) ) {
Condition83%5/6
$len and length $value and length $value > $len
!ll&&!rl&&r
10191
$len and length $value
!ll&&!rl&&r
01020
MC/DC66%2/3
$len and length $value and length $value > $len
$len length $value length $value > $len
Truth table75%3/4
A and B and C
A= $lenB= length $valueC= length $value > $len
ABCresult
0XX0
10X0
1100
1111
212 1 return (undef, { msg => 'is limited to '.$len.' characters' });
213 ▶ } elsif (defined $value && $value !~ /^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>\/\@\w]*)$/) {
Condition100%3/3
defined $value and not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
!ll&&!rl&&r
9191
MC/DC100%2/2
defined $value and not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
defined $value not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
Truth table100%3/3
A and not(B)
A= defined $valueB= not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
ABresult
0X0
100
111
214 1 return (undef, { msg => 'can only use letters, 0-9 and -.,\'\"!&#$?:()[]=%<>;/@ (do not cut and paste from a Word document, you must Save As text only)' });
215 } else {
216 # This is to ensure that $1 is from the last regex match
217 28 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 19 9 28
218 19 return ($1);
219 } else {
220 9 return $value;
221 }
222 }
223 }
224  
225 # _val_password is the same as _val_text but it also allows {}s
226 7 ▶sub _val_password {
Subroutine _val_password: called CC=10 SCAR=23.2
227 7 my ($mand, $len, $value) = @_;
228  
229 7 ▶ if ($mand && (!$value || $value =~ /bogus="1"/)) { #tiny mce
Branch: 3 branches
BranchTrueFalseTotal
if ($mand and !$value || $value =~ /bogus="1"/) { } 1 6 7
elsif ($len and length $value and length $value > $len) { } 1 5 6
elsif ($value and not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/) { } 1 4 5
Condition50%3/6
$mand and !$value || $value =~ /bogus="1"/
!ll&&!rl&&r
601
not $value or $value =~ /bogus="1"/
l!l&&r!l&&!r
100
MC/DC33%1/3
$mand and !$value || $value =~ /bogus="1"/
$mand not $value $value =~ /bogus="1"/
Truth table50%2/4
A and not(B) or C
A= $mandB= not $valueC= $value =~ /bogus="1"/
ABCresult
0XX0
1000
11X1
1011
230 1 return (undef, { msg => 'cannot be blank' });
231 ▶ } elsif ($len && length($value) && (length($value) > $len) ) {
Condition83%5/6
$len and length $value and length $value > $len
!ll&&!rl&&r
231
$len and length $value
!ll&&!rl&&r
024
MC/DC66%2/3
$len and length $value and length $value > $len
$len length $value length $value > $len
Truth table75%3/4
A and B and C
A= $lenB= length $valueC= length $value > $len
ABCresult
0XX0
10X0
1100
1111
232 1 return (undef, { msg => 'is limited to '.$len.' characters' });
233 ▶ } elsif ($value && $value !~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/) {
Condition100%3/3
$value and not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
!ll&&!rl&&r
221
MC/DC100%2/2
$value and not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
$value not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
Truth table100%3/3
A and not(B)
A= $valueB= not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
ABresult
0X0
100
111
234 1 return (undef, { msg => 'can only use letters, 0-9 and -.,\'\"!&#$?:()[]=%<>;/@ (do not cut and paste from a Word document, you must Save As text only)' });
235 } else {
236 4 my $tf = new HTML::TagFilter;
237 # This is to ensure that $1 is from the last regex match
238 4 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 2 2 4
239 2 return ($tf->filter($1));
240 } else {
241 2 return $value;
242 }
243 }
244 }
245  
246 10 ▶sub _val_int {
Subroutine _val_int: called CC=9 SCAR=22.5
247 10 my ($mand, $value) = @_;
248 10 ▶ if ( (not( defined $value ) or $value ne '0') && !$value && $mand ) {
Branch: 2 branches
BranchTrueFalseTotal
if (!defined($value) || $value ne '0' and not $value and $mand) { } 1 9 10
elsif (defined $value and $value || $value eq '0' and not $value =~ /^[-]?\d+$/) { } 1 8 9
Condition66%6/9
!defined($value) || $value ne 0 and not $value and $mand
!ll&&!rl&&r
451
!defined($value) || $value ne 0 and not $value
!ll&&!rl&&r
046
not defined $value or $value ne 0
l!l&&r!l&&!r
0100
MC/DC50%2/4
!defined($value) || $value ne 0 and not $value and $mand
not defined $value $value ne 0 not $value $mand
Truth table42%3/7
not(A) or B and not(C) and D
A= not defined $valueB= $value ne 0C= not $valueD= $mand
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
249 1 return (undef, { msg => 'cannot be blank' });
250 ▶ } elsif ( ( defined $value and ( $value or $value eq '0' ) ) and $value !~ /^[-]?\d+$/) {
Condition77%7/9
defined $value and $value || $value eq 0 and not $value =~ /^[-]?\d+$/
!ll&&!rl&&r
531
defined $value and $value || $value eq 0
!ll&&!rl&&r
054
$value or $value eq 0
l!l&&r!l&&!r
405
MC/DC50%2/4
defined $value and $value || $value eq 0 and not $value =~ /^[-]?\d+$/
defined $value $value $value eq 0 not $value =~ /^[-]?\d+$/
Truth table50%3/6
A and B or C and not(D)
A= defined $valueB= $valueC= $value eq 0D= not $value =~ /^[-]?\d+$/
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
251 1 return (undef, { msg => 'can only use numbers' });
252 } else {
253 8 return ($value);
254 }
255 }
256  
257 2 ▶sub _val_selected {
Subroutine _val_selected: called CC=3 SCAR=11.0
258 2 my ($value) = @_;
259 2 ▶ if (not defined $value or $value eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq '') { } 1 1 2
Condition66%2/3
not defined $value or $value eq ""
l!l&&r!l&&!r
011
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
260 1 return (undef, { msg => 'must be selected' });
261 } else {
262 1 return $value;
263 }
264 }
265  
266 6 ▶sub _val_number {
Subroutine _val_number: called CC=9 SCAR=22.0
267 6 my ($mand, $len, $value) = @_;
268 6 ▶ if ((!defined $value or $value eq '') && $mand) {
Branch: 3 branches
BranchTrueFalseTotal
if (!defined($value) || $value eq '' and $mand) { } 1 5 6
elsif ($len and length $value > $len) { } 2 3 5
elsif ($value and not $value =~ /^([-\.]*\d[\d\.-]*)$/) { } 1 2 3
Condition83%5/6
!defined($value) || $value eq "" and $mand
!ll&&!rl&&r
411
not defined $value or $value eq ""
l!l&&r!l&&!r
024
MC/DC66%2/3
!defined($value) || $value eq "" and $mand
not defined $value $value eq "" $mand
Truth table60%3/5
not(A) or B and C
A= not defined $valueB= $value eq ""C= $mand
ABCresult
00X0
1X00
0100
1X11
0111
269 1 return (undef, { msg => 'cannot be blank' });
270 ▶ } elsif ($len && (length($value) > $len) ) {
Condition66%2/3
$len and length $value > $len
!ll&&!rl&&r
032
MC/DC50%1/2
$len and length $value > $len
$len length $value > $len
Truth table66%2/3
A and B
A= $lenB= length $value > $len
ABresult
0X0
100
111
271 2 return (undef, { msg => 'is limited to '.$len.' characters' });
272 ▶ } elsif ($value && $value !~ /^([-\.]*\d[\d\.-]*)$/) {
Condition100%3/3
$value and not $value =~ /^([-\.]*\d[\d\.-]*)$/
!ll&&!rl&&r
111
MC/DC100%2/2
$value and not $value =~ /^([-\.]*\d[\d\.-]*)$/
$value not $value =~ /^([-\.]*\d[\d\.-]*)$/
Truth table100%3/3
A and not(B)
A= $valueB= not $value =~ /^([-\.]*\d[\d\.-]*)$/
ABresult
0X0
100
111
273 1 return (undef, { msg => 'can only use numbers and . or -' });
274 } else {
275 # This is to ensure that $1 is from the last regex match
276 2 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 1 1 2
277 1 return ($1);
278 } else {
279 1 return $value;
280 }
281 }
282 }
283  
284  
285 3 1;
286 __END__
↑ Summary