Debian Codegraph @

README

raw
1 NAME
2 Getopt::Usaginator - Conjure up a usage function for your applications
3
4 VERSION
5 version 0.0012
6
7 SYNOPSIS
8 use Getopt::Usaginator <<_END_;
9
10 Usage: xyzzy <options>
11
12 --derp Derp derp derp
13 --durp Durp durp durp
14 -h, --help This usage
15
16 _END_
17
18 # The 'usage' subroutine is now installed
19
20 ...
21
22 $options = parse_options( @ARGV ); # Not supplied by Usaginator
23
24 usage if $options{help}; # Print usage and exit with status 0
25
26 if ( ! $options{derp} ) {
27 # Print warning and usage and exit with status -1
28 usage "You should really derp";
29 }
30
31 if ( $options{durp} ) {
32 # Print warning and usage and exit with status 2
33 usage 2 => "--durp is not ready yet";
34 }
35
36 ...
37
38 usage 3 # Print usage and exit with status 3
39
40 DESCRIPTION
41 Getopt::Usaginator is a tool for creating a handy usage subroutine for
42 commandline applications
43
44 It does not do any option parsing, but is best paired with Getopt::Long
45 or any of the other myriad of option parsers
46
47 USAGE
48 use Getopt::Usaginator <usage>
49 Install a "usage" subroutine configured with the <usage> text
50
51 $code = Getopt::Usaginator->usaginator( <usage> )
52 Return a subroutine configured with the <usage> text
53
54 ...
55 More advanced usage is possible, peek under the hood for more
56 information
57
58 perldoc -m Getopt::Usaginator
59
60 An example:
61
62 use Getopt::Usaginator
63 # Called with the error
64 error => sub { ... },
65 # Called when usage printing is needed
66 usage => sub { ... },
67 ...
68 ;
69
70 An example with Getopt::Long parsing
71 use Getopt::Usaginator ...
72
73 sub run {
74 my $self = shift;
75 my @arguments = @_;
76
77 usage 0 unless @arguments;
78
79 my ( $help );
80 {
81 local @ARGV = @arguments;
82 GetOptions(
83 'help|h|?' => \$help,
84 );
85 }
86
87 usage 0 if $help;
88
89 ...
90 }
91
92 AUTHOR
93 Robert Krimen <[email protected]>
94
95 COPYRIGHT AND LICENSE
96 This software is copyright (c) 2010 by Robert Krimen.
97
98 This is free software; you can redistribute it and/or modify it under
99 the same terms as the Perl 5 programming language system itself.
100