| 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
Condition100%3/3
defined $problem or not $args{"bigint"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 33 | 45 | ▶ | return undef if $bigint; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | 23 | } | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 23 | 1; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||