File Coverage

blib/lib/Process/Pipeline/DSL.pm
Criterion Covered Total %
statement 24 30 80.0
branch 1 4 25.0
condition n/a
subroutine 6 7 85.7
pod 0 2 0.0
total 31 43 72.0


line stmt bran cond sub pod time code
1             package Process::Pipeline::DSL;
2 9     9   158895 use 5.008001;
  9         27  
3 9     9   36 use strict;
  9         9  
  9         153  
4 9     9   18 use warnings;
  9         18  
  9         180  
5 9     9   2916 use Process::Pipeline;
  9         18  
  9         243  
6              
7 9     9   36 use Exporter qw/ import /;
  9         9  
  9         2052  
8             our @EXPORT = qw/ proc set /;
9              
10             our $PIPELINE;
11             our $PROCESS;
12              
13             sub set {
14 0 0   0 0 0 die "Cannot call outside proc()\n" unless $PROCESS;
15 0         0 my ($key, $value) = @_;
16 0         0 $PROCESS->set($key, $value);
17             }
18              
19             sub proc (&;@) {
20 57     57 0 13891 my ($code, @process) = @_;
21 57 50       96 if (!$PIPELINE) {
22 57         161 local $PIPELINE = Process::Pipeline->new;
23 57         140 local $PROCESS = Process::Pipeline::Process->new;
24 57         88 $PROCESS->cmd($code->());
25 57         113 $PIPELINE->_push($PROCESS);
26 57         101 $PIPELINE->_push($_) for map { @{$_->{process}} } @process;
  44         49  
  44         118  
27 57         110 return $PIPELINE;
28             } else {
29 0           local $PROCESS = Process::Pipeline::Process->new;
30 0           $PROCESS->cmd($code->());
31 0           return $PROCESS;
32             }
33             }
34              
35             1;