MooX::Cmd::Role(3pm)
π MooX::Cmd::Role β the perl manual page, but make it cute π
okay bestie, so you're reading MooX::Cmd::Role(3pm), which lives in the User Contributed Perl Documentation section. buckle up, it's giving "tiny role, huge power". π
β¨ NAME β¨
MooX::Cmd::Role β MooX cli app commands do this. that's it. that's the whole name. iconic behavior, honestly. π
πΈ SYNOPSIS πΈ
using role and want behavior as MooX::Cmd
package MyFoo;
with MooX::Cmd::Role;
sub _build_command_execute_from_new { 1 }
package main;
my $cmd = MyFoo->new_with_cmd;
using role and don't execute immediately
package MyFoo;
with MooX::Cmd::Role;
use List::MoreUtils qw/ first_idx /;
sub _build_command_base { "MyFoo::Command" }
sub _build_command_execute_from_new { 0 }
sub execute {
my $self = shift;
my $chain_idx = first_idx { $self == $_ } @{$self->command_chain};
my $next_cmd = $self->command_chain->{$chain_idx+1};
$next_cmd->owner($self);
$next_cmd->execute;
}
package main;
my $cmd = MyFoo->new_with_cmd;
$cmd->command_chain->[-1]->run();
explicit expression of some implicit stuff
package MyFoo;
with MooX::Cmd::Role;
sub _build_command_base { "MyFoo::Command" }
sub _build_command_execute_method_name { "run" }
sub _build_command_execute_from_new { 0 }
package main;
my $cmd = MyFoo->new_with_cmd;
$cmd->command_chain->[-1]->run();
π¦ DESCRIPTION π¦
MooX::Cmd::Role is made for modern, flexible Moo style to tailor cli commands. fr fr, that's literally the whole pitch β it's the role you slap onto your command classes so they can do the whole MooX::Cmd thing. β¨
π ATTRIBUTES π
command_args
ARRAY-REF of args on command line. π
command_chain
ARRAY-REF of commands lead to this instance.
command_chain_end
COMMAND accesses the finally detected command in chain. π―
command_name
ARRAY-REF the name of the command lead to this command.
command_commands
HASH-REF names of other commands.
command_base
STRING base of command plugins.
command_execute_method_name
STRING name of the method to invoke to execute a command, default "execute". yep, it defaults, you don't gotta set it unless you're feeling spicy
command_execute_return_method_name
STRING β and I quote the original here, bestie: I have no clue what that is good for ... π even the docs are like "idk girl". keeping it 100.
command_creation_method_name
STRING name of constructor.
command_creation_chain_methods
ARRAY-REF names of methods to chain for creating object (from command_creation_method_name).
command_execute_from_new
BOOL β true when constructor shall invoke command_execute_method_name, false otherwise. β‘
π METHODS π
new_with_cmd
initializes by searching command line args for commands and invoke them. the main character method, honestly π
execute_return
returns the content of $self->{execute_return}. π«Ά
π LICENSE AND COPYRIGHT π
Copyright 2012-2013 Torsten Raudssus, Copyright 2013-2017 Jens Rehsack.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See <http://dev.perl.org/licenses/> for more information.
heads up bestie: that license bit is the real deal β GPL or Artistic, your pick. don't be weird about it. π
okay that's the whole page, and a lil sign-off for the road: this manual page is from perl v5.36.0, dated 2022-11-19, and it's the MooX::Cmd::Role(3pm) page. slay, go build some cli commands. π¦π
β¨
π¦ where this page comes from
- debian bookworm: libmoox-cmd-perl 0.017-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoox-cmd-perl 0.017-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoox-cmd-perl 0.017-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libmoox-cmd-perl 0.017-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms