Synopsis
# MyApp.pm : App Base Class
use Moo;
use MooX::Cmd;
use MooX::Cmd::ChainedOptions;
option app_opt => ( is => 'ro', format => 's', default => 'BASE' );
sub execute {
print $_[0]->app_opt, "\n";
}
# MyApp/Cmd/cmd.pm : Command Class
package MyApp::Cmd::cmd;
use Moo;
use MooX::Cmd;
use MooX::Cmd::ChainedOptions;
option cmd_opt => ( is => 'ro', format => 's', default => 'A' );
sub execute {
print $_[0]->app_opt, "\n";
print $_[0]->cmd_opt, "\n";
}
Description
When used instead of MooX::Options in applications constructed with MooX::Cmd, this class adds attributes to a command object which provide access to command line options passed to commands higher up the command chain.
For example (using the above code which creates an application and a command), the following command line
app --app-opt=FOO cmd --cmd-opt=BAR
would result in the MyApp::Cmd::cmd
object having an attribute called app_opt
which contains FOO
.
Without this module, the MyApp::Cmd::cmd
object would have to search through the chain of commands (passed to the execute
method, or available via the command_chainmethod)
looking for the app_opt
attribute.
I'm afraid the name may be confused with "chained" method approaches, but MooX::Cmd uses the "chain" terminology to describe the hierarchy of commands, so I thought I'd stick to that.
Any alternate suggestions?
Thanks, Diab
Comments
Please sign up to post a review.