App::vaporcalc::Role::UI::Cmd - Helper for vaporcalc command objects
# An example command subject; # placed in the App::vaporcalc::Cmd::Subject:: namespace so it can be found # by an App::vaporcalc::CmdEngine instance: package App::vaporcalc::Cmd::Subject::Foo; use Defaults::Modern; use Moo; with 'App::vaporcalc::Role::UI::Cmd'; # To be listed in an App::vaporcalc::CmdEngine's 'subject_list'; # must be a class method (not an attribute): sub _subject { 'foo' } # To provide a default verb: has '+verb' => ( builder => sub { 'show' } ); # Add verbs that return an App::vaporcalc::Cmd::Result: method _action_view { $self->_action_show } method _action_show { $self->create_result( string => "hello world!" ) }
A Moo::Role providing attributes & behavior common to App::vaporcalc command objects.
Command objects define a "subject" that provides "verbs" -- methods prefixed with _action_ that have access to the current "recipe" object and command "params". Executing a verb returns a App::vaporcalc::Cmd::Result (see "create_result") or throws an exception (see "throw_exception") in case of failure.
_action_
If using an App::vaporcalc::CmdEngine, consumers of this role will likely also want to define a _subject class method returning a string to be taken as the command subject when building the CmdEngine's subject_list.
_subject
subject_list
The given _subject string must translate to the relevant class name by trimming spaces and CamelCasing; for example:
sub _subject { 'flavor' } # -> ::Cmd::Subject::Flavor sub _subject { 'nic base' } # -> ::Cmd::Subject::NicBase
The action to perform.
An empty string by default. Consumers may want to override to provide a default action.
The parameters for the command, as a "ArrayObj" in List::Objects::Types.
Can be coerced from a plain ARRAY.
The App::vaporcalc::Recipe object being operated on.
Required by default.
A default dispatcher that, when called, converts "verb" to lowercase and attempts to find a method named _action_$verb to call.
_action_$verb
$self->throw_exception( message => 'failed!' );
Throw an exception object.
Builds an App::vaporcalc::Cmd::Result instance.
my $new_recipe = $self->munge_recipe( target_vg => 50, target_pg => 50 );
Calls TO_JSON on the current "recipe" object, merges in the given key/value pairs, and returns a new App::vaporcalc::Recipe with the appropriate values.
TO_JSON
App::vaporcalc::Cmd::Result
App::vaporcalc::CmdEngine
App::vaporcalc::Role::UI::ParseCmd
App::vaporcalc::Role::UI::PrepareCmd
Jon Portnoy <avenj@cobaltirc.org>
To install App::vaporcalc, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::vaporcalc
CPAN shell
perl -MCPAN -e shell install App::vaporcalc
For more information on module installation, please visit the detailed CPAN module installation guide.