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