App-Cmdline
view release on metacpan or search on metacpan
docs/App-Cmdline.html view on Meta::CPAN
<li class='indexItem indexItem2'><a href='#execute'>execute</a>
</ul>
<li class='indexItem indexItem1'><a href='#PREDEFINED_SETS_OF_OPTIONS'>PREDEFINED SETS OF OPTIONS</a>
<ul class='indexList indexList2'>
<ul class='indexList indexList3'>
<li class='indexItem indexItem3'><a href='#How_to_create_a_new_predefined_set'>How to create a new predefined set</a>
</ul>
</ul>
<li class='indexItem indexItem1'><a href='#AUTHOR'>AUTHOR</a>
<li class='indexItem indexItem1'><a href='#COPYRIGHT_AND_LICENSE'>COPYRIGHT AND LICENSE</a>
</ul>
</div>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="NAME"
>NAME</a></h1>
<p>App::Cmdline - helper for writing command-line applications</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="VERSION"
>VERSION</a></h1>
<p>version 0.1.2</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="SYNOPSIS"
>SYNOPSIS</a></h1>
<p>In your command-line script,
e.g.
in <em>myapp</em>:</p>
<pre> use App::myapp;
App::myapp->run;</pre>
<p>Such command-line script will be executed, for example, by:</p>
<pre> senger@ShereKhan$ myapp --version
senger@ShereKhan$ myapp --check
senger@ShereKhan$ myapp -c</pre>
<p>In your module that does the full job you are implementing, e.g. in <em>App/myapp.pm</em>:</p>
<pre> package App::myapp;
use parent 'App::Cmdline';
# Define your own options, and/or add some predefined sets.
sub opt_spec {
my $self = shift;
return $self->check_for_duplicates (
[ 'check|c' => "only check the configuration" ],
$self->composed_of (
'App::Cmdline::Options::Basic',
'App::Cmdline::Options::DB',
)
);
}
# The main job is implemented here
use Data::Dumper;
sub execute {
my ($self, $opt, $args) = @_;
print STDERR "Started...\n" unless $opt->quiet;
print STDOUT 'Options ($opt): ' . Dumper ($opt);
print STDOUT 'Arguments ($args): ' . Dumper ($args);
...
}</pre>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="DESCRIPTION"
>DESCRIPTION</a></h1>
<p>This module helps to write command-line applications, especially if they need to be fed by some command-line options and arguments. It extends the <a href="http://search.cpan.org/perldoc?App%3A%3ACmd%3A%3ASimple" class="podlinkpod"
>App::Cmd::Simple</a> module by adding the ability to use several predefined sets of options that many real command-line applications use and need anyway. For example, in most applications you need a way how to print its version or how to provide a d...
<p>Your module (representing the application you are writing) should inherit from this module and implement, at least, the method <a href="#opt_spec" class="podlinkpod"
>opt_spec</a> (optionally) and the method <a href="#execute" class="podlinkpod"
>execute</a> (mandatory).</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="METHODS"
>METHODS</a></h1>
<p>In order to use the ability of composing list of options from the existing sets of predefined options (which is, after all, the main <i>raison d'être</i> of this module) use the method <a href="#composed_of" class="podlinkpod"
>composed_of</a>. And to find out that various predefined sets of options do not step on each other toes, use the method <a href="#check_for_duplicates" class="podlinkpod"
>check_for_duplicates</a>.</p>
<p>When writing a subclass of App::Cmdline, there are only a few methods that you might want to overwrite (except for <a href="#execute" class="podlinkpod"
>execute</a> that you <b>must</b> overwrite). Below are those that may be of your interest, or those that are implemented here slightly differently from the <a href="http://search.cpan.org/perldoc?App%3A%3ACmd%3A%3ASimple" class="podlinkpod"
>App::Cmd::Simple</a>.</p>
<h3><a class='u' href='#___top' title='click to go to top of document'
name="Summary_of_methods"
>Summary of methods</a></h3>
<dl>
<dt><a name="Methods_that_you_must_overwrite"
>Methods that you must overwrite</a></dt>
<dd>
<pre> execute()</pre>
<dt><a name="Methods_that_you_should_overwrite"
>Methods that you should overwrite</a></dt>
<dd>
<pre> opt_spec()</pre>
<dt><a name="Methods_that_you_may_overwrite"
>Methods that you may overwrite</a></dt>
<dd>
<pre> usage_desc()
validate_args()
usage_error()
getopt_conf()
...</pre>
<dt><a name="Methods_that_you_just_call"
( run in 1.160 second using v1.01-cache-2.11-cpan-39bf76dae61 )