App-Cmdline
view release on metacpan or search on metacpan
lib/App/Cmdline/Options/ExtBasic.pm view on Meta::CPAN
#-----------------------------------------------------------------
# App::Cmdline::Options::ExtBasic
# Author: Martin Senger <martin.senger@gmail.com>
# For copyright and disclaimer see the POD.
#
# ABSTRACT: set of basic options for command-line applications
# PODNAME: App::Cmdline::Options::ExtBasic
#-----------------------------------------------------------------
use warnings;
use strict;
package App::Cmdline::Options::ExtBasic;
use parent 'App::Cmdline::Options::Basic';
our $VERSION = '0.1.2'; # VERSION
use Pod::Usage;
use Pod::Find qw(pod_where);
my @OPT_SPEC = (
[ 'help' => "display a full usage message" ],
[ 'man|m' => "display a full manual page" ],
[ 'quiet|q' => "skip various progress messages" ],
);
# ----------------------------------------------------------------
# Return definition of my options
# ----------------------------------------------------------------
sub get_opt_spec {
return shift->SUPER::get_opt_spec(), @OPT_SPEC;
}
# ----------------------------------------------------------------
# Do typical actions with my options
# ----------------------------------------------------------------
sub validate_opts {
my ($class, $app, $caller, $opt, $args) = @_;
$class->SUPER::validate_opts ($app, $caller, $opt, $args);
# show various levels of help and exit
my $pod_where = pod_where ({-inc => 1}, $app);
pod2usage (-input => $pod_where, -verbose => 1, -exitval => 'NOEXIT')
if $opt->can ('help') and $opt->help;
pod2usage (-input => $pod_where, -verbose => 2, -exitval => 'NOEXIT')
if $opt->can ('man') and $opt->man;
if ( ($opt->can ('help') and $opt->help) or ($opt->can ('man') and $opt->man) ) {
if ($^S) { die "Okay\n" } else { exit (0) };
}
return;
}
1;
=pod
=head1 NAME
App::Cmdline::Options::ExtBasic - set of basic options for command-line applications
=head1 VERSION
version 0.1.2
=head1 SYNOPSIS
# In your module that represents a command-line application:
sub opt_spec {
my $self = shift;
return $self->check_for_duplicates (
[ 'check|c' => "only check the configuration" ],
...,
$self->composed_of (
'App::Cmdline::Options::ExtBasic', # here are the options added
)
);
}
=head1 DESCRIPTION
This is a kind of a I<role> module, defining a particular set of
command-line options and their validation. See more about how to write
a module that represents a command-line application and that uses this
set of options in L<App::Cmdline>.
=head1 OPTIONS
Particularly, this module extends the basic options, adding mostly
more documentation options. It inherits from
L<App::Cmdline::Options::Basic> module, and, therefore, provides the
same basic options defined there, and it adds the following options:
[ 'help' => "display a full usage message" ],
[ 'man|m' => "display a full manual page" ],
[ 'quiet|q' => "skip various progress messages" ],
=head2 --help
( run in 1.784 second using v1.01-cache-2.11-cpan-39bf76dae61 )