Name

Class::Usul::Options - Command line processing

Synopsis

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 };

Description

This is an extended clone of MooX::Options but is closer to MooseX::Getopt::Dashes

Configuration and Environment

The option function accepts the following attributes in addition to those already supported by 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

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

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

Defines no attributes

Subroutines/Methods

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

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

option_type

One of; none, short, or verbose. Determines the amount of option type information displayed by the option_text method. Defaults to short

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]

Diagnostics

None

Dependencies

Sub::Install

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

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

Acknowledgements

Larry Wall - For the Perl programming language

Author

Peter Flanigan, <pjfl@cpan.org>

License and Copyright

Copyright (c) 2016 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