Term::CLI::Argument::Bool - class for "boolean" arguments in Term::CLI
version 0.04005
use Term::CLI::Argument::Bool; # Case-insensitive booleans (default) my $arg = Term::CLI::Argument::Bool->new( name => 'arg1', ignore_case => 1, # default ); $arg->validate( 'true' ); # -> returns 1 $arg->validate( 'tRuE' ); # -> returns 1 $arg->validate( '1' ); # -> returns 1 $arg->validate( 'false' ); # -> returns 0 $arg->validate( 'FaLsE' ); # -> returns 0 $arg->validate( '0' ); # -> returns 0 $arg->validate( 'never' ); # -> returns undef, sets error. # Case-sensitive booleans $arg = Term::CLI::Argument::Bool->new( name => 'arg1', ignore_case => 0, ); $arg->validate( 'tRuE' ); # -> returns undef, sets error. $arg->validate( 'FaLsE' ); # -> returns undef, sets error. # Alternative booleans $arg = Term::CLI::Argument::Bool->new( name => 'arg1', true_values => ['on', 'yes'], false_values => ['off', 'no'], ); $arg->validate( 'on' ); # -> returns 1 $arg->validate( 'off' ); # -> returns 0 # Abbreviation $arg->validate( 'y' ); # -> returns 1 $arg->validate( 'n' ); # -> returns 0 $arg->validate( 'o' ); # ambiguous -> returns undef, sets error.
Class for "boolean" string arguments in Term::CLI(3p).
This class inherits from the Term::CLI::Argument(3p) class.
By default, the valid strings for a boolean are:
true
1
A true value.
false
0
A false value.
By default, the object's validate() and complete() methods ignore case, so FAlsE validates as "false", and TR will have a completion of TRue.
FAlsE
TR
TRue
Set the ignore_case flag to 0 to do case-sensitive matching.
The validate method accepts abbreviations as long as they are uniquely identifying either one or more "true" values or one or more "false" values.
For example, if you specify the following:
Then the string o will not validate since it matches both a "true" value (on) and a "false" value (off). On the other hand, the string n will validate, for although it matches both never and no, those values are both "false" values, so there is no ambiguity.
o
on
off
n
never
no
Term::CLI::Argument(3p).
None.
See also Term::CLI::Argument(3p).
Additional attributes:
List of values that are considered to be "true". Default is ['true', '1'].
['true', '1']
List of values that are considered to be "false". Default is ['false', '0'].
['false', '0']
Whether or not matching should ignore case. Default is 1 (so True and FALSE are valid as well).
True
FALSE
Get or set the ignore_case flag.
ignore_case
Get or set the list of strings that denote a "true" value.
Get or set the list of strings that denote a "false" value.
The following methods are added or overloaded:
Validate Str to see if it is a uniquely "true" or "false" value. Return 1 if it is a "true" value, 0 if it is a "false" value.
If the true/false validity cannot be determined, the object's error attribute is set and undef is returned.
error
undef
Return a list of possible completions for Str. If ignore_case is true, then values like FA will result in ('FAlse').
FA
('FAlse')
Term::CLI::Argument(3p), Term::CLI(3p).
Steven Bakker <sbakker@cpan.org>, 2018.
Copyright (c) 2018 Steven Bakker
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See "perldoc perlartistic."
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Term::CLI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::CLI
CPAN shell
perl -MCPAN -e shell install Term::CLI
For more information on module installation, please visit the detailed CPAN module installation guide.