Pad/Type/Int.pm

filter: Statementstmt 95.8% 46 / 48 Branchbran 91.6% 11 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 88.8% 8 / 9 Podpod 75.0% 3 / 4 totaltotal 93.5% 73 / 78 CC 9 SCAR 11.0
CC
9
Cov
95%
checkSpecKeys
5.0
checkFormat
4.0
coerce
2.0
CRAP 3.0
« Pad/Spec/Option.pm ↑ Summary Pad/Spec.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::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 class Getopt::Pad::Type::Int :isa(Getopt::Pad::Type::Number) :strict(params) {
7 23 ▶ use constant NAMES => ['i', 'int', 'integer'];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 23 ▶ use constant SPEC_KEYS => ['min', 'max', 'bigint'];
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 23 our $VERSION = '0.06';
11  
12 0 field $bigint :param :reader = 0;
13  
14 # Math::BigInt is loaded only for the options that ask for it.
15 0 ▶ ADJUST {
Subroutine bigint: not called CC=1 SCAR=1.2
Pod undocumented
16 require Math::BigInt if $bigint;
17 }
18  
19 # The bounds of a bigint option are compared exactly, so they must be
20 # integers themselves.
21 126 ▶ method checkSpecKeys :common (%args) {
Subroutine checkSpecKeys: called CC=5 SCAR=16.1
Pod documented
22 126 my $problem = $class->SUPER::checkSpecKeys(%args);
23 126 ▶ return $problem if defined $problem || !$args{bigint};
Branch: 1 branch
BranchTrueFalseTotal
if defined $problem or not $args{"bigint"} 124 2 126
Condition100%3/3
defined $problem or not $args{"bigint"}
l!l&&r!l&&!r
21222
MC/DC100%2/2
defined $problem or not $args{"bigint"}
defined $problem not $args{"bigint"}
Truth table100%3/3
A or not(B)
A= defined $problemB= not $args{"bigint"}
ABresult
1X1
011
000
24  
25 2 foreach my $bound (grep { defined $args{$_} } qw(min max)) {
26 1 ▶ return sprintf("%s must be an integer with bigint, not '%s'", $bound, $args{$bound}) if $args{$bound} !~ /\A[+-]?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{$bound} =~ /\A[+-]?[0-9]+\z/u 1 0 1
27 }
28 1 return undef;
29 23 }
30  
31 58 ▶ method checkFormat($value) {
Subroutine checkFormat: called CC=4 SCAR=13.9
Pod documented
32 58 ▶ return sprintf("'%s' is not an integer", $value) if $value !~ /\A[+-]?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A[+-]?[0-9]+\z/u 13 45 58
33 45 ▶ return undef if $bigint;
Branch: 1 branch
BranchTrueFalseTotal
if $bigint 3 42 45
34  
35 # Beyond Perl's integer range the value would become a rounded
36 # float, or Inf: it reads back as other digits than the given ones.
37 42 my $digits = $value =~ s/\A\+//r =~ s/\A(-?)0+(?=[0-9])/$1/r =~ s/\A-0\z/0/r;
38 42 ▶ return sprintf("'%s' is too large for an integer", $value) if ($value + 0) . '' ne $digits;
Branch: 1 branch
BranchTrueFalseTotal
if ($value + 0) . '' ne $digits 4 38 42
39 38 return undef;
40 23 }
41  
42 83 ▶ method coerce($value) {
Subroutine coerce: called CC=2 SCAR=6.9
Pod documented
43 83 ▶ return $bigint ? Math::BigInt->new($value) : $value + 0;
Branch: 1 branch
BranchTrueFalseTotal
$bigint ? : 8 75 83
44 23 }
45 }
46  
47 23 1;
48  
49 __END__
« Pad/Spec/Option.pm ↑ Summary Pad/Spec.pm »