MirrorMerger/RetryPolicy.pm

filter: Statementstmt 30.2% 13 / 43 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 2 totaltotal 25.7% 17 / 66 CC 8 SCAR 37.3
CC
8
Cov
23%
__ANON__
72.0
apply
2.0
apply_and_doit
2.0
CRAP 41.7
↑ Summary MirrorMerger/Agent.pm »
1 package CPAN::MirrorMerger::RetryPolicy;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Class::Accessor::Lite ro => [qw/max_retries interval jitter_factor/], new => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub apply {
Subroutine apply: not called CC=1 SCAR=6.9
Pod undocumented
10 0 my ($self, $code) = @_;
11 0 ▶ return sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
12 0 my $wantarray = wantarray;
13  
14 0 my $e;
15 0 my $retry_count = 0;
16 0 my $interval = $self->interval * 1_000_000; # usec
17  
18 0 my @ret;
19 0 ▶ while ($retry_count < $self->max_retries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retry_count < $self->max_retries) 0 0 0
20 0 eval {
21 0 ▶ if ($wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wantarray) { } 0 0 0
elsif (defined $wantarray) { } 0 0 0
22 0 @ret = $code->($retry_count, $e);
23 } elsif (defined $wantarray,) {
24 0 $ret[0] = $code->($retry_count, $e);
25 } else {
26 0 $code->($retry_count, $e);
27 }
28 };
29 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
30 # retry
31 0 $e = $@;
32 0 $retry_count++;
33  
34 0 $interval *= 2;
35 0 ▶ if ($self->jitter_factor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->jitter_factor) 0 0 0
36 0 my $delta = $interval * $self->jitter_factor;
37 0 my $min = $interval - $delta;
38 0 $interval = $min + rand(1+2*$delta);
39 }
40  
41 0 Time::HiRes::usleep($interval);
42 0 next;
43 }
44  
45 0 $e = undef;
46 0 last;
47 }
48 0 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
49  
50 0 ▶ return $wantarray ? @ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
$wantarray ? : 0 0 0
51 0 };
52 }
53  
54 0 ▶sub apply_and_doit {
Subroutine apply_and_doit: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my $self = shift;
56 0 my $code = shift;
57 0 return $self->apply($code)->();
58 }
59  
60 2 1;
61 __END__
↑ Summary MirrorMerger/Agent.pm »