TypeSafe/RetryPolicy.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran 54.5% 12 / 22 Conditioncond 42.8% 6 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 63.9% 62 / 97 CC 18 SCAR 24.1
CC
18
Cov
71%
new
17.6
delay
10.7
BEGIN
1.0
CRAP 11.1
« TypeSafe/Client.pm ↑ Summary TypeSafe/Question.pm »
1 package WebService::TypeSafe::RetryPolicy;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶sub new {
Subroutine new: called CC=10 SCAR=28.7
Pod undocumented
8 6 my ($class, @args) = @_;
9 0 ▶ my %args = @args == 1 && ref($args[0]) eq 'HASH' ? %{ $args[0] } : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 && ref $args[0] eq 'HASH' ? : 0 6 6
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
600
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
10 my $self = {
11 max_retries => 2,
12 backoff_initial => 0.5,
13 backoff_max => 8,
14 backoff_jitter => 0.25,
15 6 http_statuses => { map { $_ => 1 } qw(408 409 429 500 502 503 504 529) },
16 respect_retry_after => 1,
17 connection_errors => 1,
18 timeout => undef,
19 %args,
20 };
21 croak 'max_retries must be a nonnegative integer'
22 6 ▶ unless $self->{max_retries} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"max_retries"} =~ /^\d+$/ 0 6 6
23 6 for my $name (qw(backoff_initial backoff_max backoff_jitter)) {
24 croak "$name must be a nonnegative number"
25 18 ▶ unless defined($self->{$name}) && $self->{$name} =~ /^\d+(?:\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$name} and $self->{$name} =~ /^\d+(?:\.\d+)?$/ 0 18 18
Condition33%1/3
defined $self->{$name} and $self->{$name} =~ /^\d+(?:\.\d+)?$/
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $self->{$name} and $self->{$name} =~ /^\d+(?:\.\d+)?$/
defined $self->{$name} $self->{$name} =~ /^\d+(?:\.\d+)?$/
Truth table33%1/3
A and B
A= defined $self->{$name}B= $self->{$name} =~ /^\d+(?:\.\d+)?$/
ABresult
0X0
100
111
26 }
27 6 ▶ croak 'backoff_jitter must be between 0 and 1' if $self->{backoff_jitter} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"backoff_jitter"} > 1 0 6 6
28 6 ▶ if (ref($self->{http_statuses}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"http_statuses"} eq "ARRAY") 0 6 6
29 0 $self->{http_statuses} = { map { $_ => 1 } @{ $self->{http_statuses} } };
30 }
31 croak 'http_statuses must be an array or hash reference'
32 6 ▶ unless ref($self->{http_statuses}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"http_statuses"} eq "HASH" 0 6 6
33 6 return bless $self, $class;
34 }
35  
36 3 ▶sub should_retry_status { return !!$_[0]->{http_statuses}{ $_[1] } }
Subroutine should_retry_status: called CC=1 SCAR=0.0
Pod undocumented
37 4 ▶sub max_retries { $_[0]->{max_retries} }
Subroutine max_retries: called CC=1 SCAR=0.0
Pod undocumented
38 3 ▶sub timeout { $_[0]->{timeout} }
Subroutine timeout: called CC=1 SCAR=0.0
Pod undocumented
39  
40 2 ▶sub delay {
Subroutine delay: called CC=9 SCAR=23.7
Pod undocumented
41 2 my ($self, $retry_number, $headers) = @_;
42 2 ▶ $headers ||= {};
Condition50%1/2
$headers ||= {}
l!l
20
MC/DC0%0/1
$headers ||= {}
$headers
Truth table50%1/2
A
A= $headers
Aresult
11
00
43 2 ▶ if ($self->{respect_retry_after}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"respect_retry_after"}) 2 0 2
44 2 my $ms = $headers->{'retry-after-ms'};
45 2 ▶ return $ms / 1000 if defined($ms) && $ms =~ /^\d+(?:\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ms and $ms =~ /^\d+(?:\.\d+)?$/ 1 1 2
Condition66%2/3
defined $ms and $ms =~ /^\d+(?:\.\d+)?$/
!ll&&!rl&&r
101
MC/DC50%1/2
defined $ms and $ms =~ /^\d+(?:\.\d+)?$/
defined $ms $ms =~ /^\d+(?:\.\d+)?$/
Truth table66%2/3
A and B
A= defined $msB= $ms =~ /^\d+(?:\.\d+)?$/
ABresult
0X0
100
111
46 1 my $seconds = $headers->{'retry-after'};
47 1 ▶ return $seconds if defined($seconds) && $seconds =~ /^\d+(?:\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seconds and $seconds =~ /^\d+(?:\.\d+)?$/ 0 1 1
Condition33%1/3
defined $seconds and $seconds =~ /^\d+(?:\.\d+)?$/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $seconds and $seconds =~ /^\d+(?:\.\d+)?$/
defined $seconds $seconds =~ /^\d+(?:\.\d+)?$/
Truth table33%1/3
A and B
A= defined $secondsB= $seconds =~ /^\d+(?:\.\d+)?$/
ABresult
0X0
100
111
48 }
49 1 my $delay = $self->{backoff_initial} * (2 ** ($retry_number - 1));
50 1 ▶ $delay = $self->{backoff_max} if $delay > $self->{backoff_max};
Branch: 1 branch
BranchTrueFalseTotal
if $delay > $self->{"backoff_max"} 0 1 1
51 1 ▶ $delay *= 1 - rand($self->{backoff_jitter}) if $self->{backoff_jitter};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"backoff_jitter"} 1 0 1
52 1 return $delay;
53 }
54  
55 3 1;
« TypeSafe/Client.pm ↑ Summary TypeSafe/Question.pm »