logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MooX::Cmd::Role - MooX cli app commands do this

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"

   command_execute_return_method_name
       STRING I have no clue what that is good for ...

   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

Description

       MooX::Cmd::Role is made for modern, flexible Moo style to tailor cli commands.

Methods

new_with_cmd
       initializes by searching command line args for commands and invoke them

   execute_return
       returns the content of $self->{execute_return}

Name

       MooX::Cmd::Role - MooX cli app commands do this

Synopsis

usingroleandwantbehaviorasMooX::Cmd
         package MyFoo;

         with MooX::Cmd::Role;

         sub _build_command_execute_from_new { 1 }

         package main;

         my $cmd = MyFoo->new_with_cmd;

   usingroleanddon'texecuteimmediately
         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();

   explicitexpressionofsomeimplicitstuff
         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();

See Also