Getopt-Usaginator
view release on metacpan or search on metacpan
lib/Getopt/Usaginator.pm view on Meta::CPAN
usage if $options{help}; # Print usage and exit with status 0
if ( ! $options{derp} ) {
# Print warning and usage and exit with status -1
usage "You should really derp";
}
if ( $options{durp} ) {
# Print warning and usage and exit with status 2
usage 2 => "--durp is not ready yet";
}
...
usage 3 # Print usage and exit with status 3
=head1 DESCRIPTION
Getopt::Usaginator is a tool for creating a handy usage subroutine for commandline applications
It does not do any option parsing, but is best paired with L<Getopt::Long> or any of the other myriad of option parsers
=head1 USAGE
=head2 use Getopt::Usaginator <usage>
Install a C<usage> subroutine configured with the <usage> text
=head2 $code = Getopt::Usaginator->usaginator( <usage> )
Return a subroutine configured with the <usage> text
=head2 ...
More advanced usage is possible, peek under the hood for more information
perldoc -m Getopt::Usaginator
An example:
use Getopt::Usaginator
# Called with the error
error => sub { ... },
# Called when usage printing is needed
usage => sub { ... },
...
;
=head1 An example with Getopt::Long parsing
use Getopt::Usaginator ...
sub run {
my $self = shift;
my @arguments = @_;
usage 0 unless @arguments;
my ( $help );
{
local @ARGV = @arguments;
GetOptions(
'help|h|?' => \$help,
);
}
usage 0 if $help;
...
}
=head1 AUTHOR
Robert Krimen <robertkrimen@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Robert Krimen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.614 second using v1.01-cache-2.11-cpan-97f6503c9c8 )