Nested/Profile/Param/Validator.pm

filter: Statementstmt 100% 82 / 82 Branchbran 96.1% 25 / 26 Conditioncond 76.1% 16 / 21 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 3 totaltotal 89.8% 141 / 157 CC 23 SCAR 20.3
CC
23
Cov
95%
_if_check
13.0
process_scalar
8.1
process_array
4.0
CRAP 7.6
« Nested/Validator/File.pm ↑ Summary Nested/Profile/Param/Filter.pm »
1 package FormValidator::Nested::Profile::Param::Validator;
2 18 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 with 'FormValidator::Nested::Profile::Param::Processor';
5  
6 18 ▶use FormValidator::Nested;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use FormValidator::Nested::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use FormValidator::Nested::Result::Param;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 18 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 18 has 'blank_process' => (
13 is => 'ro',
14 isa => 'Bool',
15 lazy_build => 1,
16 );
17 18 __PACKAGE__->meta->make_immutable;
18  
19 43 ▶sub _build_blank_process {
Subroutine _build_blank_process: called CC=1 SCAR=0.0
20 43 my $self = shift;
21 18 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 43 return ${$self->class . '::BLANK'};
23 }
24  
25 55 ▶sub msg {
Subroutine msg: called CC=1 SCAR=0.0
Pod undocumented
26 55 my $self = shift;
27  
28 55 my $class = $self->class;
29 55 $class =~ s/^FormValidator::Nested::Validator:://;
30  
31 55 return $FormValidator::Nested::MESSAGES->{$class . '#' . $self->method};
32 }
33  
34 671 ▶sub _if_check {
Subroutine _if_check: called CC=13 SCAR=25.7
35 671 my $self = shift;
36 671 my $req = shift;
37  
38 671 ▶ if ( !$self->options->{if} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->options->{"if"}) 621 50 671
39 621 return 1;
40 }
41  
42 50 foreach my $condition ( @{$self->options->{if}} ) {
43 71 my ($method) = keys %{$condition};
44 71 ▶ if ( $method eq 'EMPTY' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($method eq 'EMPTY') { } 20 51 71
elsif ($method eq 'NOT_EMPTY') { } 19 32 51
elsif ($method eq 'EQUAL') { } 17 15 32
elsif ($method eq 'NOT_EQUAL') { } 15 0 15
45 20 my ($target) = values %{$condition};
46 20 my $value = $req->param($target);
47 20 ▶ if ( defined $value && $value ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne "") 9 11 20
Condition100%3/3
defined $value and $value ne ""
!ll&&!rl&&r
839
MC/DC100%2/2
defined $value and $value ne ""
defined $value $value ne ""
Truth table100%3/3
A and B
A= defined $valueB= $value ne ""
ABresult
0X0
100
111
48 9 return 0;
49 }
50 }
51 elsif ( $method eq 'NOT_EMPTY' ) {
52 19 my ($target) = values %{$condition};
53 19 my $value = $req->param($target);
54 19 ▶ if ( !defined $value || $value eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq "") 4 15 19
Condition66%2/3
not defined $value or $value eq ""
l!l&&r!l&&!r
0415
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
55 4 return 0;
56 }
57 }
58 elsif ( $method eq 'EQUAL' ) {
59 17 my $target = $condition->{EQUAL}->{target};
60 17 my $value = $condition->{EQUAL}->{value};
61 17 ▶ if ( $req->param($target) ne $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param($target) ne $value) 6 11 17
62 6 return 0;
63 }
64 }
65 elsif ( $method eq 'NOT_EQUAL' ) {
66 15 my $target = $condition->{NOT_EQUAL}->{target};
67 15 my $value = $condition->{NOT_EQUAL}->{value};
68 15 ▶ if ( $req->param($target) eq $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param($target) eq $value) 2 13 15
69 2 return 0;
70 }
71 }
72 }
73 29 return 1;
74 }
75  
76 671 ▶sub process_scalar {
Subroutine process_scalar: called CC=8 SCAR=20.9
Pod undocumented
77 671 my $self = shift;
78 671 my $req = shift;
79 671 my $value = shift;
80 671 ▶ my $param_name = shift || $self->param->key;
Condition66%2/3
shift() || $self->param->key
l!l&&r!l&&!r
66920
MC/DC0%0/2
shift() || $self->param->key
shift() $self->param->key
Truth table66%2/3
A || B
A= shift()B= $self->param->key
ABresult
1X1
011
000
81 671 my $parent_names = shift;
82  
83 671 ▶ return if !$self->_if_check($req);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_if_check($req) 21 650 671
84  
85 650 ▶ if ( (!defined $value || $value eq '') && !$self->blank_process ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($value) || $value eq "" and not $self->blank_process) 308 342 650
Condition100%6/6
!defined($value) || $value eq "" and not $self->blank_process
!ll&&!rl&&r
31131308
not defined $value or $value eq ""
l!l&&r!l&&!r
28257311
MC/DC100%3/3
!defined($value) || $value eq "" and not $self->blank_process
not defined $value $value eq "" not $self->blank_process
Truth table100%5/5
not(A) or B and not(C)
A= not defined $valueB= $value eq ""C= not $self->blank_process
ABCresult
00X0
1X00
0100
1X11
0111
86 308 return;
87 }
88  
89 342 ▶ $param_name ||= $self->param->key;
Condition33%1/3
$param_name ||= $self->param->key
l!l&&r!l&&!r
34200
MC/DC0%0/2
$param_name ||= $self->param->key
$param_name $self->param->key
Truth table33%1/3
A ||= B
A= $param_nameB= $self->param->key
ABresult
1X1
011
000
90 342 ▶ FormValidator::Nested::Result::Param->new({
Branch: 1 branch
BranchTrueFalseTotal
$self->method_ref->($value, $self->options, $req, $param_name) ? : 259 83 342
91 validator => $self,
92 has_error => $self->method_ref->($value, $self->options, $req, $param_name) ? 0 : 1,
93 key => $self->_make_param_name($parent_names, $param_name),
94 });
95 }
96  
97 29 ▶sub process_array {
Subroutine process_array: called CC=4 SCAR=13.9
Pod undocumented
98 29 my $self = shift;
99 29 my $req = shift;
100 29 my $values_ref = shift;
101 29 ▶ my $param_name = shift || $self->param->key;
Condition66%2/3
shift() || $self->param->key
l!l&&r!l&&!r
2090
MC/DC0%0/2
shift() || $self->param->key
shift() $self->param->key
Truth table66%2/3
A || B
A= shift()B= $self->param->key
ABresult
1X1
011
000
102 29 my $parent_names = shift;
103  
104 29 my $result = FormValidator::Nested::Result->new({});
105  
106 29 my @values = @$values_ref;
107 29 ▶ if ( !@values ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@values) 3 26 29
108 3 push @values, undef;
109 }
110  
111 29 foreach my $value ( @values ) {
112 39 $result->merge($self->process_scalar($req, $value, $param_name, $parent_names));
113 }
114  
115 29 return $result;
116 }
117  
118  
119 18 1;
120  
« Nested/Validator/File.pm ↑ Summary Nested/Profile/Param/Filter.pm »