package FhPhRole; use Moose::Role; use Moose::Util::TypeConstraints; #goals to be able to use molecular object to do fun stuff: # 0. read/write from/to input_filename # a. read # b. write # # 1. read/create output # a. read output file # b. pipe to output # c. pipe to memory # d. tee it to output and memory with qw(FileRole PipeRole SlurpRole); requires '_input'; has 'exe' => ( is => 'rw', isa => 'Str', default => '/usr/local/bin/bar', ); subtype 'MyMode', as 'Str', where { $_[0] =~ /0a|0b|1a|1b|1c|1d/ }, message { "0a. read from input \n 0b. write input \n" . "1a. read from output \n" . "1b. write to output \n 1c. pipe to memory\n" . "1d. tee it!\n""}; has 'mode' => ( is => 'ro', required => 1, isa => 'MyMode', ); has 'scratch' => ( is => 'ro', isa=> 'Str', predicate => 'has_scratch', ); # if we have scratch make the scratch and run in there # sub BUILD { my $self = shift; if ($self->has_scratch and $self->mode =~ /0b|1b|1c|1d/){ mkdir $self->scratch unless (-e $self->scratch); $self->exe("cd ". $self->scratch ." ; " . $self->exe); } $self->rw_input_filename('w'); $self->rw_input_filename('r') if $self->mode eq '0a'; $self->rw_output_filename('r') if $self->mode eq '1a'; $self->rw_output_filename('w') if $self->mode eq '1b'; $self->command($self->exe . " ". $self->input_filename); $self->command($self->command . " > " . $self->output_filename) if $self->mode eq '1b'; $self->command($self->command . " |tee " . $self->output_filename) if $self->mode eq '1d'; print $self->command . "\n"; $self->clear_command() if ($self->mode =~ /0/); }