App-Easer
view release on metacpan or search on metacpan
docs/docs/15-tutorial-splitting.md view on Meta::CPAN
my $sub = $package->can($key) or next;
$direct{$key} = $sub->();
}
$direct{execute} //= $package;
return \%direct;
}
```
The `execute` key is (conditionally) set to the package name. When
provided with a package name, the resolution process in [App::Easer][]
looks for a sub called `execute` inside that package, so it will suffice
to call our command implementation `sub execute`.
The specific way `autospec` is implemented (i.e. accepting an input hash
`%direct`) allows us to adopt different degrees of shifting stuff from
the hash to the functions. As an example, we go full-on with the
implementation for sub-command `add`:
```perl
package MuDu::Command::Add;
use v5.24;
lib/App/Easer/Tutorial/V2_008.pod view on Meta::CPAN
[2024/09/07 16:34:49] [ INFO] this is INFO
What is happening now?
Each command level in L<App::Easer> is tracked as an object instance by
itself, representing the specific root/intermediate/leaf command. For
this reason, methods called on the specific object provide a I<view>
from that object's perspective.
The C<final_commit> is set inside the root command, so when we call the
C<config> method it only looks at the options collected in the root
command. Which means... no C<loglevel> value set in the selected leaf
command.
For this reason, method C<leaf> allows getting the final I<leaf> command
object that resulted from the search done by L<App::Easer>. Calling it
is meaningful only inside C<final_commit>, but it's exactly where we
need it:
#!/usr/bin/env perl
use v5.24;
lib/App/Easer/V1.pod view on Meta::CPAN
It is possible to set several I<sources> for gathering options values,
setting them using the C<sources> array. By default it is set to the
ordered list with C<+Default>, C<+CmdLine>, C<+Environment>, and
C<+Parent>, , meaning that options from the command line will have the
highest precedence, then the environment, then whatever comes from the
parent command configuration, then default values if present. This can
be set explicitly with C<+DefaultSources>.
As an alternative, C<sources> can be set to C<+SourcesWithFiles>, which
adds C<+JsonFileFromConfig> and C<+JsonFiles> to the ones above. The
former looks for a configuration named C<config> (or whatever is set as
C<config-option> in the overall configuration hash) to load a JSON file
with additional configurations; the latter looks for a list of JSON
files to try in C<config-files> inside the configuration hash.
=over
Although the C<+Default> source is put I<first>, it actually acts as the
one with the I<least precedence> by how it is coded and how the merging
algorithm is implemented. From a practical point of view it's I<like> it
were put last, but is put first instead so that its defaults can be
applied as options are gathered along the way.
lib/App/Easer/V2.pod view on Meta::CPAN
should be considered a liability.
=item C<children_prefixes>
Array of strings. Defaults to C<[$pkg . '::Cmd']>.
Each string in the array is used as a prefix to look for sub-commands in
C<@INC>.
Assuming the main command is implemented in class C<MyApp>, the default
value looks for classes named C<MyApp::Cmd*>, e.g. C<MyApp::CmdFoo> and
C<MyApp::CmdBar> and I<ignores> classed named C<MyApp::Common> or
C<MyApp::Utils>.
=item C<commit>
Executable with signature:
sub commit_function ($app) { ... }
where C<$app> is the blessed object for the application.
( run in 0.765 second using v1.01-cache-2.11-cpan-64827b87656 )