Getopt-Yath

 view release on metacpan or  search on metacpan

lib/Getopt/Yath/Tutorial.pm  view on Meta::CPAN

expands the glob.

    option dev_libs => (
        type        => 'AutoPathList',
        short       => 'D',
        name        => 'dev-lib',
        autofill    => sub { 'lib', 'blib/lib', 'blib/arch' },
        description => 'Add dev library paths (default: lib, blib/lib, blib/arch)',
    );

Usage:

    -D              # adds lib, blib/lib, blib/arch
    -D=lib          # adds just lib
    -D='lib/*'      # adds all matches

=head2 BoolMap

Matches a pattern of options dynamically, building a hash of boolean values.
Requires a C<pattern> attribute with a capture group.

    option features => (
        type        => 'BoolMap',
        pattern     => qr/feature-(.+)/,
        description => 'Toggle features on or off',
    );

Usage:

    --feature-color         # {color => 1}
    --feature-unicode       # {unicode => 1}
    --no-feature-color      # {color => 0}

The pattern is embedded into C<< qr/^--(no-)?$pattern$/ >> automatically. Each
captured key gets a true or false value depending on the C<--no-> prefix.

=head1 COMMON OPTION ATTRIBUTES

These attributes work across all option types.

=head2 short

A single-character alias for the option:

    option jobs => (
        type  => 'Scalar',
        short => 'j',
        ...
    );

    # -j4   --jobs 4   --jobs=4   -j 4

=head2 alt and alt_no

Alternate long names for the option:

    option use_stream => (
        type   => 'Bool',
        alt    => ['stream'],       # --stream also works
        alt_no => ['TAP'],          # --TAP is equivalent to --no-use-stream
        description => 'Use streaming format instead of TAP',
    );

=head2 prefix

Adds a prefix to the option name. Especially useful in option groups:

    option_group {group => 'db', category => 'Database', prefix => 'db'} => sub {

        option host => (
            type => 'Scalar',
            description => 'Database host',
        );

        option port => (
            type    => 'Scalar',
            default => 5432,
            description => 'Database port',
        );

    };

    # --db-host myhost --db-port 3306

The values are still accessed as C<< $settings->db->host >> and
C<< $settings->db->port >> -- the prefix only affects the command-line form.

=head2 field and name

By default, the option title determines both the field name (underscores) and
the CLI name (dashes). You can override either:

    option test_args => (
        type  => 'List',
        field => 'args',        # $settings->tests->args (not test_args)
        alt   => ['test-arg'],
        ...
    );

=head2 default

A value used when the option is not provided on the command line and not set
via an environment variable:

    option timeout => (
        type    => 'Scalar',
        default => 60,
        description => 'Timeout in seconds',
    );

    # Can also be a coderef:
    option search => (
        type    => 'PathList',
        default => sub { './t', './t2' },
        ...
    );

=head2 initialize

Set an initial value before parsing begins. This differs from C<default> in
that C<default> is applied after parsing if the option was never set, while



( run in 1.743 second using v1.01-cache-2.11-cpan-ceb78f64989 )