나는 아직도 사슴에 빠지다. 그러나 그것은 나에게 침을 흘린다! 아래는 단순화 된 버전입니다. 외부 프로그램을 실행하는 데 사용할 수있는 객체 종속 입력 파일을 생성하십시오. 이러한 외부 프로그램은 계산적으로 집중적으로 수행 할 수 있으며, 많은 외부 객체에 대해 (외부 매개 변수 조정의 함수로) 객체에 여러 번 출력을 처리합니다. 아래의 모듈은 잘 작동하지만 (더 나은/깨끗한 방법으로)이를 수행 할 수 있습니다. 이 작업을 수행하는 적절한 방법은 무엇입니까? 이 모든 객체들은 자신의 작은 세상에 살고 있기 때문에, 객체 컬렉션을 효율적으로 수행하기 위해 이들의 배치를 병렬로 실행할 수 있어야합니다. 이것에 대한 조언! ??무스로 파이프를 올바르게 여는 방법은 무엇입니까?
{
package input_genrun;
use Moose;
use IO::Pipe;
use FileHandle;
has 'name', is => 'ro', isa =>'Str';
has 'exe' => (
is => 'ro',
isa => 'Str',
default => '/usr/local/bin/bar',
);
has 'inp_fh' => (
is => 'rw',
isa=> 'FileHandle',
default => sub {
my $handle = FileHandle->new;
return $handle;
}
);
has 'out_fh' => (
is => 'rw',
isa=> 'IO::Pipe',
default => sub {
my $handle = IO::Pipe->new;
return $handle;
}
);
sub inp_wrt
{
my ($self,$object) = @_;
my $filename = $object->name() . ".inp";
my $fh = FileHandle->new;
$fh->open(">" . $filename);
print $fh "foo \n";
print $fh "bar \n";
$fh->close;
}
sub run
{
my ($self, $object) = @_;
my $name = $object->name() . ".inp";
my $exe = $self->exe;
my $command = $self->exe . " $name";
$self->out_fh()->reader($command);
return($self->out_fh());
}
}
my $l = input_genrun->new(name=> 'foo_l',exe=> 'wc');
my $m = input_genrun->new(name=> 'foo_m',exe=> 'cat');
my $n = input_genrun->new(name=> 'foo_n',exe=> 'tac');
$l->inp_wrt($l);
$m->inp_wrt($m);
$n->inp_wrt($n);
my $pipe_l = $l->run($l);
my $pipe_m = $m->run($m);
my $pipe_n = $n->run($n);
while (<$pipe_l>){
print "from_l: $_";
}
while (<$pipe_m>){
print "from_m: $_";
}
while (<$pipe_n>){
print "from_n: $_";
}