File Coverage

blib/lib/Algorithm/Backoff/MILD.pm
Criterion Covered Total %
statement 18 19 94.7
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Algorithm::Backoff::MILD;
2              
3             our $DATE = '2019-06-20'; # DATE
4             our $VERSION = '0.008'; # VERSION
5              
6 1     1   54046 use strict;
  1         9  
  1         23  
7 1     1   5 use warnings;
  1         1  
  1         23  
8              
9 1     1   358 use parent qw(Algorithm::Backoff);
  1         255  
  1         4  
10              
11             our %SPEC;
12              
13             $SPEC{new} = {
14             v => 1.1,
15             is_class_meth => 1,
16             is_func => 0,
17             args => {
18             %Algorithm::Backoff::attr_consider_actual_delay,
19             %Algorithm::Backoff::attr_max_actual_duration,
20             %Algorithm::Backoff::attr_max_attempts,
21             %Algorithm::Backoff::attr_jitter_factor,
22             %Algorithm::Backoff::attr_max_delay,
23             %Algorithm::Backoff::attr_min_delay,
24             %Algorithm::Backoff::attr_initial_delay,
25             %Algorithm::Backoff::attr_delay_multiple_on_failure,
26             %Algorithm::Backoff::attr_delay_increment_on_success,
27             },
28             result_naked => 1,
29             result => {
30             schema => 'obj*',
31             },
32             };
33              
34             sub _success {
35 8     8   10 my ($self, $timestamp) = @_;
36              
37 8 50       17 unless (defined $self->{_prev_delay}) {
38 0         0 return $self->{_prev_delay} = $self->{initial_delay};
39             }
40              
41 8         13 my $delay = $self->{_prev_delay} + $self->{delay_increment_on_success};
42              
43 8         13 $delay;
44             }
45              
46             sub _failure {
47 5     5   10 my ($self, $timestamp) = @_;
48              
49 5 100       8 unless (defined $self->{_prev_delay}) {
50 1         3 return $self->{_prev_delay} = $self->{initial_delay};
51             }
52              
53 4         8 my $delay = $self->{_prev_delay} * $self->{delay_multiple_on_failure};
54              
55 4         6 $delay;
56             }
57              
58             1;
59             # ABSTRACT: Multiplicative Increment, Linear Decrement (MILD) backoff
60              
61             __END__