| 1 | #============================================================================= | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Module: Term::CLI::Argument | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Description: Generic parent class for arguments in Term::CLI | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Author: Steven Bakker (SBAKKER), <sbakker@cpan.org> | ||||||||||||||||||||||||||||
| 8 | # Created: 22/01/18 | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Copyright (c) 2018 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 | 4 | ▶ | use 5.014_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | package Term::CLI::Argument 0.051003 { | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use Modern::Perl 1.20140107; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use Moo 1.000001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | ▶ | use Term::CLI::L10N; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use Types::Standard 1.000005 qw( Int ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | use namespace::clean 0.25; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | extends 'Term::CLI::Element'; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | has min_occur => ( is => 'rw', isa => Int, default => sub{1}); | ||||||||||||||||||||||||||||
| 37 | has max_occur => ( is => 'rw', isa => Int, default => sub{1}); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub BUILD { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 41 | # Allow "occur" as a shortcut for min/max setting. | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (defined $args->{occur}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->min_occur($args->{occur}); | |||||||||||||||||||||||||||
| 44 | 0 | $self->max_occur($args->{occur}); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub occur { | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $self = shift @_; | ||||||||||||||||||||||||||
|
Subroutine
occur: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | my $min = shift @_; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $max = @_ ? shift @_ : $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->min_occur($min); | |||||||||||||||||||||||||||
| 54 | 0 | $self->max_occur($max); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | return ($self->min_occur, $self->max_occur); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub type { | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
type: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 61 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($class eq 'Term::CLI::Argument') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | return 'GENERIC'; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | return $class =~ s/^Term::CLI::Argument:://r; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | before validate => sub { $_[0]->set_error('') }; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub validate { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
validate: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | $self->set_error(''); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (!defined $value or $value eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $value or $value eq ""
MC/DC0%0/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table0%0/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||
| 75 | 0 | return $self->set_error(loc('value cannot be empty')); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 0 | return $value; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||