Command::Template::Runner
use Command::Template::Instance; use Command::Template::Runner; my @command = qw{ ls [options=-l] <dir> }; my $instance = Command::Template::Instance->new(@command); my $runner = Command::Template::Runner->new($instance); # run command qw< ls -l / >, returns a Command::Template::RunRecord my $r = $runner->run(dir => '/'); my $run_successful = $r->success; my $exit_code = $r->exit_code; # 0 is OK as usual in UNIX my $received_signal = $r->signal; # e.g. if killed, ... my $stdout = $r->stdout; my $stderr = $r->stderr; my $merged = $r->merged; # stderr then stdout, no newlines
This class allows running commands generated by a Command::Template::Instance object, by means of IPC::Run.
my $instance = $obj->instance;
Returns a reference to the Command::Template::Instance object used to generate the commands that are then executed.
my $run = $obj->last_run;
Returns the Command::Template::Runner::Record object of the last run (i.e. the same returned by the last call to the "run" method).
my $runner = Command::Template::Runner->new($instance);
Constructor. Accepts a single parameter, that is supposed to support the interface provided by Command::Template::Instance (in particular, to support its "generate" in Command::Template::Instance method).
my $href = $obj->options; $obj->options({ ... });
Get/set the options for running. Options are represented by a hash reference with the following keys:
stdin
a string holding the standard input to provide to the command;
timeout
a timeout for running the command.
my $record = $obj->run(%bindings_or_options);
Run a command using IPC::Run:
The input hash %bindings_or_options is first divided into bindings and options; the latter are set with a leading - character (e.g. -stdin is used to the standard input, while -timeout to set the timeout; also see "options").
%bindings_or_options
-
-stdin
-timeout
The bindings are used to generate the actual command using the Command::Template::Instance object held by "instance"; this command is then executed with the provided options (defaulting to those set via "options"), leveraging IPC::Run.
The outcome of the call is wrapped into a Command::Template::Runner::Record object and returned. It is also later available via method "last_run".
See documentation for Command::Template.
To install Command::Template, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Command::Template
CPAN shell
perl -MCPAN -e shell install Command::Template
For more information on module installation, please visit the detailed CPAN module installation guide.