Verifier/Results.pm

filter: Statementstmt 100% 77 / 77 Branchbran 92.3% 24 / 26 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 20 / 20 Podpod 100% 17 / 17 totaltotal 98.7% 153 / 155 CC 18 SCAR 8.3
CC
18
Cov
98%
is_wrong
4.0
is_invalid
3.0
is_missing
3.0
CRAP 2.3
« Verifier/Nested.pm ↑ Summary Verifier/Filters.pm »
1 package Data::Verifier::Results;
2 17 $Data::Verifier::Results::VERSION = '0.66';
3 17 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use MooseX::Storage;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 with 'MooseX::Storage::Deferred';
7  
8 # ABSTRACT: Results of a Data::Verifier verify
9  
10  
11 has 'fields' => (
12 is => 'rw',
13 isa => 'HashRef',
14 traits => [ 'Hash' ],
15 112 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 17 handles => {
17 get_field => 'get',
18 set_field => 'set',
19 has_field => 'exists'
20 }
21 );
22  
23  
24 14 ▶sub get_original_value {
Subroutine get_original_value: called CC=2 SCAR=7.0
Pod documented
25 14 my ($self, $key) = @_;
26  
27 14 my $f = $self->get_field($key);
28 14 ▶ return undef unless defined($f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 0 14 14
29 14 return $f->original_value;
30 }
31  
32  
33 46 ▶sub get_post_filter_value {
Subroutine get_post_filter_value: called CC=2 SCAR=7.0
Pod documented
34 46 my ($self, $key) = @_;
35  
36 46 my $f = $self->get_field($key);
37 46 ▶ return undef unless defined($f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 0 46 46
38 46 return $f->post_filter_value;
39 }
40  
41  
42 136 ▶sub get_value {
Subroutine get_value: called CC=2 SCAR=6.9
Pod documented
43 136 my ($self, $key) = @_;
44  
45 136 my $f = $self->get_field($key);
46 136 ▶ return undef unless defined($f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 2 134 136
47 134 return $f->value;
48 }
49  
50  
51 1 ▶sub get_values {
Subroutine get_values: called CC=1 SCAR=0.0
Pod documented
52 1 my ($self, @keys) = @_;
53  
54 1 return map { $self->get_value($_) } @keys;
55 }
56  
57  
58 27 ▶sub is_invalid {
Subroutine is_invalid: called CC=3 SCAR=11.0
Pod documented
59 27 my ($self, $field) = @_;
60  
61 27 my $f = $self->get_field($field);
62  
63 27 ▶ return 0 unless defined($f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 3 24 27
64 24 ▶ return $f->valid ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$f->valid ? : 12 12 24
65 }
66  
67  
68 17 ▶sub is_missing {
Subroutine is_missing: called CC=3 SCAR=11.0
Pod documented
69 17 my ($self, $field) = @_;
70  
71 17 ▶ return 0 unless $self->has_field($field);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_field($field) 2 15 17
72  
73 15 my $f = $self->get_field($field);
74  
75 15 ▶ return 1 unless defined($f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 7 8 15
76 8 return 0;
77 }
78  
79  
80 20 ▶sub is_valid {
Subroutine is_valid: called CC=3 SCAR=11.0
Pod documented
81 20 my ($self, $field) = @_;
82  
83 20 my $f = $self->get_field($field);
84  
85 20 ▶ return 0 unless defined($f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 5 15 20
86 15 ▶ return $f->valid ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$f->valid ? : 13 2 15
87 }
88  
89  
90 4 ▶sub is_wrong {
Subroutine is_wrong: called CC=4 SCAR=13.9
Pod documented
91 4 my ($self, $field) = @_;
92  
93 # return true if it is missing
94 4 ▶ return 1 if $self->is_missing($field);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_missing($field) 1 3 4
95 # return 0 if it's not present at all
96 3 ▶ return 0 if !defined($self->get_field($field));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->get_field($field) 1 2 3
97 # lastly, check that it's valid
98 2 ▶ return 1 if $self->is_invalid($field);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_invalid($field) 1 1 2
99  
100 # Nope, must be fine
101 1 return 0;
102 }
103  
104  
105 9 ▶sub merge {
Subroutine merge: called CC=2 SCAR=6.9
Pod documented
106 9 my ($self, $other) = @_;
107  
108 9 foreach my $f (keys %{ $other->fields }) {
109 11 $self->set_field($f, $other->get_field($f));
110 }
111 }
112  
113  
114 115 ▶sub invalid_count {
Subroutine invalid_count: called CC=1 SCAR=0.0
Pod documented
115 115 my ($self) = @_;
116  
117 115 return scalar($self->invalids);
118 }
119  
120  
121 115 ▶sub invalids {
Subroutine invalids: called CC=2 SCAR=6.9
Pod documented
122 115 my ($self) = @_;
123  
124 return grep(
125 175 ▶ { my $field = $self->get_field($_); defined($field) && !$field->valid; }
Condition100%3/3
defined $field && !$field->valid
!ll&&!rl&&r
314329
MC/DC100%2/2
defined $field && !$field->valid
defined $field !$field->valid
Truth table100%3/3
A && not(B)
A= defined $fieldB= !$field->valid
ABresult
0X0
100
111
126 115 keys %{ $self->fields }
127 );
128 }
129  
130  
131 121 ▶sub missing_count {
Subroutine missing_count: called CC=1 SCAR=0.0
Pod documented
132 121 my ($self) = @_;
133  
134 121 return scalar($self->missings);
135 }
136  
137  
138 121 ▶sub missings {
Subroutine missings: called CC=1 SCAR=0.0
Pod documented
139 121 my ($self) = @_;
140  
141 return grep(
142 184 { my $field = $self->get_field($_); !defined($field) }
143 121 keys %{ $self->fields }
144 );
145 }
146  
147  
148 105 ▶sub success {
Subroutine success: called CC=3 SCAR=11.0
Pod documented
149 105 my ($self) = @_;
150  
151 105 ▶ if($self->missing_count || $self->invalid_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->missing_count or $self->invalid_count) 27 78 105
Condition100%3/3
$self->missing_count or $self->invalid_count
l!l&&r!l&&!r
72078
MC/DC100%2/2
$self->missing_count or $self->invalid_count
$self->missing_count $self->invalid_count
Truth table100%3/3
A or B
A= $self->missing_countB= $self->invalid_count
ABresult
1X1
011
000
152 27 return 0;
153 }
154  
155 78 return 1;
156 }
157  
158  
159 15 ▶sub valids {
Subroutine valids: called CC=2 SCAR=6.9
Pod documented
160 15 my ($self) = @_;
161  
162 return grep(
163 23 ▶ { my $field = $self->get_field($_); defined($field) && $field->valid; }
Condition100%3/3
defined $field && $field->valid
!ll&&!rl&&r
2318
MC/DC100%2/2
defined $field && $field->valid
defined $field $field->valid
Truth table100%3/3
A && B
A= defined $fieldB= $field->valid
ABresult
0X0
100
111
164 15 keys %{ $self->fields }
165 );
166 }
167  
168  
169 13 ▶sub valid_count {
Subroutine valid_count: called CC=1 SCAR=0.0
Pod documented
170 13 my ($self) = @_;
171  
172 13 return scalar($self->valids);
173 }
174  
175  
176 2 ▶sub valid_values {
Subroutine valid_values: called CC=1 SCAR=0.0
Pod documented
177 2 my ($self) = @_;
178  
179 2 return map { $_ => $self->get_value($_) } $self->valids;
180 }
181  
182 17 __PACKAGE__->meta->make_immutable;
183  
184 17 1;
185  
186 __END__
« Verifier/Nested.pm ↑ Summary Verifier/Filters.pm »