Pad/Type/Number.pm

filter: Statementstmt 92.8% 52 / 56 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.1% 94 / 102 CC 11 SCAR 13.6
CC
11
Cov
94%
checkSpecKeys
6.1
check
6.0
min
1.3
CRAP 3.9
« Pad/Type/Path.pm ↑ Summary Pad/Parser.pm »
1 23 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 23 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 23 ▶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 23 ▶ use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 our $VERSION = '0.06';
10  
11 23 ▶ 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 0 ▶ 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 128 foreach my $bound (grep { defined $args{$_} } qw(min max)) {
19 41 ▶ 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 40 41
20 }
21 127 ▶ 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 126 127
Condition83%5/6
defined $args{"min"} and defined $args{"max"} and $args{"min"} > $args{"max"}
!ll&&!rl&&r
12601
defined $args{"min"} and defined $args{"max"}
!ll&&!rl&&r
89371
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 126 return undef;
23 23 }
24  
25 158 ▶ method glSuffix() { return '=s' }
Subroutine glSuffix: called CC=1 SCAR=0.0
Pod documented
26  
27 23 method checkFormat($value);
28  
29 3 ▶ method coerce($value) {
Subroutine coerce: called CC=1 SCAR=0.0
Pod documented
30 3 return $value + 0;
31 23 }
32  
33 # The bounds are compared as converted, so a subclass whose numbers are
34 # objects (a Math::BigInt) compares them exactly.
35 64 ▶ method check($value) {
Subroutine check: called CC=6 SCAR=17.9
Pod documented
36 64 my $problem = $self->checkFormat($value);
37 64 ▶ return $problem if defined $problem;
Branch: 1 branch
BranchTrueFalseTotal
if defined $problem 21 43 64
38  
39 43 my $number = $self->coerce($value);
40 43 ▶ return sprintf('%s is smaller than the minimum of %s', $value, $min) if defined $min && $number < $self->coerce($min);
Branch: 1 branch
BranchTrueFalseTotal
if defined $min and $number < $self->coerce($min) 3 40 43
Condition100%3/3
defined $min and $number < $self->coerce($min)
!ll&&!rl&&r
3643
MC/DC100%2/2
defined $min and $number < $self->coerce($min)
defined $min $number < $self->coerce($min)
Truth table100%3/3
A and B
A= defined $minB= $number < $self->coerce($min)
ABresult
0X0
100
111
41 40 ▶ return sprintf('%s is larger than the maximum of %s', $value, $max) if defined $max && $number > $self->coerce($max);
Branch: 1 branch
BranchTrueFalseTotal
if defined $max and $number > $self->coerce($max) 1 39 40
Condition100%3/3
defined $max and $number > $self->coerce($max)
!ll&&!rl&&r
3811
MC/DC100%2/2
defined $max and $number > $self->coerce($max)
defined $max $number > $self->coerce($max)
Truth table100%3/3
A and B
A= defined $maxB= $number > $self->coerce($max)
ABresult
0X0
100
111
42 39 return undef;
43 23 }
44 }
45  
46 23 1;
47  
48 __END__
« Pad/Type/Path.pm ↑ Summary Pad/Parser.pm »