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

NAME

6       App::Cmd::Simple - a helper for building one-command App::Cmd
7       applications
8

VERSION

10       version 0.334
11

SYNOPSIS

13       in simplecmd:
14
15         use YourApp::Cmd;
16         Your::Cmd->run;
17
18       in YourApp/Cmd.pm:
19
20         package YourApp::Cmd;
21         use parent qw(App::Cmd::Simple);
22
23         sub opt_spec {
24           return (
25             [ "blortex|X",  "use the blortex algorithm" ],
26             [ "recheck|r",  "recheck all results"       ],
27           );
28         }
29
30         sub validate_args {
31           my ($self, $opt, $args) = @_;
32
33           # no args allowed but options!
34           $self->usage_error("No args allowed") if @$args;
35         }
36
37         sub execute {
38           my ($self, $opt, $args) = @_;
39
40           my $result = $opt->{blortex} ? blortex() : blort();
41
42           recheck($result) if $opt->{recheck};
43
44           print $result;
45         }
46
47       and, finally, at the command line:
48
49         knight!rjbs$ simplecmd --recheck
50
51         All blorts successful.
52

PERL VERSION SUPPORT

54       This module has a long-term perl support period.  That means it will
55       not require a version of perl released fewer than five years ago.
56
57       Although it may work on older versions of perl, no guarantee is made
58       that the minimum required version will not be increased.  The version
59       may be increased for any reason, and there is no promise that patches
60       will be accepted to lower the minimum required perl.
61

SUBCLASSING

63       When writing a subclass of App::Cmd:Simple, there are only a few
64       methods that you might want to implement.  They behave just like the
65       same-named methods in App::Cmd.
66
67   opt_spec
68       This method should be overridden to provide option specifications.
69       (This is list of arguments passed to "describe_options" from
70       Getopt::Long::Descriptive, after the first.)
71
72       If not overridden, it returns an empty list.
73
74   usage_desc
75       This method should be overridden to provide the top level usage line.
76       It's a one-line summary of how the command is to be invoked, and should
77       be given in the format used for the $usage_desc parameter to
78       "describe_options" in Getopt::Long::Descriptive.
79
80       If not overridden, it returns something that prints out like:
81
82         yourapp [-?h] [long options...]
83
84   validate_args
85         $cmd->validate_args(\%opt, \@args);
86
87       This method is passed a hashref of command line options (as processed
88       by Getopt::Long::Descriptive) and an arrayref of leftover arguments.
89       It may throw an exception (preferably by calling "usage_error") if they
90       are invalid, or it may do nothing to allow processing to continue.
91
92   execute
93         Your::App::Cmd::Simple->execute(\%opt, \@args);
94
95       This method does whatever it is the command should do!  It is passed a
96       hash reference of the parsed command-line options and an array
97       reference of left over arguments.
98

WARNINGS

100       This should be considered experimental!  Although it is probably not
101       going to change much, don't build your business model around it yet,
102       okay?
103
104       App::Cmd::Simple is not rich in black magic, but it does do some
105       somewhat gnarly things to make an App::Cmd::Simple look as much like an
106       App::Cmd::Command as possible.  This means that you can't deviate too
107       much from the sort of thing shown in the synopsis as you might like.
108       If you're doing something other than writing a fairly simple command,
109       and you want to screw around with the App::Cmd-iness of your program,
110       Simple might not be the best choice.
111
112       One specific warning...  if you are writing a program with the
113       App::Cmd::Simple class embedded in it, you must call import on the
114       class.  That's how things work.  You can just do this:
115
116         YourApp::Cmd->import->run;
117

AUTHOR

119       Ricardo Signes <rjbs@semiotic.systems>
120
122       This software is copyright (c) 2021 by Ricardo Signes.
123
124       This is free software; you can redistribute it and/or modify it under
125       the same terms as the Perl 5 programming language system itself.
126
127
128
129perl v5.34.0                      2021-07-22               App::Cmd::Simple(3)
Impressum