The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Command::Template::Runner

SYNOPSIS

   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

DESCRIPTION

This class allows running commands generated by a Command::Template::Instance object, by means of IPC::Run.

INTERFACE

instance

   my $instance = $obj->instance;

Returns a reference to the Command::Template::Instance object used to generate the commands that are then executed.

last_run

   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).

new

   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).

options

   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.

run

   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").

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".

ANYTHING ELSE (INCLUDING AUTHOR, COPYRIGHT AND LICENSE)

See documentation for Command::Template.