Pod::Usage::CommandLine - Add some common command line options from Pod::Usage


Pod-Usage-CommandLine documentation Contained in the Pod-Usage-CommandLine distribution.

Index


Code Index:

NAME

Top

Pod::Usage::CommandLine - Add some common command line options from Pod::Usage

SYNOPSIS

Top

  use Pod::Usage::CommandLine;

  BEGIN { our $VERSION = '1.0'; }    # NOTE: Set main version in BEGIN block

  # then, use command line options:

  my_program.pl --version
  my_program.pl --help
  my_program.pl -h
  my_program.pl '-?'
  my_program.pl --man
  my_program.pl -m

  # You can also export GetOptions and/or pod2usage if you need them:

  use Pod::Usage::CommandLine qw(GetOptions pod2usage);

  my %opt;
  GetOptions(\%opt, @getopt_long_specs) or pod2usage;

DESCRIPTION

Top

Basically a cut/paste from the boilerplate described in Pod::Usage and Getopt::Long so it can be included with a single "use" instead of cut/pasting it.

See Getopt::Long for all the intricacies of specifying options.

Set $VERSION in a BEGIN block as shown above so it will get picked up by the '--version' option.

EXPORTS

Top

GetOptions and pod2usage are exported on demand.

SEE ALSO

Top

Pod::Usage, Getopt::Long

AUTHOR

Top

Curt Tilmes, <ctilmes@cpan.org>

CREDITS

Top

Thanks to:

Lars Dieckow <daxim@cpan.org>

COPYRIGHT AND LICENSE

Top


Pod-Usage-CommandLine documentation Contained in the Pod-Usage-CommandLine distribution.

package Pod::Usage::CommandLine;

use strict;
use warnings;

our $VERSION = '0.04';

use Pod::Usage;
use Getopt::Long;
use File::Basename;
use base 'Exporter';
our @EXPORT_OK = qw(GetOptions pod2usage);

INIT
{
    Getopt::Long::Parser
    ->new(config => [qw(pass_through no_auto_abbrev no_ignore_case)] )
    ->getoptions
    (
        'help|h|?' => sub { pod2usage(-exitstatus => 0); },
        'man|m'    => sub { pod2usage(-exitstatus => 0, -verbose => 2); },
        version    => sub
        {
            pod2usage(-exitstatus => 0,
                      -msg => basename($0) . ' ' . ($main::VERSION or '0.0'),
                      -verbose => 99,
                      -sections => 'COPYRIGHT.*|LICENSE.*|AUTHOR.*');
        }
    );
}

1;
__END__