opts.3pm

Langue: en

Version: 2009-11-16 (fedora - 01/12/10)

Section: 3 (Bibliothèques de fonctions)

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.
 
   alias
     define option param's alias.
 
 

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>

SEE ALSO

http://github.com/tokuhirom/p5-args <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.