lib/Form/Sensible/Validator/Result.pm

filter: Statementstmt 39.3% 37 / 94 Branchbran 17.6% 6 / 34 Conditioncond 27.2% 3 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 47.0% 8 / 17 Podpod 83.3% 10 / 12 totaltotal 37.1% 65 / 175 CC 24 SCAR 22.0
CC
24
Cov
33%
add_missing
20.0
error
20.0
missing
12.0
CRAP 9.0
« lib/Form/Sensible/Field/Number.pm ↑ Summary lib/Form/Sensible/Field/FileSelector.pm »
1 package Form::Sensible::Validator::Result;
2  
3 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has 'error_fields' => (
8 is => 'rw',
9 isa => 'HashRef',
10 required => 1,
11 57 ▶ default => sub { return {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 16 lazy => 1,
13 );
14  
15 has 'missing_fields' => (
16 is => 'rw',
17 isa => 'HashRef',
18 required => 1,
19 8 ▶ default => sub { return {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 16 lazy => 1,
21 );
22  
23 83 ▶sub add_error {
Subroutine add_error: called CC=4 SCAR=14.8
Pod documented
24 83 my ($self, $fieldname, $message) = @_;
25
26 83 ▶ if (ref($message) && $message->isa('Form::Sensible::Validator::Result')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $message and $message->isa('Form::Sensible::Validator::Result')) { } 0 83 83
Condition33%1/3
ref $message and $message->isa("Form::Sensible::Validator::Result")
!ll&&!rl&&r
8300
MC/DC0%0/2
ref $message and $message->isa("Form::Sensible::Validator::Result")
ref $message $message->isa("Form::Sensible::Validator::Result")
Truth table33%1/3
A and B
A= ref $messageB= $message->isa("Form::Sensible::Validator::Result")
ABresult
0X0
100
111
27 0 $self->merge_from_result($message);
28 } else {
29 83 ▶ if (!exists($self->error_fields->{$fieldname})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->error_fields->{$fieldname}) 76 7 83
30 76 $self->error_fields->{$fieldname} = [];
31 }
32 83 push @{$self->error_fields->{$fieldname}}, $message;
33 }
34 }
35  
36 0 ▶sub add_missing {
Subroutine add_missing: not called CC=4 SCAR=30.0
Pod documented
37 0 my ($self, $fieldname, $message) = @_;
38
39 0 ▶ if (ref($message) && $message->isa('Form::Sensible::Validator::Result')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $message and $message->isa('Form::Sensible::Validator::Result')) { } 0 0 0
Condition0%0/3
ref $message and $message->isa("Form::Sensible::Validator::Result")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $message and $message->isa("Form::Sensible::Validator::Result")
ref $message $message->isa("Form::Sensible::Validator::Result")
Truth table0%0/3
A and B
A= ref $messageB= $message->isa("Form::Sensible::Validator::Result")
ABresult
0X0
100
111
40 0 $self->merge_from_result($message);
41 } else {
42 0 ▶ if (!exists($self->missing_fields->{$fieldname})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->missing_fields->{$fieldname}) 0 0 0
43 0 $self->missing_fields->{$fieldname} = [];
44 }
45 0 push @{$self->missing_fields->{$fieldname}}, $message;
46 }
47 }
48  
49 106 ▶sub is_valid {
Subroutine is_valid: called CC=3 SCAR=11.0
Pod documented
50 106 my ($self) = shift;
51
52 106 ▶ if ((scalar keys %{$self->error_fields}) || (scalar keys %{$self->missing_fields})) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$self->error_fields;} or scalar keys %{$self->missing_fields;}) { } 92 14 106
Condition100%2/2
scalar keys %{$self->error_fields;} or scalar keys %{$self->missing_fields;}
l!l
9214
MC/DC100%1/1
scalar keys %{$self->error_fields;} or scalar keys %{$self->missing_fields;}
scalar keys %{$self->error_fields;}
Truth table100%2/2
A
A= scalar keys %{$self->error_fields;}
Aresult
11
00
53 92 return 0;
54 } else {
55 14 return 1;
56 }
57 }
58  
59 # if we have a validation result instead of a message in the error routines, we will need to
60 # merge the values from the provided result into the current result
61  
62 1 ▶sub merge_from_result {
Subroutine merge_from_result: called CC=5 SCAR=19.3
Pod undocumented
63 1 my ($self, $result) = @_;
64
65 1 foreach my $fieldname (keys %{$result->error_fields}) {
66 1 ▶ if (!exists($self->error_fields->{$fieldname})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->error_fields->{$fieldname}) 1 0 1
67 1 $self->error_fields->{$fieldname} = [];
68 }
69 1 push @{$self->error_fields->{$fieldname}}, @{$result->error_fields->{$fieldname}};
70 }
71 1 foreach my $fieldname (keys %{$result->missing_fields}) {
72 0 ▶ if (!exists($self->missing_fields->{$fieldname})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->missing_fields->{$fieldname}) 0 0 0
73 0 $self->missing_fields->{$fieldname} = [];
74 }
75 0 push @{$self->missing_fields->{$fieldname}}, @{$result->missing_fields->{$fieldname}};
76 }
77 }
78  
79 ## below here are things that make Form::Sensible::Validator results behave
80 ## more like FormValidator::Simple
81  
82 0 ▶sub has_missing {
Subroutine has_missing: not called CC=2 SCAR=17.9
Pod documented
83 0 my $self = shift;
84
85 0 ▶ if (scalar keys %{$self->missing_fields}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$self->missing_fields;}) { } 0 0 0
86 0 return 1;
87 } else {
88 0 return 0;
89 }
90 }
91  
92 0 ▶sub has_invalid {
Subroutine has_invalid: not called CC=2 SCAR=17.9
Pod documented
93 0 my $self = shift;
94
95 0 ▶ if (scalar keys %{$self->error_fields}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$self->error_fields;}) { } 0 0 0
96 0 return 1;
97 } else {
98 0 return 0;
99 }
100 }
101  
102 0 ▶sub has_error {
Subroutine has_error: not called CC=1 SCAR=6.9
Pod documented
103 0 my $self = shift;
104
105 0 return !$self->is_valid();
106 }
107  
108 0 ▶sub success {
Subroutine success: not called CC=1 SCAR=6.9
Pod documented
109 0 my $self = shift;
110
111 0 return $self->is_valid();
112 }
113  
114 0 ▶sub missing {
Subroutine missing: not called CC=3 SCAR=24.8
Pod documented
115 0 my $self = shift;
116
117 0 ▶ if ($#_ != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != -1) { } 0 0 0
118 0 ▶ if (exists($self->missing_fields->{$_[0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->missing_fields->{$_[0]}) 0 0 0
119 0 return 1;
120 }
121 } else {
122 0 return keys %{$self->missing_fields};
123 }
124 }
125  
126 0 ▶sub invalid {
Subroutine invalid: not called CC=3 SCAR=24.8
Pod documented
127 0 my $self = shift;
128
129 0 ▶ if ($#_ != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != -1) { } 0 0 0
130 0 ▶ if (exists($self->error_fields->{$_[0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->error_fields->{$_[0]}) { } 0 0 0
131 0 return $self->error_fields->{$_[0]};
132 } else {
133 0 return 0;
134 }
135 } else {
136 0 return keys %{$self->error_fields};
137 }
138 }
139  
140 0 ▶sub error {
Subroutine error: not called CC=4 SCAR=30.0
Pod documented
141 0 my $self = shift;
142
143 0 ▶ if ($#_ == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == -1) { } 0 0 0
144 0 return keys %{$self->missing_fields}, keys %{$self->error_fields};
145 } else {
146 0 ▶ if ($_[1] eq 'NOT_BLANK' && exists($self->missing_fields->{$_[0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq 'NOT_BLANK' and exists $self->missing_fields->{$_[0]}) { } 0 0 0
Condition0%0/3
$_[1] eq "NOT_BLANK" and exists $self->missing_fields->{$_[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1] eq "NOT_BLANK" and exists $self->missing_fields->{$_[0]}
$_[1] eq "NOT_BLANK" exists $self->missing_fields->{$_[0]}
Truth table0%0/3
A and B
A= $_[1] eq "NOT_BLANK"B= exists $self->missing_fields->{$_[0]}
ABresult
0X0
100
111
147 0 return 1;
148 } else {
149 0 return exists($self->error_fields->{$_[0]});
150 }
151 }
152 }
153  
154 0 ▶sub messages_for {
Subroutine messages_for: not called CC=3 SCAR=24.8
Pod undocumented
155 0 my ($self, $fieldname) = @_;
156
157 0 my @messages;
158 0 ▶ if (exists($self->error_fields->{$fieldname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->error_fields->{$fieldname}) 0 0 0
159 0 push @messages, @{$self->error_fields->{$fieldname}};
160 }
161 0 ▶ if (exists($self->missing_fields->{$fieldname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->missing_fields->{$fieldname}) 0 0 0
162 0 push @messages, @{$self->missing_fields->{$fieldname}};
163 }
164
165 0 return @messages;
166
167 }
168  
169 16 __PACKAGE__->meta->make_immutable;
170 16 1;
171  
172 __END__
« lib/Form/Sensible/Field/Number.pm ↑ Summary lib/Form/Sensible/Field/FileSelector.pm »