MooX::Cmd::ChainedOptions - easily access options from higher up the command chain
version 0.04
# 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"; } # MyApp/Cmd/cmd/Cmd/subcmd.pm : Sub-Command Class package MyApp::Cmd::cmd::Cmd::subcmd; use Moo; use MooX::Cmd; use MooX::Cmd::ChainedOptions; option subcmd_opt => ( is => 'ro', format => 's', default => 'B' ); sub execute { print $_[0]->app_opt, "\n"; print $_[0]->cmd_opt, "\n"; print $_[0]->subcmd_opt, "\n"; }
For applications using MooX::Cmd and MooX::Options, MooX::Cmd::ChainedOptions transparently provides access to command line options from further up the command chain.
For example, if an application provides options at each level of the command structure:
app --app-opt cmd --cmd-opt subcmd --subcmd-opt
The subcmd object will have direct access to the app_option and cmd_option options via object attributes:
app_option
cmd_option
sub execute { print $self->app_opt, "\n"; print $self->cmd_opt, "\n"; print $self->subcmd_opt, "\n"; }
Simply
use MooX::Cmd::ChainedOptions;
instead of
use MooX::Options;
Every layer in the application hierarchy (application class, command class, sub-command class) must use MooX::Cmd::ChainedOptions. See the "SYNOPSIS" for an example.
You can make new bug reports, and view existing ones, through the web interface at https://rt.cpan.org/Public/Dist/Display.html?Name=MooX-Cmd-ChainedOptions.
Diab Jerius <djerius@cpan.org>
This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
To install MooX::Cmd::ChainedOptions, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooX::Cmd::ChainedOptions
CPAN shell
perl -MCPAN -e shell install MooX::Cmd::ChainedOptions
For more information on module installation, please visit the detailed CPAN module installation guide.