opts - simple command line option parser
# 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
opts is DSL for command line option.
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. alias define option param's alias.
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
Kan Fushihara <kan.fushihara at gmail.com>
http://github.com/tokuhirom/p5-args, Getopt::Long
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install opts, copy and paste the appropriate command in to your terminal.
cpanm
cpanm opts
CPAN shell
perl -MCPAN -e shell install opts
For more information on module installation, please visit the detailed CPAN module installation guide.