lib/HTML/FormFu/Constraint/MinMaxFields.pm

filter: Statementstmt 100% 54 / 54 Branchbran 84.6% 22 / 26 Conditioncond 66.6% 8 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 87.2% 96 / 110 CC 19 SCAR 25.0
CC
19
Cov
91%
process
17.8
constrain_value
3.0
BEGIN
1.0
CRAP 12.2
« lib/HTML/FormFu/Model/HashRef.pm ↑ Summary lib/HTML/FormFu/Role/Render.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::MinMaxFields;
4 8 $HTML::FormFu::Constraint::MinMaxFields::VERSION = '2.09';
5 # ABSTRACT: Min/Max Multi-field Constraint
6  
7 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 extends 'HTML::FormFu::Constraint';
11  
12 8 with 'HTML::FormFu::Role::Constraint::Others';
13  
14 8 ▶use HTML::FormFu::Util qw( DEBUG_CONSTRAINTS debug );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 8 has minimum => (
17 is => 'rw',
18 alias => 'min',
19 traits => ['Chained'],
20 );
21  
22 8 has maximum => (
23 is => 'rw',
24 alias => 'max',
25 traits => ['Chained'],
26 );
27  
28 6 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 6 my $self = shift;
30  
31 6 $self->attach_errors_to_base(1);
32  
33 6 return;
34 8 };
35  
36 24 ▶sub process {
Subroutine process: called CC=17 SCAR=28.8
Pod undocumented
37 24 my ( $self, $params ) = @_;
38 24 my $count = 0;
39  
40 # check when condition
41 24 ▶ return if !$self->_process_when($params);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_process_when($params) 1 23 24
42  
43 # others are needed
44 23 my $others = $self->others;
45 23 ▶ return if !defined $others;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $others 0 23 23
46  
47 # get field names to check
48 23 my @names = ( $self->nested_name );
49 23 ▶ push @names, ref $others ? @{$others} : $others;
Branch: 1 branch
BranchTrueFalseTotal
ref $others ? : 22 1 23
50  
51 # get min/max values
52 23 ▶ my $min
Branch: 1 branch
BranchTrueFalseTotal
defined $self->minimum ? : 22 1 23
53 = defined $self->minimum
54 ? $self->minimum
55 : 1;
56  
57 23 ▶ my $max
Branch: 1 branch
BranchTrueFalseTotal
defined $self->maximum ? : 22 1 23
58 = defined $self->maximum
59 ? $self->maximum
60 : scalar @names;
61  
62 23 for my $name (@names) {
63 86 my $value = $self->get_nested_hash_value( $params, $name );
64  
65 86 ▶ DEBUG_CONSTRAINTS && debug( OTHER_NAME => $name );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("OTHER_NAME", $name) 0 86 86
66 86 ▶ DEBUG_CONSTRAINTS && debug( VALUE => $value );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("VALUE", $value) 0 86 86
67  
68 86 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 4 82 86
69 4 my @errors = eval { $self->constrain_values( $value, $params ) };
70  
71 4 ▶ if ( !@errors && !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@errors or $@) 4 0 4
Condition33%1/3
@errors or $@
l!l&&r!l&&!r
004
MC/DC0%0/2
@errors or $@
@errors $@
Truth table33%1/3
A or B
A= @errorsB= $@
ABresult
1X1
011
000
72 4 $count++;
73 }
74 }
75 else {
76 82 my $ok = eval { $self->constrain_value($value) };
77  
78 82 ▶ if ( $ok && !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and not $@) 37 45 82
Condition66%2/3
$ok and not $@
!ll&&!rl&&r
45037
MC/DC50%1/2
$ok and not $@
$ok not $@
Truth table66%2/3
A and not(B)
A= $okB= not $@
ABresult
0X0
100
111
79 37 $count++;
80 }
81 }
82 }
83  
84 23 ▶ my $pass = ( $count < $min || $count > $max ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$count < $min || $count > $max ? : 7 16 23
Condition66%2/3
$count < $min or $count > $max
l!l&&r!l&&!r
0716
MC/DC50%1/2
$count < $min or $count > $max
$count < $min $count > $max
Truth table66%2/3
A or B
A= $count < $minB= $count > $max
ABresult
1X1
011
000
85  
86 23 ▶ return $self->mk_errors(
Branch: 1 branch
BranchTrueFalseTotal
$pass ? : 16 7 23
87 { pass => $pass,
88 failed => $pass ? [] : \@names,
89 names => \@names,
90 } );
91 }
92  
93 # return true if value is defined
94 87 ▶sub constrain_value {
Subroutine constrain_value: called CC=3 SCAR=11.0
Pod undocumented
95 87 my ( $self, $value ) = @_;
96  
97 87 ▶ return 0 if !defined $value || $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 45 42 87
Condition100%3/3
not defined $value or $value eq ""
l!l&&r!l&&!r
83742
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
98  
99 42 return 1;
100 }
101  
102 8 __PACKAGE__->meta->make_immutable;
103  
104 8 1;
105  
106 __END__
« lib/HTML/FormFu/Model/HashRef.pm ↑ Summary lib/HTML/FormFu/Role/Render.pm »