App-Easer
view release on metacpan or search on metacpan
lib/App/Easer/V1.pod view on Meta::CPAN
myapp stats
In the first two cases, C<App::Easer::V1> would normally look for
sub-commands C<this> and C<that> respectively, failing. With a fallback,
though, it's possible to select another command and implement the
C<DWIM> interface.
C<fallback> is an I<executable> that is expected to return the name of a
child (or actually any command) or the empty list/C<undef>, in which
case the current command's C<execute> will be used instead. This is the
most flexible way of doing the fallback.
Calling convention:
sub ($app, $spec, $args)
# $app: hash ref with the details on the whole applications
# $spec: hash ref with the specification of the command
# $args: array ref with residual (command line) arguments
The configuration that has been assembled up to the specific command can
be retrieved at C<< $app->{configs}[-1] >>.
C<fallback-to> sets the name of a children (or actually any command) as
a static string. It can also be set to C<undef>, which means that the
current command's C<execute> should be used instead.
C<fallback-to-default> selects whatever default is set for the command;
it is a boolean-ish option.
In all cases, when the set/returned value is a reference to a hash that
contains only the key C<index> pointing to an integer, this is assumed
to point to an element inside the children array reference and used as
such.
=item C<leaf>
This is an alternative, hopefully more readable, way to set the command
as a I<leaf> and avoid considering any sub-command, including the
auto-generated ones.
=item C<no-auto>
This option disables the automatic addition of automatically generated
sub-commands.
If set to an array reference, all items in the array will be filtered
out from the list of automatically added sub-commands. If set to the
string C<*>, all automatic sub-commands will be ignored.
=back
=head1 FUNCTIONS
The following functions can be optionally imported.
=head2 d
d(['whatever', {hello => 'world'}]);
Dump data on standard error using L<Data::Dumper>.
=head2 run
run($application, \@args);
# hash data structure
run({...}, \@ARGV);
# filename or string, in JSON or Perl
run('/path/to/app.json', \@ARGV);
run('/path/to/app.pl', \@ARGV);
run(\$app, \@ARGV);
# filehandle, data in JSON or Perl
run(\*DATA, \@ARGV)
Run an application.
Takes two positional parameters:
=over
=item *
an I<application> definition, which can be provided as:
=over
=item *
hash reference ("native" format)
=item *
reference to a string, containing either a JSON or a Perl definition for
the application.
For the JSON alternative, the string must contain a JSON object so that
the parsing returns a reference to a hash.
For the Perl alternative, the text is C<eval>ed and must return a
reference to a hash.
=item *
a string with a file path, pointing to either a JSON or a Perl file. The
file is loaded and treated as described above for the I<reference to a
string> case;
=item *
a filehandle, allowing to load either a JSON or a Perl file. The content
is treated as described above for the I<reference to a string> case.
=back
=item *
the command-line arguments to parse (usually taken from C<@ARGV>),
provided as a reference to an array.
( run in 2.963 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )