lib/Sys/Bprsync/Worker.pm

filter: Statementstmt 21.9% 51 / 232 Branchbran 0.0% 0 / 84 Conditioncond 0.0% 0 / 74 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 44.0% 11 / 25 Podpod 100% 1 / 1 totaltotal 14.1% 63 / 446 CC 73 SCAR 56.6
CC
73
Cov
13%
_rsync_cmd
600.0
_check_timeframe
462.0
_init
182.0
CRAP 286.1
↑ Summary script/bprsync.pl »
1 package Sys::Bprsync::Worker;
2 {
3 1 $Sys::Bprsync::Worker::VERSION = '0.25';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Sys::Bprsync::Worker::AUTHORITY = 'cpan:TEX';
7 }
8 # ABSTRACT: bprsync worker, does all the work
9  
10 1 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # use IO::Handle;
18 # use autodie;
19 # use MooseX::Params::Validate;
20 1 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use File::Blarf;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Sys::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 extends 'Job::Manager::Worker';
28  
29 1 has 'parent' => (
30 'is' => 'ro',
31 'isa' => 'Sys::Bprsync',
32 'required' => 1,
33 );
34  
35 1 has 'sys' => (
36 'is' => 'rw',
37 'isa' => 'Sys::Run',
38 'lazy' => 1,
39 'builder' => '_init_sys',
40 );
41  
42 1 has 'name' => (
43 'is' => 'ro',
44 'isa' => 'Str',
45 'required' => 1,
46 );
47  
48 1 has '_job_prefix' => (
49 'is' => 'ro',
50 'isa' => 'Str',
51 'lazy' => 1,
52 'builder' => '_init_job_prefix',
53 );
54  
55 0 ▶sub _init_job_prefix {
Subroutine _init_job_prefix: not called CC=1 SCAR=6.9
56 0 return 'Jobs';
57 }
58  
59 # ArrayRef[Str] - not required
60 1 foreach my $key (qw(execpre execpost exclude)) {
61 has $key => (
62 'is' => 'ro',
63 'isa' => 'ArrayRef[Str]',
64 'required' => 0,
65 0 ▶ 'default' => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 3 );
67 }
68  
69 # Str - not required
70 1 foreach my $key (qw(description source destination timeframe excludefrom options rsh rshopts)) {
71 8 has $key => (
72 'is' => 'ro',
73 'isa' => 'Str',
74 'required' => 0,
75 'clearer' => 'clear_'.$key,
76 'predicate' => 'has_'.$key,
77 );
78 }
79  
80 # Bool - not required - default 0
81 1 foreach my $key (qw(compression numericids verbose delete nocrossfs hardlink dry sudo)) {
82 8 has $key => (
83 'is' => 'ro',
84 'isa' => 'Bool',
85 'required' => 0,
86 'clearer' => 'clear_'.$key,
87 'predicate' => 'has_'.$key,
88 );
89 }
90  
91 # Int - not required
92 1 foreach my $key (qw(bwlimit)) {
93 1 has $key => (
94 'is' => 'ro',
95 'isa' => 'Int',
96 'required' => 0,
97 'clearer' => 'clear_'.$key,
98 'predicate' => 'has_'.$key,
99 );
100 }
101 1 has 'runloops' => (
102 'is' => 'ro',
103 'isa' => 'Int',
104 'default' => 3,
105 );
106  
107 has 'loop_status' => (
108 'is' => 'ro',
109 'isa' => 'HashRef',
110 0 ▶ 'default' => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 1 );
112  
113 1 has 'logfile' => (
114 'is' => 'ro',
115 'isa' => 'Str',
116 'lazy' => 1,
117 'builder' => '_init_logfile',
118 );
119  
120 1 has '_init_done' => (
121 'is' => 'rw',
122 'isa' => 'Bool',
123 'default' => 0,
124 );
125  
126 0 ▶sub _init_sys {
Subroutine _init_sys: not called CC=1 SCAR=6.9
127 0 my $self = shift;
128  
129 0 return $self->parent()->sys();
130 }
131  
132 0 ▶sub _init {
Subroutine _init: not called CC=13 SCAR=52.0
133 0 my $self = shift;
134  
135 0 ▶ return 1 if $self->_init_done();
Branch: 1 branch
BranchTrueFalseTotal
if $self->_init_done 0 0 0
136  
137 # ok, now we have a config and a job name, we should be able to
138 # get everything else from the config ...
139 # scalars ...
140 0 my $common_config_prefix = $self->parent()->config_prefix() . q{::} . $self->_job_prefix() . q{::} . $self->name() . q{::};
141 0 foreach my $key (qw(description timeframe excludefrom rsh rshopts compression options delete numericids bwlimit source destination nocrossfs hardlink sudo)) {
142 0 my $predicate = 'has_'.$key;
143 0 ▶ if ( !$self->$predicate() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->$predicate) { } 0 0 0
144 0 my $config_key = $common_config_prefix . $key;
145 0 my $val = $self->parent()->config()->get($config_key);
146 0 ▶ if ( defined($val) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
147 0 $self->parent()->logger()->log( message => 'Set '.$key.' ('.$config_key.') for job ' . $self->name() . ' to '.$val, level => 'debug', );
148 0 $self->{$key} = $val;
149 }
150 else {
151 0 my $msg = 'Recommended configuration key '.$key.' ('.$config_key.') not found!';
152 0 $self->parent()->logger()->log( message => $msg, level => 'debug', );
153 }
154 }
155 else {
156 0 $self->parent()->logger()->log( message => "Configration key $key is " . $self->{$key}, level => 'debug', );
157 }
158 }
159  
160 # arrays ...
161 0 foreach my $key (qw(execpre execpost exclude)) {
162 0 ▶ if ( !defined( $self->{$key} ) || ref( $self->{$key} ) ne 'ARRAY' || scalar( @{ $self->{$key} } ) < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{$key} or ref $self->{$key} ne 'ARRAY' or scalar @{$self->{$key};} < 1) { } 0 0 0
Condition0%0/6
not defined $self->{$key} or ref $self->{$key} ne "ARRAY" or scalar @{$self->{$key};} < 1
l!l&&r!l&&!r
000
not defined $self->{$key} or ref $self->{$key} ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $self->{$key} or ref $self->{$key} ne "ARRAY" or scalar @{$self->{$key};} < 1
not defined $self->{$key} ref $self->{$key} ne "ARRAY" scalar @{$self->{$key};} < 1
Truth table0%0/4
not(A) or B or C
A= not defined $self->{$key}B= ref $self->{$key} ne "ARRAY"C= scalar @{$self->{$key};} < 1
ABCresult
1XX1
01X1
0011
0000
163 0 my $config_key = $common_config_prefix . $key;
164 0 my @vals = $self->parent()->config()->get_array($config_key);
165 0 ▶ if (@vals) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 0 0 0
166 0 $self->parent()->logger()->log( message => 'Set '.$key.' ('.$config_key.') for job ' . $self->name() . ' to ' . join( q{:}, @vals ), level => 'debug', );
167 0 ▶ $self->{$key} = [@vals] if @vals;
Branch: 1 branch
BranchTrueFalseTotal
if @vals 0 0 0
168 }
169 }
170 else {
171 0 $self->parent()->logger()->log( message => 'Configration key '.$key.' is ' . $self->{$key}, level => 'debug', );
172 }
173 }
174  
175 0 ▶ if ( !$self->source() || !$self->destination() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->source and $self->destination) 0 0 0
Condition0%0/3
$self->source and $self->destination
!ll&&!rl&&r
000
MC/DC0%0/2
$self->source and $self->destination
$self->source $self->destination
Truth table0%0/3
A and B
A= $self->sourceB= $self->destination
ABresult
0X0
100
111
176 0 croak('Missing source or destination!');
177 }
178  
179 0 $self->_init_done(1);
180  
181 0 return 1;
182 }
183  
184 0 ▶sub _init_logfile {
Subroutine _init_logfile: not called CC=1 SCAR=6.9
185 0 my $self = shift;
186  
187 0 return $self->parent()->logfile() . '.rsync.' . $PID;
188 }
189  
190 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
191 0 my $self = shift;
192  
193 0 $self->_init();
194 0 $self->_prepare();
195 0 ▶ if ( !$self->_exec_pre() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_exec_pre) 0 0 0
196 0 $self->logger()->log( message => 'Exec-Pre failed', level => 'error', );
197 0 return;
198 }
199 0 my $status = $self->_mainloop();
200 0 $self->_cleanup($status);
201 0 $self->_exec_post();
202 0 return $status;
203 }
204  
205 0 ▶sub _prepare {
Subroutine _prepare: not called CC=1 SCAR=6.9
206 0 my $self = shift;
207  
208 # Nothing to do.
209 0 return 1;
210 }
211  
212 0 ▶sub _cleanup {
Subroutine _cleanup: not called CC=4 SCAR=30.0
213 0 my $self = shift;
214 0 my $status = shift;
215  
216 # cleanup logfile
217 0 ▶ if ( -e $self->logfile() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->logfile) { } 0 0 0
218 0 my $target = $self->parent()->logfile() . '.rsync';
219 0 ▶ if ( File::Blarf::cat( $self->logfile(), $target, { Flock => 1, Append => 1, } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (File::Blarf::cat($self->logfile, $target, {'Flock', 1, 'Append', 1})) { } 0 0 0
220 0 $self->logger()->log( message => 'Appended temporary logfile (' . $self->logfile() . ') to '.$target, level => 'debug', );
221 0 my $cmd = 'rm -f '.$self->logfile();
222 0 ▶ if($self->sys()->run_cmd($cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sys->run_cmd($cmd)) { } 0 0 0
223 0 $self->logger()->log( message => 'Removed temporary logfile: '.$self->logfile(), level => 'debug', );
224 } else {
225 0 $self->logger()->log( message => 'Failed to remove temporary logfile: '.$self->logfile(), level => 'warning', );
226 }
227 }
228 else {
229 0 $self->logger()->log( message => 'Failed to append temporary logfile (' . $self->logfile() . ') to '.$target, level => 'warning', );
230 }
231 }
232 else {
233 0 $self->logger()->log( message => 'No temporary logfile found at ' . $self->logfile(), level => 'notice', );
234 }
235  
236 # Nothing to do.
237 0 return 1;
238 }
239  
240 0 ▶sub _exec_pre {
Subroutine _exec_pre: not called CC=3 SCAR=24.8
241 0 my $self = shift;
242  
243 0 my $ok = 1;
244 0 foreach my $cmd ( @{ $self->execpre() } ) {
245 0 ▶ if ( $self->sys()->run_cmd($cmd) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sys->run_cmd($cmd)) { } 0 0 0
246 0 $self->logger()->log( message => 'Executed CMD '.$cmd.' w/ success.', level => 'debug', );
247 }
248 else {
249 0 $self->logger()->log( message => 'Could not execute CMD '.$cmd.' w/o error.', level => 'error', );
250 0 $ok = 0;
251 }
252 }
253 0 return $ok;
254 }
255  
256 0 ▶sub _exec_post {
Subroutine _exec_post: not called CC=3 SCAR=24.8
257 0 my $self = shift;
258  
259 0 foreach my $cmd ( @{ $self->execpost() } ) {
260 0 ▶ if ( $self->sys()->run_cmd($cmd) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sys->run_cmd($cmd)) { } 0 0 0
261 0 $self->logger()->log( message => 'Executed CMD '.$cmd.' w/ success.', level => 'debug', );
262 }
263 else {
264 0 $self->logger()->log( message => 'Could not execute CMD '.$cmd.' w/o error.', level => 'error', );
265 }
266 }
267  
268 0 return 1;
269 }
270  
271 0 ▶sub _rsync_cmd {
Subroutine _rsync_cmd: not called CC=24 SCAR=64.0
272 0 my $self = shift;
273  
274 0 my $cmd = q{};
275 0 $cmd .= $self->parent()->get_cmd_prefix();
276 0 $cmd .= '/usr/bin/rsync';
277  
278 0 my $rsyncd_mode = 0;
279 0 ▶ if ( $self->source() =~ m/::/ || $self->destination() =~ m/::/ || ( $self->rsh() && $self->rsh() =~ m/rsyncd/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->source =~ /::/ or $self->destination =~ /::/ or $self->rsh and $self->rsh =~ /rsyncd/) 0 0 0
Condition0%0/9
$self->source =~ /::/ or $self->destination =~ /::/ or $self->rsh and $self->rsh =~ /rsyncd/
l!l&&r!l&&!r
000
$self->source =~ /::/ or $self->destination =~ /::/
l!l&&r!l&&!r
000
$self->rsh and $self->rsh =~ /rsyncd/
!ll&&!rl&&r
000
MC/DC0%0/4
$self->source =~ /::/ or $self->destination =~ /::/ or $self->rsh and $self->rsh =~ /rsyncd/
$self->source =~ /::/ $self->destination =~ /::/ $self->rsh $self->rsh =~ /rsyncd/
Truth table0%0/5
A or B or C and D
A= $self->source =~ /::/B= $self->destination =~ /::/C= $self->rshD= $self->rsh =~ /rsyncd/
ABCDresult
1XXX1
01XX1
00111
000X0
00100
280 0 $rsyncd_mode = 1;
281 }
282  
283 0 my $opts = q{};
284 0 ▶ if ( $self->excludefrom() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->excludefrom) 0 0 0
285 0 $opts .= " --exclude-from=" . $self->excludefrom();
286 }
287 0 ▶ if ( $self->exclude() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exclude) 0 0 0
288 0 my @excludes = @{ $self->exclude() };
289 0 ▶ if (@excludes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@excludes) 0 0 0
290 0 $opts .= ' --exclude="';
291 0 $opts .= join( '" --exclude="', @excludes );
292 0 $opts .= q{"};
293 }
294 }
295 0 ▶ if ($rsyncd_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rsyncd_mode) { } 0 0 0
296 0 $self->logger()->log( message => 'Skipping rsh handling, using rsyncd mode.', level => 'debug', );
297 0 ▶ if ( $self->rshopts() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rshopts) 0 0 0
298  
299 # for e.g. password-file
300 0 $opts .= q{ } . $self->rshopts();
301 }
302 } else { # ssh mode
303 0 ▶ if ( $self->rsh() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rsh) { } 0 0 0
304 0 $opts .= ' -e "' . $self->rsh();
305 0 ▶ if ( $self->rsh() eq 'ssh' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rsh eq "ssh") 0 0 0
306 0 $opts .= $self->sys()->_ssh_opts();
307 }
308 }
309 else {
310 0 $opts .= ' -e "ssh '.$self->sys()->_ssh_opts();
311 }
312 0 ▶ if ( $self->rshopts() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rshopts) 0 0 0
313 0 $opts .= q{ } . $self->rshopts();
314 }
315 0 $opts .= q{"}; # finish args to -e (remote shell)
316 }
317 0 $opts .= ' -a'; # always set archive mode
318 0 ▶ if ( $self->hardlink() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hardlink) 0 0 0
319 0 $opts .= ' -H';
320 }
321 0 ▶ if ( $self->nocrossfs() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nocrossfs) 0 0 0
322 0 $opts .= ' -x';
323 }
324 0 ▶ if ( $self->verbose() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
325 0 $opts .= ' -v';
326 }
327 0 ▶ if ( $self->compression() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compression) 0 0 0
328 0 $opts .= ' -z';
329 }
330 0 ▶ if ( $self->options() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options) 0 0 0
331 0 $self->parent()->logger()->log(
332 message => q{DEPRECATION WARNING: The use of 'options' is deprecated! Please don't use it anymore! There are individual options now.},
333 level => 'warning'
334 );
335  
336 # don't prepend '-' if already present
337 0 ▶ if ( $self->options() =~ m/^\s*-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options =~ /^\s*-/) { } 0 0 0
338 0 $opts .= q{ } . $self->options();
339 }
340 else {
341 0 $opts .= q{ -} . $self->options();
342 }
343 }
344 0 ▶ if ( $self->numericids() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->numericids) 0 0 0
345 0 $opts .= ' --numeric-ids';
346 }
347 0 ▶ if ( $self->bwlimit() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->bwlimit) 0 0 0
348 0 $opts .= ' --bwlimit=' . $self->bwlimit();
349 }
350 0 ▶ if ( $self->delete() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->delete) 0 0 0
351 0 $opts .= ' --delete';
352 }
353 0 ▶ if ( $self->dry() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dry) 0 0 0
354 0 $opts .= ' --dry-run';
355 }
356  
357 0 my $dirs = q{};
358 0 $dirs .= q{ } . $self->source();
359 0 $dirs .= q{ } . $self->destination();
360  
361 0 my @cmd = ( $cmd, $opts, $dirs );
362  
363 0 ▶ return wantarray ? @cmd : join( q{}, @cmd );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
364 }
365  
366 0 ▶sub _mainloop {
Subroutine _mainloop: not called CC=10 SCAR=47.0
367 0 my $self = shift;
368 0 my %status = ();
369  
370 0 my $cmd = $self->_rsync_cmd();
371  
372 0 foreach my $runloop ( 1 .. $self->runloops() ) {
373 0 ▶ last if ( !$self->_check_timeframe() );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_timeframe 0 0 0
374 0 $self->parent()->logger()->log(
375 message => 'Job: [' . $self->name() . '] ' . $self->description . ' (Runloop: '.$runloop.q{/} . $self->runloops() . ') starting ...',
376 level => 'debug'
377 );
378  
379 0 $self->parent()->logger()->log( message => 'Starting ' . $self->description . q{ - } . $cmd, level => 'debug', );
380 0 $self->parent()->logger()->log( message => 'CMD: '.$cmd, level => 'debug', );
381 0 $self->loop_status()->{$runloop}->{'time_start'} = time();
382  
383 0 my $opts = {
384 'Logfile' => $self->logfile(),
385 'ReturnRV' => 1,
386 'Timeout' => 60 * 60 * 23, # 23h
387 };
388  
389 0 my $rv;
390 0 ▶ if ( $self->parent()->config()->get( $self->parent()->config_prefix() . '::Dry' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent->config->get($self->parent->config_prefix . '::Dry')) { } 0 0 0
391 0 $rv = 0;
392 }
393 else {
394 0 $rv = $self->sys()->run_cmd( $cmd, $opts );
395 }
396  
397 0 my $reason = q{};
398 0 my $severity = 'debug';
399 0 ▶ if ( $self->parent()->rsync_codes()->{$rv} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent->rsync_codes->{$rv}) 0 0 0
400 0 ▶ if ( $self->parent()->rsync_codes()->{$rv}[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent->rsync_codes->{$rv}[0]) 0 0 0
401 0 $severity = $self->parent()->rsync_codes()->{$rv}[0];
402 }
403 0 ▶ if ( $self->parent()->rsync_codes()->{$rv}[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent->rsync_codes->{$rv}[1]) 0 0 0
404 0 $reason = $self->parent()->rsync_codes()->{$rv}[1];
405 }
406 }
407 0 ▶ $severity ||= 'debug';
Condition0%0/2
$severity ||= "debug"
l!l
00
MC/DC0%0/1
$severity ||= "debug"
$severity
Truth table0%0/2
A
A= $severity
Aresult
11
00
408 0 $self->parent()->logger()->log( message => 'Command finished with RV '.$rv.'. Reason: '.$reason, level => $severity, );
409 0 $self->loop_status()->{$runloop}->{'rv'} = $rv;
410 0 $self->loop_status()->{$runloop}->{'reason'} = $reason;
411 0 $self->loop_status()->{$runloop}->{'severity'} = $severity;
412 0 $self->loop_status()->{$runloop}->{'time_finish'} = time();
413  
414 # end loop if fatal or no error, otherwise loop again
415 0 ▶ if ( $self->parent()->rsync_codes()->{$rv}[0] eq 'fatal' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->parent->rsync_codes->{$rv}[0] eq 'fatal') { } 0 0 0
elsif ($self->parent->rsync_codes->{$rv}[0] ne 'error') { } 0 0 0
416 0 $self->logger()
417 ->log( message => 'Exiting mainloop after runloop ' . $runloop . ' of ' . $self->runloops() . ' due to: a FATAL error', level => 'error', );
418 0 return;
419 }
420 elsif ( $self->parent()->rsync_codes()->{$rv}[0] ne 'error' ) {
421 0 $self->logger()
422 ->log( message => 'Exiting mainloop after runloop ' . $runloop . ' of ' . $self->runloops() . ' due to: SUCCESS', level => 'debug', );
423 0 return 1;
424 }
425 }
426  
427 0 $self->logger()->log(
428 message => 'Exiting mainloop after runloop ' . $self->runloops() . ' of ' . $self->runloops() . ' due to: no more runloops left',
429 level => 'debug',
430 );
431 0 return 1;
432 }
433  
434 0 ▶sub _check_timeframe {
Subroutine _check_timeframe: not called CC=21 SCAR=61.4
435 0 my $self = shift;
436  
437 ## no critic (ProhibitExcessComplexity)
438 0 my ( $from_hour, $from_min, $to_hour, $to_min ) = ( 0, 0, 0, 0 );
439 0 ▶ if ( $self->timeframe()
Branch: 1 branch
BranchTrueFalseTotal
if ($self->timeframe and $self->timeframe =~ /0?(\d?\d):0?(\d?\d)-0?(\d?\d):0?(\d?\d)/) 0 0 0
Condition0%0/3
$self->timeframe and $self->timeframe =~ /0?(\d?\d):0?(\d?\d)-0?(\d?\d):0?(\d?\d)/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->timeframe and $self->timeframe =~ /0?(\d?\d):0?(\d?\d)-0?(\d?\d):0?(\d?\d)/
$self->timeframe $self->timeframe =~ /0?(\d?\d):0?(\d?\d)-0?(\d?\d):0?(\d?\d)/
Truth table0%0/3
A and B
A= $self->timeframeB= $self->timeframe =~ /0?(\d?\d):0?(\d?\d)-0?(\d?\d):0?(\d?\d)/
ABresult
0X0
100
111
440 && $self->timeframe() =~ m/0?(\d?\d):0?(\d?\d)-0?(\d?\d):0?(\d?\d)/ )
441 {
442 0 $from_hour = $1;
443 0 $from_min = $2;
444 0 $to_hour = $3;
445 0 $to_min = $4;
446 0 my $now_min = ( localtime() )[1];
447 0 my $now_hour = ( localtime() )[2];
448 0 my $now_mday = ( localtime() )[3];
449 0 my $now_mon = ( localtime() )[4];
450 0 my $now_year = ( localtime() )[5];
451  
452 # Check if this job may run now
453 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($from_hour < $to_hour || $from_hour == $to_hour && $from_min < $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min || ($now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min) or $from_hour > $to_hour || $from_hour == $to_hour && $from_min > $to_min and $now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min) 0 0 0
Condition0%0/51
$from_hour < $to_hour || $from_hour == $to_hour && $from_min < $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min || ($now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min) or $from_hour > $to_hour || $from_hour == $to_hour && $from_min > $to_min and $now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min
l!l&&r!l&&!r
000
$from_hour < $to_hour || $from_hour == $to_hour && $from_min < $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min || ($now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min)
!ll&&!rl&&r
000
$from_hour < $to_hour or $from_hour == $to_hour and $from_min < $to_min
l!l&&r!l&&!r
000
$from_hour == $to_hour and $from_min < $to_min
!ll&&!rl&&r
000
$now_hour < $from_hour or $now_hour == $from_hour and $now_min < $from_min or ($now_hour > $to_hour or $now_hour == $to_hour and $now_min > $to_min)
l!l&&r!l&&!r
000
$now_hour < $from_hour or $now_hour == $from_hour and $now_min < $from_min
l!l&&r!l&&!r
000
$now_hour == $from_hour and $now_min < $from_min
!ll&&!rl&&r
000
$now_hour > $to_hour or $now_hour == $to_hour and $now_min > $to_min
l!l&&r!l&&!r
000
$now_hour == $to_hour and $now_min > $to_min
!ll&&!rl&&r
000
$from_hour > $to_hour || $from_hour == $to_hour && $from_min > $to_min and $now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min
!ll&&!rl&&r
000
$from_hour > $to_hour || $from_hour == $to_hour && $from_min > $to_min and $now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min
!ll&&!rl&&r
000
$from_hour > $to_hour or $from_hour == $to_hour and $from_min > $to_min
l!l&&r!l&&!r
000
$from_hour == $to_hour and $from_min > $to_min
!ll&&!rl&&r
000
$now_hour > $to_hour or $now_hour == $to_hour and $now_min > $to_min
l!l&&r!l&&!r
000
$now_hour == $to_hour and $now_min > $to_min
!ll&&!rl&&r
000
$now_hour < $from_hour or $now_hour == $from_hour and $now_min < $from_min
l!l&&r!l&&!r
000
$now_hour == $from_hour and $now_min < $from_min
!ll&&!rl&&r
000
MC/DC0%0/18
$from_hour < $to_hour || $from_hour == $to_hour && $from_min < $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min || ($now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min) or $from_hour > $to_hour || $from_hour == $to_hour && $from_min > $to_min and $now_hour > $to_hour || $now_hour == $to_hour && $now_min > $to_min and $now_hour < $from_hour || $now_hour == $from_hour && $now_min < $from_min
too many conditions
454 (
455 (
456  
457 # from < to
458 ( $from_hour < $to_hour || ( $from_hour == $to_hour && $from_min < $to_min ) )
459 && (
460 ## now < from
461 ( $now_hour < $from_hour || ( $now_hour == $from_hour && $now_min < $from_min ) )
462 ## now > to
463 || ( $now_hour > $to_hour || ( $now_hour == $to_hour && $now_min > $to_min ) )
464 )
465 )
466 || (
467  
468 # from > to
469 ( $from_hour > $to_hour || ( $from_hour == $to_hour && $from_min > $to_min ) )
470 &&
471 ## now > to && now < from
472 ( $now_hour > $to_hour || ( $now_hour == $to_hour && $now_min > $to_min ) )
473 && ( $now_hour < $from_hour || ( $now_hour == $from_hour && $now_min < $from_min ) )
474 )
475 )
476 )
477 {
478 0 $self->parent()->logger()->log(
479 message => 'Skipping Job: '
480 . $self->description()
481 . ' because not within timeframe (time: '
482 . $now_hour . q{:}
483 . $now_min
484 . ', from: '
485 . $from_hour . q{:}
486 . $from_min
487 . ', to: '
488 . $to_hour . q{:}
489 . $to_min,
490 level => 'debug'
491 );
492 0 return;
493 }
494 }
495 ## use critic
496 0 return 1;
497 }
498  
499 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
500 1 __PACKAGE__->meta->make_immutable;
501  
502 1 1;
503  
504 __END__
↑ Summary script/bprsync.pl »