Actions Status MetaCPAN Release

NAME

Getopt::EX::Hashed - Hash store object automation

VERSION

Version 0.9919

SYNOPSIS

use App::foo;
App::foo->new->run();

package App::foo;

use Getopt::EX::Hashed;
has start  => ( spec => "=i s begin", default => 1 );
has end    => ( spec => "=i e" );
has file   => ( spec => "=s", is => 'rw', re => qr/^(?!\.)/ );
has score  => ( spec => '=i', min => 0, max => 100 );
has answer => ( spec => '=i', must => sub { $_[1] == 42 } );
no  Getopt::EX::Hashed;

sub run {
    my $app = shift;
    use Getopt::Long;
    $app->getopt or pod2usage();
    if ($app->{start}) {
        ...

DESCRIPTION

Getopt::EX::Hashed is a module to automate a hash object to store command line option values. Major objective of this module is integrating initialization and specification into single place. Module name shares Getopt::EX, but it works independently from other modules included in Getopt::EX, so far.

In the current implementation, using Getopt::Long, or compatible module such as Getopt::EX::Long is assumed. It is configurable, but no other module is supported now.

Accessor methods are automatically generated when appropriate parameter is given.

FUNCTION

has

Declare option parameters in a form of:

has option_name => ( param => value, ... );

If array reference is given, multiple names can be declared at once.

has [ 'left', 'right' ] => ( spec => "=i" );

If the number of parameter is not even, first parameter is taken as spec. So the above example can be written as this:

has [ 'left', 'right' ] => "=i";

If the name start with plus (+), given parameters are added to current value.

has '+left' => ( default => 1 );

Following parameters are available.

Following parameters are all for data validation. First must is a generic validator and can implement anything. Others are shorthand for common rules.

METHOD

SEE ALSO

Getopt::Long

Getopt::EX, Getopt::EX::Long

AUTHOR

Kazumasa Utashiro

COPYRIGHT

The following copyright notice applies to all the files provided in this distribution, including binary files, unless explicitly noted otherwise.

Copyright 2021 Kazumasa Utashiro

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.