CLI/Argument.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 100% 79 / 79 CC 7 SCAR 6.1
CC
7
Cov
100%
occur
3.0
validate
3.0
BUILD
2.0
CRAP 1.8
« CLI/L10N.pm ↑ Summary CLI/Base.pm »
1 #=============================================================================
2 #
3 # Module: Term::CLI::Argument
4 #
5 # Description: Generic parent class for 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 0.061001;
22  
23 19 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 19 ▶use Moo 1.000001;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 19 ▶use Term::CLI::L10N qw( loc );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 19 ▶use Types::Standard 1.000005 qw( Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 19 ▶use namespace::clean 0.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 19 extends 'Term::CLI::Element';
35  
36 43 ▶has min_occur => ( is => 'rw', isa => Int, default => sub {1} );
Subroutine __ANON__: called CC=1 SCAR=0.0
37 39 ▶has max_occur => ( is => 'rw', isa => Int, default => sub {1} );
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39 49 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
40 49 my ( $self, $args ) = @_;
41  
42 # Allow "occur" as a shortcut for min/max setting.
43 49 ▶ if ( defined $args->{occur} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"occur"}) 6 43 49
44 6 $self->min_occur( $args->{occur} );
45 6 $self->max_occur( $args->{occur} );
46 }
47 49 return;
48 }
49  
50 5 ▶sub occur {
Subroutine occur: called CC=3 SCAR=11.0
Pod documented
51 5 my ( $self, @args ) = @_;
52 5 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 3 2 5
53 3 my $min = shift @args;
54 3 ▶ my $max = @args ? shift @args : $min;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 2 3
55 3 $self->min_occur($min);
56 3 $self->max_occur($max);
57 }
58 5 return ( $self->min_occur, $self->max_occur );
59 }
60  
61 10 ▶sub type {
Subroutine type: called CC=2 SCAR=6.9
Pod documented
62 10 my ($self) = @_;
63 10 my $class = ref $self;
64 10 ▶ if ( $class eq 'Term::CLI::Argument' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Term::CLI::Argument") 1 9 10
65 1 return 'GENERIC';
66 }
67 9 return $class =~ s/\A Term::CLI::Argument:://rxms;
68 }
69  
70 41 ▶before validate => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 41 my ($self) = @_;
72 41 $self->clear_error;
73 6 };
74  
75 41 ▶sub validate {
Subroutine validate: called CC=3 SCAR=11.0
Pod documented
76 54 my ( $self, $value, $state ) = @_;
77  
78 54 ▶ if ( not defined $value or $value eq q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq "") 9 32 41
Condition100%3/3
not defined $value or $value eq ""
l!l&&r!l&&!r
5432
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
79 22 return $self->set_error( loc('value cannot be empty') );
80 }
81 45 return $value;
82 }
83  
84 6 1;
85  
86 __END__
« CLI/L10N.pm ↑ Summary CLI/Base.pm »