File Coverage

blib/lib/Algorithm/Backoff/LIMD.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::LIMD;
2              
3             our $DATE = '2019-06-18'; # DATE
4             our $VERSION = '0.007'; # VERSION
5              
6 1     1   52304 use strict;
  1         9  
  1         24  
7 1     1   4 use warnings;
  1         1  
  1         24  
8              
9 1     1   366 use parent qw(Algorithm::Backoff);
  1         243  
  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_increment_on_failure,
26             %Algorithm::Backoff::attr_delay_multiple_on_success,
27             },
28             result_naked => 1,
29             result => {
30             schema => 'obj*',
31             },
32             };
33              
34             sub _success {
35 3     3   18 my ($self, $timestamp) = @_;
36              
37 3 50       8 unless (defined $self->{_prev_delay}) {
38 0         0 return $self->{_prev_delay} = $self->{initial_delay};
39             }
40              
41 3         6 my $delay = $self->{_prev_delay} * $self->{delay_multiple_on_success};
42              
43 3         6 $delay;
44             }
45              
46             sub _failure {
47 5     5   7 my ($self, $timestamp) = @_;
48              
49 5 100       10 unless (defined $self->{_prev_delay}) {
50 1         4 return $self->{_prev_delay} = $self->{initial_delay};
51             }
52              
53 4         6 my $delay = $self->{_prev_delay} + $self->{delay_increment_on_failure};
54              
55 4         7 $delay;
56             }
57              
58             1;
59             # ABSTRACT: Linear Increment, Multiplicative Decrement (LIMD) backoff
60              
61             __END__