Net::Remctl::Backend(3pm) | User Contributed Perl Documentation | Net::Remctl::Backend(3pm) |
Net::Remctl::Backend - Helper infrastructure for remctl backend programs
use Net::Remctl::Backend; my %commands = ( cmd1 => { code => \&run_cmd1 }, cmd2 => { code => \&run_cmd2 }, ); my $backend = Net::Remctl::Backend->new({ commands => \%commands, }); exit $backend->run();
Net::Remctl::Backend provides a framework for remctl backend commands (commands run by remctld). It can be configured with a list of supported subcommands and handles all the command-line parsing and syntax checking, dispatching the command to the appropriate sub if it is valid.
<service> remctl help:
where <service> is something like "Event handling" or "User database" or whatever this set of commands generally does or manipulates.
The commands key, described above, takes a hash of properties for each subcommand supported by this backend. The possible keys in that hash are:
There is currently no way to check all arguments in commands that take any number of arguments.
If this command is called without any arguments, behavior varies based on whether the "code" parameter is also set alongside the "nested" parameter. If "code" is set, the command is called normally, with no arguments. If "code" is not set, calling this command without a subcommand is treated as an unknown command.
For example, if this is set to "['help|h', 'version|v']" and the arguments passed to run() are:
command -hv foo bar
then the code implementing "command" will be called with the following arguments:
{ help => 1, version => 1 }, 'foo', 'bar'
Getopt::Long will always be configured with the options "bundling", "no_ignore_case", and "require_order". This means, among other things, that the first non-option argument will stop option parsing and all remaining arguments will be passed through verbatim.
If Getopt::Long rejects the options (due to an unknown option or an invalid argument to an option, for example), run() will die with the error message from Getopt::Long without running the command.
Checks for the number of arguments and for the validity of arguments with regular expression verification are done after reading the data from standard input and transforming the argument list accordingly.
If this key is omitted, the subcommand will still be shown in help output, provided that it has a syntax key, but without any trailing summary.
syntax => '<object>'
which will result in help output (assuming command is set to "object" and this parameter is set on the "delete" command) that looks like:
object delete <object>
Use abbreviations heavily to keep this string short so that the help output will remain readable.
Set this key to the empty string to indicate that this subcommand takes no arguments or flags.
If this key is omitted, the subcommand will be omitted from help output.
The command (which is the remctl subcommand) and arguments can be passed directly to run() as parameters. If no arguments are passed, run() expects @ARGV to contain the parameters passed to the backend script. Either way the first argument will be the subcommand, used to find the appropriate command to run, and any remaining arguments will be arguments to that command. (Note that if the "options" parameter is set, the first argument passed to the underlying command will be the options hash.)
If there are errors in the parameters to the command, run() will die with an appropriate error message.
Since Net::Remctl::Backend is designed to handle command line parsing for a script and report appropriate errors if there are problems with the argument, its run() method may die with various errors. The possible errors are listed below. All will be terminated with a newline so the Perl context information won't be appended.
This module was added in the 3.4 release of remctl. Since 3.5, the module version matches the remctl version but with a leading zero added so that the minor version always has two numbers (so Net::Remctl::Backend 3.05 was included in remctl 3.5).
All currently-supported methods and options have been supported since the original release of the module.
There is no way to check all arguments with a regex when the command supports any number of arguments.
Russ Allbery <eagle@eyrie.org>
Copyright 2012-2014 The Board of Trustees of the Leland Stanford Junior University
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The current version of this module is available from its web page at <https://www.eyrie.org/~eagle/software/remctl/>.
2018-11-02 | perl v5.28.0 |