1opts(3)               User Contributed Perl Documentation              opts(3)
2
3
4

NAME

6       opts - simple command line option parser
7

SYNOPSIS

9         # in script.pl
10         use opts;
11
12         opts my $foo => 'Int';
13
14         ./script.pl --foo=4 # $foo => 4
15         ./script.pl --foo 4 # $foo => 4
16         ./script.pl -f=4    # $foo => 4
17
18         # in script.pl
19         opts my $foo => { 'Int', required => 1 },
20              my $bar => 'Int';
21
22         ./script.pl --foo=3 --bar=4 # $foo => 3, $bar => 4
23         ./script.pl --foo=4         # $foo => 4, $bar => undef
24         ./script.pl --bar=4         # error!
25
26         # in script.pl
27         opts my $foo => {isa => 'Int', default => 3},
28
29         ./script.pl --foo=4     # $foo => 4
30         ./script.pl             # $foo => 3
31
32         # in script.pl
33         opts my $foo => { isa => 'Int', alias => 'x|bar' };
34
35         ./script.pl --foo=4 # $foo => 4
36         ./script.pl --bar=4 # $foo => 4
37         ./script.pl -f=4    # $foo => 4
38         ./script.pl -x=4    # $foo => 4
39

DESCRIPTION

41       opts is DSL for command line option.
42

Options

44         isa
45            define option value type. see $opts::TYPE_CONSTRAINT.
46            if you need more type, see opts::coerce
47
48         required
49           define option value is required.
50
51         default
52           define options default value.
53
54         alias
55           define option param's alias.
56

opts::coerce

58         opts::coerce NewType => SrcType => generater;
59
60         ex)
61           opts::coerce DateTime => 'Str' => sub { DateTime->strptime("%Y-%m-%d", shift) };
62
63           opts my $date => 'DateTime';
64
65           $date->ymd; # => yyyy/mm/dd
66

AUTHOR

68       Kan Fushihara <kan.fushihara at gmail.com>
69

SEE ALSO

71       http://github.com/tokuhirom/p5-args
72       <http://github.com/tokuhirom/p5-args>, Getopt::Long
73

LICENSE

75       This library is free software; you can redistribute it and/or modify it
76       under the same terms as Perl itself.
77
78
79
80perl v5.12.0                      2009-11-16                           opts(3)
Impressum