1Getopt::Usaginator(3) User Contributed Perl DocumentationGetopt::Usaginator(3)
2
3
4

NAME

6       Getopt::Usaginator - Conjure up a usage function for your applications
7

VERSION

9       version 0.0012
10

SYNOPSIS

12           use Getopt::Usaginator <<_END_;
13
14               Usage: xyzzy <options>
15
16               --derp          Derp derp derp
17               --durp          Durp durp durp
18               -h, --help      This usage
19
20           _END_
21
22           # The 'usage' subroutine is now installed
23
24           ...
25
26           $options = parse_options( @ARGV ); # Not supplied by Usaginator
27
28           usage if $options{help}; # Print usage and exit with status 0
29
30           if ( ! $options{derp} ) {
31               # Print warning and usage and exit with status -1
32               usage "You should really derp";
33           }
34
35           if ( $options{durp} ) {
36               # Print warning and usage and exit with status 2
37               usage 2 => "--durp is not ready yet";
38           }
39
40           ...
41
42           usage 3 # Print usage and exit with status 3
43

DESCRIPTION

45       Getopt::Usaginator is a tool for creating a handy usage subroutine for
46       commandline applications
47
48       It does not do any option parsing, but is best paired with Getopt::Long
49       or any of the other myriad of option parsers
50

USAGE

52   use Getopt::Usaginator <usage>
53       Install a "usage" subroutine configured with the <usage> text
54
55   $code = Getopt::Usaginator->usaginator( <usage> )
56       Return a subroutine configured with the <usage> text
57
58   ...
59       More advanced usage is possible, peek under the hood for more
60       information
61
62           perldoc -m Getopt::Usaginator
63
64       An example:
65
66           use Getopt::Usaginator
67               # Called with the error
68               error => sub { ... },
69               # Called when usage printing is needed
70               usage => sub { ... },
71               ...
72           ;
73

An example with Getopt::Long parsing

75           use Getopt::Usaginator ...
76
77           sub run {
78               my $self = shift;
79               my @arguments = @_;
80
81               usage 0 unless @arguments;
82
83               my ( $help );
84               {
85                   local @ARGV = @arguments;
86                   GetOptions(
87                       'help|h|?' => \$help,
88                   );
89               }
90
91               usage 0 if $help;
92
93               ...
94           }
95

AUTHOR

97         Robert Krimen <robertkrimen@gmail.com>
98
100       This software is copyright (c) 2010 by Robert Krimen.
101
102       This is free software; you can redistribute it and/or modify it under
103       the same terms as the Perl 5 programming language system itself.
104
105
106
107perl v5.34.0                      2022-01-21             Getopt::Usaginator(3)
Impressum