Dearest Monks, I need some guidance. I've decided to glue up a few different programs (let's call them A, B, C) that convert input to output. I would like to do fanciful things with my objects that can utilize these different programs. My goals: 1. ability to construct object from different inputs and output corresponding to a given program (A.inp A.out B.inp B.out). 2. ability to write inputs (A.inp B.inp C.inp) from object 3. ability to run the programs to generate output in files or memory. for 3. create scratch directory and run in that directory if requested. my current path: create objects for each program that can process/generate inputs and process outputs. I'm using roles to share code between them. I'm trying to get everything organized and maintainable. Do you have any advice to develop this with some sanity? it's driving me crazy! below is the role that binds up the File Pipe and Slurp roles.

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) i +f $self->mode eq '1d'; print $self->command . "\n"; $self->clear_command() if ($self->mode =~ /0/); }

In reply to Files Pipes and Slurps Oh My by docdurdee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.