File Coverage

blib/lib/Algorithm/Retry/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::Retry::Fibonacci;
2              
3             our $DATE = '2019-04-10'; # DATE
4             our $VERSION = '0.002'; # VERSION
5              
6 1     1   54270 use strict;
  1         9  
  1         25  
7 1     1   5 use warnings;
  1         1  
  1         35  
8              
9 1     1   355 use parent qw(Algorithm::Retry);
  1         259  
  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::Retry::attr_consider_actual_delay,
19             %Algorithm::Retry::attr_max_attempts,
20             %Algorithm::Retry::attr_jitter_factor,
21             %Algorithm::Retry::attr_delay_on_success,
22             %Algorithm::Retry::attr_max_delay,
23             initial_delay1 => {
24             summary => 'Initial delay for the first attempt after failure, '.
25             'in seconds',
26             schema => 'ufloat*',
27             req => 1,
28             },
29             initial_delay2 => {
30             summary => 'Initial delay for the second attempt after failure, '.
31             'in seconds',
32             schema => 'ufloat*',
33             req => 1,
34             },
35             },
36             result_naked => 1,
37             result => {
38             schema => 'obj*',
39             },
40             };
41              
42             sub _success {
43 1     1   2 my ($self, $timestamp) = @_;
44 1         2 $self->{delay_on_success};
45             }
46              
47             sub _failure {
48 6     6   13 my ($self, $timestamp) = @_;
49 6 100       14 if ($self->{_attempts} == 1) {
    100          
50 1         2 $self->{_delay_n_min_1} = 0;
51 1         3 $self->{_delay_n} = $self->{initial_delay1};
52             } elsif ($self->{_attempts} == 2) {
53 1         3 $self->{_delay_n_min_1} = $self->{initial_delay1};
54 1         2 $self->{_delay_n} = $self->{initial_delay2};
55             } else {
56 4         6 my $tmp = $self->{_delay_n};
57 4         6 $self->{_delay_n} = $self->{_delay_n_min_1} + $self->{_delay_n};
58 4         6 $self->{_delay_n_min_1} = $tmp;
59 4         8 $self->{_delay_n};
60             }
61             }
62              
63             1;
64             # ABSTRACT: Backoff using Fibonacci sequence
65              
66             __END__