Data::Object::Cli
Data-Object Cli Class
package Cli; use Data::Object::Class; extends 'Data::Object::Cli'; method main(:$args) { # do something with $args, $opts, $env } run Cli;
Data::Object::Cli provides an abstract base class for defining command-line interface classes, which can be run as scripts or passed as objects in a more complex system.
This package implements the following methods.
# given $cli $cli->env;
The env method returns the environment variables in the running process.
# given $cli $cli->args;
The args method returns the ordered arguments passed to the constructor or cli.
# given $cli $cli->opts;
The opts method returns the parsed options passed to the constructor or cli, based on the specifications defined in the specs method.
# given $cli $cli->run;
The run method automatically executes the subclass unless it's being imported by another package.
# given $cli $cli->parse($data, $specs, $meta);
The parse method parses command-line options using Getopt::Long and does not mutate @ARGV. The first argument should be an arrayref containing the data to be parsed; E.g. [@ARGV]. The second argument should be an arrayref of Getopt::Long option specifications. The third argument (optionally) should be additional options to be passed along to Getopt::Long::Configure.
@ARGV
[@ARGV]
# given $cli $cli->main(%args);
The main method is (by convention) the starting point for an automatically executed subclass, i.e. this method is run by default if the subclass is run as a script. This method should be overriden by the subclass. This method is called with the named arguments env, args and opts.
env
args
opts
# given $cli $cli->specs;
The specs method (if present) returns a list of Getopt::Long option specifications. This method should be overriden by the subclass.
To install Data::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Object
CPAN shell
perl -MCPAN -e shell install Data::Object
For more information on module installation, please visit the detailed CPAN module installation guide.