CLI/Argument/Number.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 14 / 14 Conditioncond 100% 15 / 15 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 90 / 90 CC 13 SCAR 21.3
CC
13
Cov
100%
validate
13.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.4
« CLI.pm ↑ Summary CLI/L10N/nl.pm »
1 #=============================================================================
2 #
3 # Module: Term::CLI::Argument::Number
4 #
5 # Description: Base class for numerical arguments in Term::CLI
6 #
7 # Author: Steven Bakker (SBAKKER), <cpanman@monkey-mind.net>
8 # Created: 22/01/18
9 #
10 # Copyright (c) 2018-2022 Steven Bakker
11 #
12 # This module is free software; you can redistribute it and/or modify
13 # it under the same terms as Perl itself. See "perldoc perlartistic."
14 #
15 # This software is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 #
19 #=============================================================================
20  
21 package Term::CLI::Argument::Number 0.061001;
22  
23 9 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 9 ▶use Term::CLI::L10N qw( loc );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 9 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 9 ▶use Moo 1.000001;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 9 ▶use namespace::clean 0.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 9 extends 'Term::CLI::Argument';
33  
34 9 has min => ( is => 'rw', clearer => 1, predicate => 1 );
35 9 has max => ( is => 'rw', clearer => 1, predicate => 1 );
36 3 ▶has inclusive => ( is => 'rw', default => sub {1} );
Subroutine __ANON__: called CC=1 SCAR=0.0
37  
38 1 ▶sub coerce_value {
Subroutine coerce_value: called CC=1 SCAR=0.0
Pod documented
39 1 croak "coerce_value() has not been overloaded";
40 }
41  
42 32 ▶sub validate {
Subroutine validate: called CC=13 SCAR=25.6
Pod documented
43 32 my ( $self, $value ) = @_;
44  
45 32 ▶ if ( !defined $value || length($value) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or length $value == 0) 3 29 32
Condition100%3/3
not defined $value or length $value == 0
l!l&&r!l&&!r
2129
MC/DC100%2/2
not defined $value or length $value == 0
not defined $value length $value == 0
Truth table100%3/3
not(A) or B
A= not defined $valueB= length $value == 0
ABresult
1X1
011
000
46 3 return $self->set_error( loc('not a valid number') );
47 }
48  
49 29 my $num = $self->coerce_value($value);
50  
51 28 ▶ if ( !defined $num ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $num) 2 26 28
52 2 return $self->set_error( loc('not a valid number') );
53 }
54  
55 26 ▶ if ( $self->inclusive ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inclusive) { } 18 8 26
56 18 ▶ if ( $self->has_min && $num < $self->min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_min and $num < $self->min) 3 15 18
Condition100%3/3
$self->has_min and $num < $self->min
!ll&&!rl&&r
693
MC/DC100%2/2
$self->has_min and $num < $self->min
$self->has_min $num < $self->min
Truth table100%3/3
A and B
A= $self->has_minB= $num < $self->min
ABresult
0X0
100
111
57 3 return $self->set_error( loc('too small') );
58 }
59 15 ▶ if ( $self->has_max && $num > $self->max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_max and $num > $self->max) 3 12 15
Condition100%3/3
$self->has_max and $num > $self->max
!ll&&!rl&&r
573
MC/DC100%2/2
$self->has_max and $num > $self->max
$self->has_max $num > $self->max
Truth table100%3/3
A and B
A= $self->has_maxB= $num > $self->max
ABresult
0X0
100
111
60 3 return $self->set_error( loc('too large') );
61 }
62 }
63 else {
64 8 ▶ if ( $self->has_min && $num <= $self->min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_min and $num <= $self->min) 3 5 8
Condition100%3/3
$self->has_min and $num <= $self->min
!ll&&!rl&&r
233
MC/DC100%2/2
$self->has_min and $num <= $self->min
$self->has_min $num <= $self->min
Truth table100%3/3
A and B
A= $self->has_minB= $num <= $self->min
ABresult
0X0
100
111
65 3 return $self->set_error( loc('too small') );
66 }
67 5 ▶ if ( $self->has_max && $num >= $self->max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_max and $num >= $self->max) 3 2 5
Condition100%3/3
$self->has_max and $num >= $self->max
!ll&&!rl&&r
113
MC/DC100%2/2
$self->has_max and $num >= $self->max
$self->has_max $num >= $self->max
Truth table100%3/3
A and B
A= $self->has_maxB= $num >= $self->max
ABresult
0X0
100
111
68 3 return $self->set_error( loc('too large') );
69 }
70 }
71 14 return $num;
72 }
73  
74 9 1;
75  
76 __END__
« CLI.pm ↑ Summary CLI/L10N/nl.pm »