Class::Usul::Options - Command line processing
use Class::Usul::Types qw( Str ); use Moo; use Class::Usul::Options; option 'my_attr' => is => 'ro', isa => 'Str', documentation => 'This appears in the option usage output', format => 's', short => 'a'; # OR # Causes Getopt::Long:Descriptive::Usage to produce it's new default output use Class::Usul::Options 'usage_conf' => { highlight => 'none', option_type => 'verbose', tabstop => 8 }; # OR # Causes Getopt::Long:Descriptive::Usage to produce it's old default output use Class::Usul::Options 'usage_conf' => { highlight => 'none', option_type => 'none', tabstop => 8 };
This is an extended clone of MooX::Options but is closer to MooseX::Getopt::Dashes
The option function accepts the following attributes in addition to those already supported by has
option
has
autosplit
If set split the option value using this string. Automatically creates a list of values
config
A hash reference passed as the third element in the list of tuples which forms the second argument to the describe options function
For example;
option 'my_attr' => is => 'ro', isa => 'Str', config => { hidden => 1 }, documentation => 'This appears in the option usage output', format => 's', short => 'a';
would prevent the option from appearing in the usage text
doc
Alias for documentation. Used to describe the attribute in the usage output
documentation
format
Format of the parameters, same as Getopt::Long::Descriptive
i : integer i@: array of integer s : string s@: array of string s%: hash of string f : float value
By default, it's a boolean value.
json
Boolean which if true means that the argument to the option is in JSON format and will be decoded as such
negateable
Applies only to boolean types. Means you can use --nooption-name to explicitly indicate false
--nooption-name
order
Specifies the order in which usage options appear. Attributes with no order value are alpha sorted
repeatable
Boolean which if true means that the option can appear multiple times on the command line
short
A single character that can be used as a short option, e.g. -s instead of the longer --long-option
-s
--long-option
Defines no attributes
default_options_config
Returns a list of keys and values. These are the defaults for the configuration options listed in "import"
import
Injects the option function into the caller
Accepts the following configuration options;
getopf_conf
An array reference of options passed to Getopt::Long::Configure, defaults to an empty list
prefer_commandline
A boolean which defaults to true. Prefer the command line values
protect_argv
A boolean which defaults to true. Localises the @ARGV variable before any processing takes place. Means that @ARGV will contain all of the passed command line arguments
@ARGV
show_defaults
A boolean which defaults to false. If true the default values are added to use options usage text output
skip_options
An array reference which defaults to an empty list. List of options to ignore when processing the attributes passed to the option subroutine
usage_conf
By default an empty hash reference. Attributes can be any of;
highlight
Defaults to bold which causes the option argument types to be displayed in a bold font. Set to none to turn off highlighting
bold
none
option_type
One of; none, short, or verbose. Determines the amount of option type information displayed by the option_text method. Defaults to short
verbose
tabstop
Defaults to 3. The number of spaces to expand the leading tab in the usage string
width
The total line width available for displaying usage text, defaults to 78
usage_opt
The usage option string passed as the first argument to the describe options function. Defaulted in "default_options_config" to Usage: %c %o [method]
Usage: %c %o [method]
None
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Usul. Patches are welcome
Larry Wall - For the Perl programming language
Peter Flanigan, <pjfl@cpan.org>
<pjfl@cpan.org>
Copyright (c) 2018 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
To install Class::Usul, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Usul
CPAN shell
perl -MCPAN -e shell install Class::Usul
For more information on module installation, please visit the detailed CPAN module installation guide.