| 1 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # App::Pipeline::Simple | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## no critic | ||||||||||||||||||||||||||||||||||||||||||
| 5 | package App::Pipeline::Simple; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Simple workflow manager | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | our $VERSION = '0.9.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use YAML::Syck; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use Log::Log4perl qw(get_logger :levels :no_extra_logdie_message); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | #use Data::Printer; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # Global variables | ||||||||||||||||||||||||||||||||||||||||||
| 23 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | my $logger_level = { | |||||||||||||||||||||||||||||||||||||||||
| 26 | '-1' => $WARN, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | '0' => $INFO, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | '1' => $DEBUG, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # new | ||||||||||||||||||||||||||||||||||||||||||
| 33 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # create an object | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | my $self = bless {}, ref ($class) || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # set all @args into this object with 'set' values | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | my (%args) = (@args == 1 ? (value => $args[0]) : @args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # do dir() first so that we know where to write the log | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | $self->dir($args{'dir'}) if defined $args{'dir'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | # start logging | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | $self->_configure_logging; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | foreach my $key (keys %args) { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | ▶ | next if $key eq 'config'; # this needs to be evaluated last | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 13 | ▶ | next if $key eq 'dir'; # done this | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | ## no critic | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 10 | $self->$key($args{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # delayed to first find out the verbosity level | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | $self->logger->info("Logging into file: [ ". $self->dir. '/pipeline.log'. " ]"); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # this argument needs to be done last | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | $self->config($args{'config'}) if defined $args{'config'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # look into dir() if config not given | ||||||||||||||||||||||||||||||||||||||||||
| 64 | $self->config($self->dir. '/config.yml') | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | if not $self->{config} and defined $self->dir and -e $self->dir. '/config.yml'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $self->{"config"} and defined $self->dir and -e $self->dir . '/config.yml'
not $self->{"config"} and defined $self->dir
MC/DC0%0/3
not $self->{"config"} and defined $self->dir and -e $self->dir . '/config.yml'
not $self->{"config"}
defined $self->dir
-e $self->dir . '/config.yml'
Truth table50%2/4
not(A) and B and C
A= not $self->{"config"}B= defined $self->dirC= -e $self->dir . '/config.yml'
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # die if no config found | ||||||||||||||||||||||||||||||||||||||||||
| 68 | $self->logger->fatal("pipeline config file not provided or not found in pwd") | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | if not $self->{config} and not $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"config"} or $self->debug
MC/DC0%0/2
$self->{"config"} or $self->debug
$self->{"config"}
$self->debug
Truth table66%2/3
A or B
A= $self->{"config"}B= $self->debug
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # done | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # Configure the logger | ||||||||||||||||||||||||||||||||||||||||||
| 78 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | sub _configure_logging { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_configure_logging: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | my $logger_config = q( | |||||||||||||||||||||||||||||||||||||||||
| 84 | log4perl.category.Pipeline = INFO, Screen | ||||||||||||||||||||||||||||||||||||||||||
| 85 | log4perl.appender.Screen = Log::Log4perl::Appender::Screen | ||||||||||||||||||||||||||||||||||||||||||
| 86 | log4perl.appender.Screen.stderr = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 87 | log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout | ||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | Log::Log4perl->init_once( \$logger_config ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | my $logger = Log::Log4perl->get_logger("Pipeline"); | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | ▶ | if ($self->dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $to_file = Log::Log4perl::Appender->new | |||||||||||||||||||||||||||||||||||||||||
| 95 | ("Log::Log4perl::Appender::File", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | name => 'Log', | ||||||||||||||||||||||||||||||||||||||||||
| 97 | filename => $self->dir. '/pipeline.log', | ||||||||||||||||||||||||||||||||||||||||||
| 98 | mode => 'append'); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | my $pattern = '%d [%r] %p %L | %m%n'; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | my $layout = Log::Log4perl::Layout::PatternLayout->new ($pattern); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | $to_file->layout ($layout); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | $logger->add_appender($to_file); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | $logger->level( $INFO ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | $self->logger($logger); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||||||||||||||||
| 114 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | ▶ | sub verbose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | $self->{_verbose} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # verbose = -1 0 1 | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # log level = WARN INFO DEBUG | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | $self->logger->level( $logger_level->{$value} ); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | return $self->{_verbose}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 53 | ▶ | sub id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 53 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 53 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 15 | $self->{_id} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 53 | return $self->{_id}; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | sub description { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | $self->{_description} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | return $self->{_description}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | $self->{_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | return $self->{_name}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | sub path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $self->{_path} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | return $self->{_path}; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | sub next_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_id: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $self->{_next_id} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | return $self->{_next_id}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | ▶ | sub input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | $self->{_input} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | return $self->{_input}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | ▶ | sub itype { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
itype: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 6 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | $self->{_itype} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | return $self->{_itype}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->{_start} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | return $self->{_start}; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $self->{_stop} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return $self->{_stop}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | $self->{_debug} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | return $self->{_debug}; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 59 | ▶ | sub logger { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logger: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 59 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 59 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 5 | $self->{_logger} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 59 | return $self->{_logger}; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | ▶ | sub config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=18 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | my ($self, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | ▶ | if ($config) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | $self->logger->info("Using config file: [ ". $config. " ]"); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | my $pwd = `pwd`; chomp $pwd; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | $self->logger->debug("pwd: $pwd"); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | $self->logger->debug("config: $config"); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | ▶ | die unless -e $config; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | # copy the pipeline config | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | ▶ | if ($self->dir and not -e $self->dir."/config.yml") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->dir and not -e $self->dir . '/config.yml'
MC/DC0%0/2
$self->dir and not -e $self->dir . '/config.yml'
$self->dir
not -e $self->dir . '/config.yml'
Truth table33%1/3
A and not(B)
A= $self->dirB= not -e $self->dir . '/config.yml'
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | copy $config, $self->dir."/config.yml"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | $self->logger->info("Config file [ $config ] copied to: [ ". | |||||||||||||||||||||||||||||||||||||||||
| 235 | $self->dir."/config.yml ]"); | ||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 3 | $self->{config} = LoadFile($self->dir."/config.yml"); | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # set pipeline start parameters | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | $self->id('s0'); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | $self->name($self->{config}->{name} || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'config'}{'name'} || ''
MC/DC0%0/1
$self->{'config'}{'name'} || ''
$self->{'config'}{'name'}
Truth table50%1/2
A
A= $self->{'config'}{'name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | ▶ | $self->description($self->{config}->{description} || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'config'}{'description'} || ''
MC/DC0%0/1
$self->{'config'}{'description'} || ''
$self->{'config'}{'description'}
Truth table50%1/2
A
A= $self->{'config'}{'description'}
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # go through all steps once | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | my $nexts; # hashref for finding start point(s) | |||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | for my $id (sort keys %{$self->{config}->{steps}}) { | |||||||||||||||||||||||||||||||||||||||||
| 248 | 11 | my $step = $self->{config}->{steps}->{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # bless all steps into Pipeline objects | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 11 | bless $step, ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | #print "ERROR: $id already exists\n" if defined $self->step($id); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | # create the list of all steps to be used by each_step() | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 11 | $step->id($id); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 11 | push @{$self->{steps}}, $step; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # a step without a parent is a starting point, store those with children | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 11 | foreach my $next (@{$step->{next}}) { | |||||||||||||||||||||||||||||||||||||||||
| 260 | 8 | $nexts->{$next}++; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # store starting points, not listed as children | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | foreach my $step ($self->each_step) { | |||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | push @{$self->{next}}, $step->id | |||||||||||||||||||||||||||||||||||||||||
| 267 | 11 | ▶ | unless $nexts->{$step->id} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | #run needs to fail if starting input values are not set! | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # my $s = p $self->config;# here x | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # $self->logger->info("Self-config after: [". $s. "]" );# here x | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | # insert the startup value into the appropriate starting step | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # unless we are reading old config | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | if ($self->itype and $self->input) { # only if new starting input value has been given | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->itype and $self->input
MC/DC50%1/2
$self->itype and $self->input
$self->itype
$self->input
Truth table66%2/3
A and B
A= $self->itypeB= $self->input
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | $self->logger->info("Input value: [". $self->input. "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | $self->logger->info("Input type: [". $self->itype. "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | my $real_start_id; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | for my $step ( $self->each_step) { | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | # if input type is right, insert the value | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # note only one of the each type can be used | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | foreach my $key ( keys %{$step->{args}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | my $arg = $step->{args}->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | ▶ | next unless $key eq 'in'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | next unless defined $arg->{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | ▶ | next unless $arg->{type} eq $self->itype; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $arg->{value} = $self->input; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | $real_start_id = $step->id; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | $self->{next} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | push @{$self->{next}}, $real_start_id; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | $self->logger->info("Starting point: [". $real_start_id. "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # the stored config file needs to be overwritten with these modifications | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | open my $OUT, ">", $self->dir."/config.yml"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | print $OUT Dump ($self->config); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | return $self->{config}; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # | ||||||||||||||||||||||||||||||||||||||||||
| 309 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 46 | ▶ | sub dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dir: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 46 | my ($self, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 46 | ▶ | if ($dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | ▶ | mkdir $dir unless -e $dir and -d $dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $dir and -d $dir
MC/DC50%1/2
-e $dir and -d $dir
-e $dir
-d $dir
Truth table66%2/3
A and B
A= -e $dirB= -d $dir
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 4 | ▶ | croak "Can not create project directory $dir" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $dir and -d $dir
MC/DC0%0/2
-e $dir and -d $dir
-e $dir
-d $dir
Truth table33%1/3
A and B
A= -e $dirB= -d $dir
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | unless -e $dir and -d $dir; | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | $self->{_dir} = $dir; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 46 | ▶ | $self->{_dir} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # | ||||||||||||||||||||||||||||||||||||||||||
| 323 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 16 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 16 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 16 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 16 | return $self->{config}->{steps}->{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 30 | ▶ | sub each_next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
each_next: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | #map { $_->{id} } grep { $_->{id} } @{shift->{next}}; | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 30 | @{shift->{next}}; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 5 | ▶ | sub each_step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
each_step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 5 | @{shift->{steps}}; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=23 SCAR=46.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | ▶ | unless ($self->dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $self->logger->fatal("Need an output directory to run()"); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | croak "Need an output directory to run()"; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # check for input file and warn if not found | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 2 | chdir $self->{_dir}; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # Determine where in the pipeline to start | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | my @steps; # array of next execution points | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | # User has given a starting point id | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | ▶ | if ($self->start) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $self->logger->info("Start point: user input [". $self->start. "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | push @steps, $self->start; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $self->logger->info("Starting at [". $self->start. "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # determine if and where the execution of the pipeline was interrupted | ||||||||||||||||||||||||||||||||||||||||||
| 366 | elsif (-e $self->dir. "/pipeline.log") { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | $self->logger->info("Start point: consult the log [". | |||||||||||||||||||||||||||||||||||||||||
| 368 | $self->dir. "/pipeline.log ]"); | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | ▶ | open my $LOG, '<', $self->dir. "/pipeline.log" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | or $self->logger->fatal("Can't open ". $self->dir. | ||||||||||||||||||||||||||||||||||||||||||
| 371 | "/pipeline.log for reading: $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 2 | my $in_execution; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | # look into only the latest run | ||||||||||||||||||||||||||||||||||||||||||
| 375 | my @log; | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | while (<$LOG>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | push @log, $_; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | @log = () if /Run started/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | my $done; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | for (@log) { | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | next unless /\[(\d+)\]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | undef $in_execution; # start of a new run | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | next unless /\| (Running|Finished) +\[(\w+)\]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $in_execution->{$2}++ if $1 eq 'Running'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | delete $in_execution->{$2} if $1 eq 'Finished'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | $done = 1 if /DONE/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 2 | @steps = sort keys %$in_execution; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | ▶ | if (scalar @steps == 0 and $done) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
scalar @steps == 0 and $done
MC/DC0%0/2
scalar @steps == 0 and $done
scalar @steps == 0
$done
Truth table33%1/3
A and B
A= scalar @steps == 0B= $done
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->logger->warn("Pipeline is already finished. ". | |||||||||||||||||||||||||||||||||||||||||
| 394 | "Drop -config and define the start step to rerun" ); | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | elsif (@steps) { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->logger->info("Continuing at ". $steps[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 399 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # start from beginning | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | @steps = $self->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | $self->logger->info("Starting at [". $steps[0] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 406 | # start from beginning | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $self->logger->info("Start point: start from beginning" ); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | @steps = $self->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->logger->info("Starting at [". $steps[0] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | # | ||||||||||||||||||||||||||||||||||||||||||
| 414 | # Execute one step at a time | ||||||||||||||||||||||||||||||||||||||||||
| 415 | # | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | $self->logger->info("Run started"); | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | ▶ | while (my $step_id = shift @steps) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 6 | $self->logger->debug("steps: [". join (", ", @steps). "]"); | |||||||||||||||||||||||||||||||||||||||||
| 421 | 6 | my $step = $self->step($step_id); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 6 | ▶ | croak "ERROR: Step [$step_id] does not exist" unless $step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | # check that we got an object | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | # check that the input file exists | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 6 | foreach my $arg (@{$step->{arg}}) { | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | next unless $arg->{key} eq 'in'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | next unless $arg->{type} =~ /file|dir/ ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 6 | my $command = $step->render; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 6 | $self->logger->info("Running [". $step->id . "] $command" ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | 6 | `$command`; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 6 | $self->logger->info("Finished [". $step->id . "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | # Add next step(s) to the execution queue unless | ||||||||||||||||||||||||||||||||||||||||||
| 437 | # the user has asked to stop here | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 6 | ▶ | if ( defined $self->{_stop} and $step->id eq $self->{_stop} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"_stop"} and $step->id eq $self->{"_stop"}
MC/DC0%0/2
defined $self->{"_stop"} and $step->id eq $self->{"_stop"}
defined $self->{"_stop"}
$step->id eq $self->{"_stop"}
Truth table33%1/3
A and B
A= defined $self->{"_stop"}B= $step->id eq $self->{"_stop"}
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $self->logger->info("Stopping at [". $step->id . "]" ); | |||||||||||||||||||||||||||||||||||||||||
| 440 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 6 | push @steps, $step->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 2 | $self->logger->info("DONE" ); | |||||||||||||||||||||||||||||||||||||||||
| 446 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 451 | # Render a step into a command line string | ||||||||||||||||||||||||||||||||||||||||||
| 452 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 16 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=15 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 16 | my ($step, $display) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 16 | my $str; | |||||||||||||||||||||||||||||||||||||||||
| 458 | # path to program | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 16 | ▶ | if (defined $step->{path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $str .= $step->{path}; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | $str .= '/' unless substr($str, -1, 1) eq '/' ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # program name | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 16 | ▶ | $str .= $step->{name} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$step->{'name'} || ''
MC/DC0%0/1
$step->{'name'} || ''
$step->{'name'}
Truth table50%1/2
A
A= $step->{'name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | # arguments | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 16 | my $endstr = ''; | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 16 | foreach my $key (keys %{$step->{args}}) { | |||||||||||||||||||||||||||||||||||||||||
| 470 | 44 | my $arg = $step->{args}->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 44 | ▶ | if (ref $arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 32 | ▶ | if (defined $arg->{type} and $arg->{type} eq 'unnamed') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $arg->{"type"} and $arg->{"type"} eq "unnamed"
MC/DC50%1/2
defined $arg->{"type"} and $arg->{"type"} eq "unnamed"
defined $arg->{"type"}
$arg->{"type"} eq "unnamed"
Truth table66%2/3
A and B
A= defined $arg->{"type"}B= $arg->{"type"} eq "unnamed"
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | $str .= ' '. $arg->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | ▶ | elsif (defined $arg->{type} and $arg->{type} eq 'redir') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $arg->{"type"} and $arg->{"type"} eq "redir"
MC/DC0%0/2
defined $arg->{"type"} and $arg->{"type"} eq "redir"
defined $arg->{"type"}
$arg->{"type"} eq "redir"
Truth table33%1/3
A and B
A= defined $arg->{"type"}B= $arg->{"type"} eq "redir"
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 28 | ▶ | if ($key eq 'in') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | 12 | $endstr .= " < ". $arg->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | elsif ($key eq 'out') { | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 16 | $endstr .= " > ". $arg->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | croak "Unknown key ". $key; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | elsif (defined $arg->{value}) { | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $str .= " -". $key. " ". $arg->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 488 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | $str .= " -". $key; | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 12 | ▶ | if ($arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 3 | $str .= " -". $key. " ". $arg; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 9 | $str .= " -". $key; | |||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 16 | $str .= $endstr; | |||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 16 | ▶ | $str =~ s/(['"])/\\$1/g if $display; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 16 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=12 SCAR=36.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | $self->logger->info("Stringify starting" ); | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 2 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 512 | # add checks for duplicated ids | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | # add check for a next pointer that leads nowhere | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | my @steps = $self->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | my $outputs; # hashref for storing input and output filenames | |||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | while (my $step_id = shift @steps) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 10 | my $step = $self->step($step_id); | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 10 | push @res, $step->id, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 10 | push @res, "\t", $step->render('4display'), " # "; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 10 | map { push @res, "->", $_, " " } $step->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 10 | push @steps, $step->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 10 | foreach my $arg (@{$step->{arg}}) { | |||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if ($arg->{key} eq 'out') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | for ($step->each_next) { | |||||||||||||||||||||||||||||||||||||||||
| 531 | push @res, "\n\t", "WARNING: Output file [". | ||||||||||||||||||||||||||||||||||||||||||
| 532 | $arg->{value}."] is read by [", | ||||||||||||||||||||||||||||||||||||||||||
| 533 | $outputs->{$arg->{value}}, "] and [$_]" | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | if $outputs->{$arg->{value}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $outputs->{$arg->{value}} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | ▶ | elsif ($arg->{key} eq 'in' and $arg->{type} ne 'redir') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$arg->{"key"} eq "in" and $arg->{"type"} ne "redir"
MC/DC0%0/2
$arg->{"key"} eq "in" and $arg->{"type"} ne "redir"
$arg->{"key"} eq "in"
$arg->{"type"} ne "redir"
Truth table0%0/3
A and B
A= $arg->{"key"} eq "in"B= $arg->{"type"} ne "redir"
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | my $prev_step_id = $outputs->{$arg->{value}} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$outputs{$arg->{'value'}} || ''
MC/DC0%0/1
$$outputs{$arg->{'value'}} || ''
$$outputs{$arg->{'value'}}
Truth table0%0/2
A
A= $$outputs{$arg->{'value'}}
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | push @res, "\n\t". "ERROR: Output from the previous step is not [". | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | ($arg->{value} || ''). "]" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$prev_step_id ne $step->id and $prev_step_id eq $self->id
$arg->{'value'} || ''
MC/DC0%0/2
$prev_step_id ne $step->id and $prev_step_id eq $self->id
$prev_step_id ne $step->id
$prev_step_id eq $self->id
MC/DC0%0/1
$arg->{'value'} || ''
$arg->{'value'}
Truth table0%0/3
A and B
A= $prev_step_id ne $step->idB= $prev_step_id eq $self->id
Truth table0%0/2
A
A= $arg->{'value'}
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | if $prev_step_id ne $step->id and $prev_step_id eq $self->id; | ||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | # test for steps not referenced by other steps (missing next tag) | ||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 10 | push @res, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | return join '', @res; | |||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | ▶ | sub graphviz { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
graphviz: called CC=4 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | my $function = shift; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | $self->logger->info("Graphing started. Redirect to a dot file" ); | |||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | require GraphViz; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my $g= GraphViz->new; | |||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | my $end; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $g->add_node($self->id, | |||||||||||||||||||||||||||||||||||||||||
| 564 | label => $self->id. | ||||||||||||||||||||||||||||||||||||||||||
| 565 | $self->render('4display'), rank => 'top'); | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | map { $g->add_edge('s0' => $_) } $self->each_next; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | if ($self->description) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $g->add_node('desc', label => $self->description, | |||||||||||||||||||||||||||||||||||||||||
| 569 | shape => 'box', rank => 'top'); | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $g->add_edge('s0' => 'desc'); | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | foreach my $step ($self->each_step) { | |||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $g->add_node($step->id, label => $step->id ); | |||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | if ($step->each_next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | map { $g->add_edge($step->id => $_, label => " ". $step->render('display') ) } | |||||||||||||||||||||||||||||||||||||||||
| 577 | $step->each_next; | ||||||||||||||||||||||||||||||||||||||||||
| 578 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $end++; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $g->add_node($end, label => ' '); | |||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $g->add_edge($step->id => $end, label => " ". $step->render('display') ); | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | return $g->as_dot; | |||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | $self->logger->info("Graphing done. Process the dot ". | |||||||||||||||||||||||||||||||||||||||||
| 588 | "file (e.g. dot -Tpng p.dot|display " ); | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | __END__ | ||||||||||||||||||||||||||||||||||||||||||