NAME
opts - simple command line option parser
SYNOPSIS
# in script.pl
use opts;
opts my $foo => 'Int';
./script.pl --foo=4 # $foo => 4
./script.pl --foo 4 # $foo => 4
./script.pl -f=4 # $foo => 4
# in script.pl
opts my $foo => { 'Int', required => 1 },
my $bar => 'Int';
./script.pl --foo=3 --bar=4 # $foo => 3, $bar => 4
./script.pl --foo=4 # $foo => 4, $bar => undef
./script.pl --bar=4 # error!
# in script.pl
opts my $foo => {isa => 'Int', default => 3},
./script.pl --foo=4 # $foo => 4
./script.pl # $foo => 3
# in script.pl
opts my $foo => { isa => 'Int', alias => 'x|bar' };
./script.pl --foo=4 # $foo => 4
./script.pl --bar=4 # $foo => 4
./script.pl -f=4 # $foo => 4
./script.pl -x=4 # $foo => 4
DESCRIPTION
opts is DSL for command line option.
Options
isa
define option value type. see $opts::TYPE_CONSTRAINT.
if you need more type, see opts::coerce
required
define option value is required.
default
define options default value. If passed a coderef, it
will be executed if no value is provided on the command line.
alias
define option param's alias.
TYPES
- Str
- Int
- Num
- Bool
- ArrayRef
- HashRef
- Multiple
-
This subtype is based off of ArrayRef. It will attempt to split any values passed on the command line on a comma: that is,
[ "one", "two,three" ]
will become
[ "one", "two", "three" ].
opts::coerce
opts::coerce NewType => SrcType => generater;
ex)
opts::coerce DateTime => 'Str' => sub { DateTime->strptime("%Y-%m-%d", shift) };
opts my $date => 'DateTime';
$date->ymd; # => yyyy/mm/dd
AUTHOR
Kan Fushihara <kan.fushihara at gmail.com>
THANKS TO
Chris Weyl http://search.cpan.org/~rsrchboy/
SEE ALSO
http://github.com/tokuhirom/p5-args, Getopt::Long
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.