| 1 | #============================================================================= | ||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||
| 3 | # Module: Term::CLI::Argument::String | ||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||
| 5 | # Description: Class for arbitrary string 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 | 1 | ▶ | use 5.014_001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | package Term::CLI::Argument::String 0.051003 { | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Modern::Perl 1.20140107; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Term::CLI::L10N; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Types::Standard 1.000005 qw( Int ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use Moo 1.000001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use namespace::clean 0.25; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | extends 'Term::CLI::Argument'; | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | has min_len => ( is => 'rw', isa => Int, clearer => 1, predicate => 1 ); | ||||||||||||||||||||||||||||||||
| 37 | has max_len => ( is => 'rw', isa => Int, clearer => 1, predicate => 1 ); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | sub validate { | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
validate: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | $self->set_error(''); | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->set_error(loc('value must be defined')); | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($self->has_min_len && length $value < $self->min_len) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->has_min_len and length $value < $self->min_len
MC/DC0%0/2
$self->has_min_len and length $value < $self->min_len
$self->has_min_len
length $value < $self->min_len
Truth table0%0/3
A and B
A= $self->has_min_lenB= length $value < $self->min_len
| |||||||||||||||||||||||||||||||||
| 49 | 0 | return $self->set_error( | |||||||||||||||||||||||||||||||
| 50 | loc("too short (min. length [_1])", $self->min_len) | ||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | ▶ | elsif ($self->has_max_len && length $value > $self->max_len) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->has_max_len and length $value > $self->max_len
MC/DC0%0/2
$self->has_max_len and length $value > $self->max_len
$self->has_max_len
length $value > $self->max_len
Truth table0%0/3
A and B
A= $self->has_max_lenB= length $value > $self->max_len
| |||||||||||||||||||||||||||||||||
| 54 | 0 | return $self->set_error( | |||||||||||||||||||||||||||||||
| 55 | loc("too long (max. length [_1])", $self->max_len) | ||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | 0 | return $value; | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 1; | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||||||