1MooX::Cmd::Role(3)    User Contributed Perl Documentation   MooX::Cmd::Role(3)
2
3
4

NAME

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

SYNOPSIS

9   using role and want behavior as MooX::Cmd
10         package MyFoo;
11
12         with MooX::Cmd::Role;
13
14         sub _build_command_execute_from_new { 1 }
15
16         package main;
17
18         my $cmd = MyFoo->new_with_cmd;
19
20   using role and don't execute immediately
21         package MyFoo;
22
23         with MooX::Cmd::Role;
24         use List::MoreUtils qw/ first_idx /;
25
26         sub _build_command_base { "MyFoo::Command" }
27
28         sub _build_command_execute_from_new { 0 }
29
30         sub execute {
31             my $self = shift;
32             my $chain_idx = first_idx { $self == $_ } @{$self->command_chain};
33             my $next_cmd = $self->command_chain->{$chain_idx+1};
34             $next_cmd->owner($self);
35             $next_cmd->execute;
36         }
37
38         package main;
39
40         my $cmd = MyFoo->new_with_cmd;
41         $cmd->command_chain->[-1]->run();
42
43   explicit expression of some implicit stuff
44         package MyFoo;
45
46         with MooX::Cmd::Role;
47
48         sub _build_command_base { "MyFoo::Command" }
49
50         sub _build_command_execute_method_name { "run" }
51
52         sub _build_command_execute_from_new { 0 }
53
54         package main;
55
56         my $cmd = MyFoo->new_with_cmd;
57         $cmd->command_chain->[-1]->run();
58

DESCRIPTION

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

ATTRIBUTES

64   command_args
65       ARRAY-REF of args on command line
66
67   command_chain
68       ARRAY-REF of commands lead to this instance
69
70   command_chain_end
71       COMMAND accesses the finally detected command in chain
72
73   command_name
74       ARRAY-REF the name of the command lead to this command
75
76   command_commands
77       HASH-REF names of other commands
78
79   command_base
80       STRING base of command plugins
81
82   command_execute_method_name
83       STRING name of the method to invoke to execute a command, default
84       "execute"
85
86   command_execute_return_method_name
87       STRING I have no clue what that is good for ...
88
89   command_creation_method_name
90       STRING name of constructor
91
92   command_creation_chain_methods
93       ARRAY-REF names of methods to chain for creating object (from
94       "command_creation_method_name")
95
96   command_execute_from_new
97       BOOL true when constructor shall invoke "command_execute_method_name",
98       false otherwise
99

METHODS

101   new_with_cmd
102       initializes by searching command line args for commands and invoke them
103
104   execute_return
105       returns the content of $self->{execute_return}
106
108       Copyright 2012-2013 Torsten Raudssus, Copyright 2013-2017 Jens Rehsack.
109
110       This program is free software; you can redistribute it and/or modify it
111       under the terms of either: the GNU General Public License as published
112       by the Free Software Foundation; or the Artistic License.
113
114       See <http://dev.perl.org/licenses/> for more information.
115
116
117
118perl v5.34.0                      2021-07-22                MooX::Cmd::Role(3)
Impressum