1App::Cmd::Command(3)  User Contributed Perl Documentation App::Cmd::Command(3)
2
3
4

NAME

6       App::Cmd::Command - a base class for App::Cmd commands
7

VERSION

9       version 0.334
10

PERL VERSION SUPPORT

12       This module has a long-term perl support period.  That means it will
13       not require a version of perl released fewer than five years ago.
14
15       Although it may work on older versions of perl, no guarantee is made
16       that the minimum required version will not be increased.  The version
17       may be increased for any reason, and there is no promise that patches
18       will be accepted to lower the minimum required perl.
19

METHODS

21   prepare
22         my ($cmd, $opt, $args) = $class->prepare($app, @args);
23
24       This method is the primary way in which App::Cmd::Command objects are
25       built.  Given the remaining command line arguments meant for the
26       command, it returns the Command object, parsed options (as a hashref),
27       and remaining arguments (as an arrayref).
28
29       In the usage above, $app is the App::Cmd object that is invoking the
30       command.
31
32   new
33       This returns a new instance of the command plugin.  Probably only
34       "prepare" should use this.
35
36   execute
37         $command_plugin->execute(\%opt, \@args);
38
39       This method does whatever it is the command should do!  It is passed a
40       hash reference of the parsed command-line options and an array
41       reference of left over arguments.
42
43       If no "execute" method is defined, it will try to call "run" -- but it
44       will warn about this behavior during testing, to remind you to fix the
45       method name!
46
47   app
48       This method returns the App::Cmd object into which this command is
49       plugged.
50
51   usage
52       This method returns the usage object for this command.  (See
53       Getopt::Long::Descriptive).
54
55   command_names
56       This method returns a list of command names handled by this plugin. The
57       first item returned is the 'canonical' name of the command.
58
59       If this method is not overridden by an App::Cmd::Command subclass, it
60       will return the last part of the plugin's package name, converted to
61       lowercase.  For example, YourApp::Cmd::Command::Init will, by default,
62       handle the command "init".
63
64       Subclasses should generally get the superclass value of "command_names"
65       and then append aliases.
66
67   usage_desc
68       This method should be overridden to provide a usage string.  (This is
69       the first argument passed to "describe_options" from
70       Getopt::Long::Descriptive.)
71
72       If not overridden, it returns "%c COMMAND %o";  COMMAND is the first
73       item in the result of the "command_names" method.
74
75   opt_spec
76       This method should be overridden to provide option specifications.
77       (This is list of arguments passed to "describe_options" from
78       Getopt::Long::Descriptive, after the first.)
79
80       If not overridden, it returns an empty list.
81
82   validate_args
83         $command_plugin->validate_args(\%opt, \@args);
84
85       This method is passed a hashref of command line options (as processed
86       by Getopt::Long::Descriptive) and an arrayref of leftover arguments.
87       It may throw an exception (preferably by calling "usage_error", below)
88       if they are invalid, or it may do nothing to allow processing to
89       continue.
90
91   usage_error
92         $self->usage_error("This command must not be run by root!");
93
94       This method should be called to die with human-friendly usage output,
95       during "validate_args".
96
97   abstract
98       This method returns a short description of the command's purpose.  If
99       this method is not overridden, it will return the abstract from the
100       module's Pod.  If it can't find the abstract, it will look for a
101       comment starting with "ABSTRACT:" like the ones used by
102       Pod::Weaver::Section::Name.
103
104   description
105       This method can be overridden to provide full option description. It is
106       used by the built-in help command.
107
108       If not overridden, it uses Pod::Usage to extract the description from
109       the module's Pod DESCRIPTION section or the empty string.
110

AUTHOR

112       Ricardo Signes <rjbs@semiotic.systems>
113
115       This software is copyright (c) 2021 by Ricardo Signes.
116
117       This is free software; you can redistribute it and/or modify it under
118       the same terms as the Perl 5 programming language system itself.
119
120
121
122perl v5.34.0                      2022-01-20              App::Cmd::Command(3)
Impressum