File Coverage

blib/lib/Algorithm/Backoff/Fibonacci.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Algorithm::Backoff::Fibonacci;
2              
3             our $DATE = '2019-06-18'; # DATE
4             our $VERSION = '0.007'; # VERSION
5              
6 1     1   58346 use strict;
  1         11  
  1         26  
7 1     1   4 use warnings;
  1         2  
  1         27  
8              
9 1     1   367 use parent qw(Algorithm::Backoff);
  1         260  
  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_delay_on_success,
23             %Algorithm::Backoff::attr_min_delay,
24             %Algorithm::Backoff::attr_max_delay,
25             initial_delay1 => {
26             summary => 'Initial delay for the first attempt after failure, '.
27             'in seconds',
28             schema => 'ufloat*',
29             req => 1,
30             },
31             initial_delay2 => {
32             summary => 'Initial delay for the second attempt after failure, '.
33             'in seconds',
34             schema => 'ufloat*',
35             req => 1,
36             },
37             },
38             result_naked => 1,
39             result => {
40             schema => 'obj*',
41             },
42             };
43              
44             sub _success {
45 1     1   3 my ($self, $timestamp) = @_;
46 1         3 $self->{delay_on_success};
47             }
48              
49             sub _failure {
50 6     6   10 my ($self, $timestamp) = @_;
51 6 100       17 if ($self->{_attempts} == 1) {
    100          
52 1         3 $self->{_delay_n_min_1} = 0;
53 1         3 $self->{_delay_n} = $self->{initial_delay1};
54             } elsif ($self->{_attempts} == 2) {
55 1         2 $self->{_delay_n_min_1} = $self->{initial_delay1};
56 1         3 $self->{_delay_n} = $self->{initial_delay2};
57             } else {
58 4         7 my $tmp = $self->{_delay_n};
59 4         7 $self->{_delay_n} = $self->{_delay_n_min_1} + $self->{_delay_n};
60 4         4 $self->{_delay_n_min_1} = $tmp;
61 4         9 $self->{_delay_n};
62             }
63             }
64              
65             1;
66             # ABSTRACT: Backoff using Fibonacci sequence
67              
68             __END__