Pad/Type/Number.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 100% 10 / 10 Conditioncond 91.6% 11 / 12 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 81.8% 9 / 11 Podpod 100% 6 / 6 totaltotal 92.0% 93 / 101 CC 11 SCAR 13.6
CC
11
Cov
94%
checkSpecKeys
6.1
check
6.0
min
1.3
CRAP 3.9
« Pad/Config.pm ↑ Summary Pad/Parser.pm »
1 18 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 18 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 18 ▶use Getopt::Pad::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 class Getopt::Pad::Type::Number :isa(Getopt::Pad::Type) :abstract {
7 18 ▶ use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 our $VERSION = '0.05';
10  
11 18 ▶ use constant SPEC_KEYS => ['min', 'max'];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 field $min :param :reader = undef;
14 0 ▶ field $max :param :reader = undef;
Subroutine min: not called CC=1 SCAR=2.6
Pod documented
15  
16 # A bound that is not a number, or an empty range, is a spec mistake.
17 112 ▶ method checkSpecKeys :common (%args) {
Subroutine checkSpecKeys: called CC=6 SCAR=18.1
Subroutine max: not called CC=1 SCAR=0.2
Pod documented
Pod documented
18 112 foreach my $bound (grep { defined $args{$_} } qw(min max)) {
19 39 ▶ return sprintf("%s must be a number, not '%s'", $bound, $args{$bound}) if !looks_like_number($args{$bound});
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($args{$bound}) 1 38 39
20 }
21 111 ▶ return sprintf("min %s is larger than max %s", $args{min}, $args{max}) if defined $args{min} && defined $args{max} && $args{min} > $args{max};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"min"} and defined $args{"max"} and $args{"min"} > $args{"max"} 1 110 111
Condition83%5/6
defined $args{"min"} and defined $args{"max"} and $args{"min"} > $args{"max"}
!ll&&!rl&&r
11001
defined $args{"min"} and defined $args{"max"}
!ll&&!rl&&r
74361
MC/DC66%2/3
defined $args{"min"} and defined $args{"max"} and $args{"min"} > $args{"max"}
defined $args{"min"} defined $args{"max"} $args{"min"} > $args{"max"}
Truth table75%3/4
A and B and C
A= defined $args{"min"}B= defined $args{"max"}C= $args{"min"} > $args{"max"}
ABCresult
0XX0
10X0
1100
1111
22 110 return undef;
23 18 }
24  
25 137 ▶ method glSuffix() { return '=s' }
Subroutine glSuffix: called CC=1 SCAR=0.0
Pod documented
26  
27 18 method checkFormat($value);
28  
29 29 ▶ method coerce($value) {
Subroutine coerce: called CC=1 SCAR=0.0
Pod documented
30 29 return $value + 0;
31 18 }
32  
33 47 ▶ method check($value) {
Subroutine check: called CC=6 SCAR=17.9
Pod documented
34 47 my $problem = $self->checkFormat($value);
35 47 ▶ return $problem if defined $problem;
Branch: 1 branch
BranchTrueFalseTotal
if defined $problem 14 33 47
36 33 ▶ return sprintf('%s is smaller than the minimum of %s', $value, $min) if defined $min && $value < $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min and $value < $min 2 31 33
Condition100%3/3
defined $min and $value < $min
!ll&&!rl&&r
2832
MC/DC100%2/2
defined $min and $value < $min
defined $min $value < $min
Truth table100%3/3
A and B
A= defined $minB= $value < $min
ABresult
0X0
100
111
37 31 ▶ return sprintf('%s is larger than the maximum of %s', $value, $max) if defined $max && $value > $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max and $value > $max 1 30 31
Condition100%3/3
defined $max and $value > $max
!ll&&!rl&&r
2911
MC/DC100%2/2
defined $max and $value > $max
defined $max $value > $max
Truth table100%3/3
A and B
A= defined $maxB= $value > $max
ABresult
0X0
100
111
38 30 return undef;
39 18 }
40 }
41  
42 18 1;
43  
44 __END__
« Pad/Config.pm ↑ Summary Pad/Parser.pm »