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.311
10

METHODS

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   app
29       This method returns the App::Cmd object into which this command is
30       plugged.
31
32   usage
33       This method returns the usage object for this command.  (See
34       Getopt::Long::Descriptive).
35
36   command_names
37       This method returns a list of command names handled by this plugin.  If
38       this method is not overridden by a App::Cmd::Command subclass, it will
39       return the last part of the plugin's package name, converted to
40       lowercase.
41
42       For example, YourApp::Cmd::Command::Init will, by default, handle the
43       command "init"
44
45   usage_desc
46       This method should be overridden to provide a usage string.  (This is
47       the first argument passed to "describe_options" from
48       Getopt::Long::Descriptive.)
49
50       If not overridden, it returns "%c COMMAND %o";  COMMAND is the first
51       item in the result of the "command_names" method.
52
53   opt_spec
54       This method should be overridden to provide option specifications.
55       (This is list of arguments passed to "describe_options" from
56       Getopt::Long::Descriptive, after the first.)
57
58       If not overridden, it returns an empty list.
59
60   validate_args
61         $command_plugin->validate_args(\%opt, \@args);
62
63       This method is passed a hashref of command line options (as processed
64       by Getopt::Long::Descriptive) and an arrayref of leftover arguments.
65       It may throw an exception (preferably by calling "usage_error", below)
66       if they are invalid, or it may do nothing to allow processing to
67       continue.
68
69   usage_error
70         $self->usage_error("This command must not be run by root!");
71
72       This method should be called to die with human-friendly usage output,
73       during "validate_args".
74
75   abstract
76       This method returns a short description of the command's purpose.  If
77       this method is not overridden, it will return the abstract from the
78       module's POD.  If it can't find the abstract, it will return the string
79       "(unknown")
80
81   description
82       This method should be overridden to provide full option description. It
83       is used by the help command.
84
85       If not overridden, it returns an empty string.
86
87         $command_plugin->execute(\%opt, \@args);
88
89       This method does whatever it is the command should do!  It is passed a
90       hash reference of the parsed command-line options and an array
91       reference of left over arguments.
92
93       If no "execute" method is defined, it will try to call "run" -- but it
94       will warn about this behavior during testing, to remind you to fix the
95       method name!
96

AUTHOR

98       Ricardo Signes <rjbs@cpan.org>
99
101       This software is copyright (c) 2011 by Ricardo Signes.
102
103       This is free software; you can redistribute it and/or modify it under
104       the same terms as the Perl 5 programming language system itself.
105
106
107
108perl v5.12.3                      2011-03-18              App::Cmd::Command(3)
Impressum