NAME

OmniPITR::Tools::CommandPiper - Class for building complex pipe-based shell commands

SYNOPSIS

General usage is:

my $run = OmniPITR::Tools::CommandPiper->new( 'ls', '-l' );
$run->add_stdout_file( '/tmp/z.txt' );
$run->add_stdout_file( '/tmp/y.txt' );
my $checksummer = $run->add_stdout_program( 'md5sum', '-' );
$checksummer->add_stdout_file( '/tmp/checksum.txt' );

system( $run->command() );

Will run:

ls -l | tee /tmp/z.txt /tmp/y.txt | md5sum - > /tmp/checksum.txt

DESCRIPTION

It is important to note that to make the final shell command work, it should be run within bash (or other shell that accepts constructions like:

program > >( other program )

And that you have tee program in path.

new()

Object contstructor.

Given options are treated as program that is run to generate stdout.

set_write_mode()

Sets whether writes of data should overwrite, or append (> vs. >>)

Accepted values:

  • overwrite

  • append

Any other would switch back to default, which is overwrite.

set_tee_path()

Sets path to tee program, when using tee is required.

$program->set_tee_path( '/opt/gnu/bin/tee' );

Value of tee path will be automaticaly copied to all newly created stdout and stderr programs.

add_stdout_file()

Adds another file destination for stdout from current program.

add_stdout_program()

Add another program that should receive stdout from current program, as its (the new program) stdin.

add_stderr_file()

Add another program that should receive stdout from current program, as its (the new program) stdin.

add_stderr_program()

Add another program that should receive stderr from current program, as its (the new program) stdin.

new_subprogram()

Helper function to create sub-programs, inheriting settings

command()

Returns stringified command that should be ran via "system" that does all the described redirections.

stdout()

Internal function returning whole stdout redirection for current program, or undef if there are no stdout consummers.

stderr()

Internal function returning whole stderr redirection for current program, or undef if there are no stderr consummers.

tee_maker()

Receives array of arrayrefs. Each element is array with two values:

1. type of element "PATH" - path to file, "CMD" - command to run
2. path to file, or command line of program to run.

Returns single item of [ "PATH", "/path/to/file" ] or [ "CMD", "command to run" ] that will deliver data to all receivers.