| 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), <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::String 0.061001; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use Term::CLI::L10N qw( loc ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use Types::Standard 1.000005 qw( Int ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use Moo 1.000001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 7 | ▶ | use namespace::clean 0.25; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | extends 'Term::CLI::Argument'; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 7 | has min_len => ( is => 'rw', isa => Int, clearer => 1, predicate => 1 ); | |||||||||||||||||||||||||||
| 36 | 7 | has max_len => ( is => 'rw', isa => Int, clearer => 1, predicate => 1 ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 36 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 36 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 36 | $self->clear_error; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 36 | ▶ | if ( !defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1 | return $self->set_error( loc('value must be defined') ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 35 | ▶ | if ( $self->has_min_len && length $value < $self->min_len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_min_len and length $value < $self->min_len
MC/DC100%2/2
$self->has_min_len and length $value < $self->min_len
$self->has_min_len
length $value < $self->min_len
Truth table100%3/3
A and B
A= $self->has_min_lenB= length $value < $self->min_len
| |||||||||||||||||||||||||||||
| 48 | 1 | return $self->set_error( | |||||||||||||||||||||||||||
| 49 | loc( "too short (min. length [_1])", $self->min_len ) ); | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 34 | ▶ | if ( $self->has_max_len && length $value > $self->max_len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_max_len and length $value > $self->max_len
MC/DC100%2/2
$self->has_max_len and length $value > $self->max_len
$self->has_max_len
length $value > $self->max_len
Truth table100%3/3
A and B
A= $self->has_max_lenB= length $value > $self->max_len
| |||||||||||||||||||||||||||||
| 52 | 1 | return $self->set_error( | |||||||||||||||||||||||||||
| 53 | loc( "too long (max. length [_1])", $self->max_len ) ); | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 33 | return $value; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 7 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||