File Coverage

blib/lib/Action/Retry/Strategy/Fibonacci.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 11 12 91.6


line stmt bran cond sub pod time code
1             #
2             # This file is part of Action-Retry
3             #
4             # This software is copyright (c) 2013 by Damien "dams" Krotkine.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package Action::Retry::Strategy::Fibonacci;
10             {
11             $Action::Retry::Strategy::Fibonacci::VERSION = '0.24';
12             }
13              
14             # ABSTRACT: Fibonacci incrementation of sleep time strategy
15              
16 2     2   3610 use Math::Fibonacci qw(term);
  2         22131  
  2         144  
17              
18 2     2   18 use Moo;
  2         5  
  2         19  
19              
20              
21              
22             with 'Action::Retry::Strategy';
23             with 'Action::Retry::Strategy::HelperRole::RetriesLimit';
24             with 'Action::Retry::Strategy::HelperRole::SleepTimeout';
25              
26              
27             has initial_term_index => (
28             is => 'ro',
29             lazy => 1,
30             default => sub { 0 },
31             );
32              
33             # the current sequence term index
34             has _current_term_index => (
35             is => 'rw',
36             lazy => 1,
37             default => sub { $_[0]->initial_term_index },
38             init_arg => undef,
39             clearer => 1,
40             );
41              
42              
43              
44             has multiplicator => (
45             is => 'ro',
46             lazy => 1,
47             default => sub { 1000 },
48             );
49              
50             sub reset {
51             my ($self) = @_;
52             $self->_clear_current_term_index;
53             return;
54             }
55              
56             sub compute_sleep_time {
57 83     83 0 1868 my ($self) = @_;
58             # print STDERR " -- sleep time is " . term($self->_current_term_index) * $self->multiplicator . "\n";
59 83         2032 return term($self->_current_term_index) * $self->multiplicator;
60             }
61              
62             sub next_step {
63             my ($self) = @_;
64             $self->_current_term_index($self->_current_term_index + 1);
65             return;
66             }
67              
68             sub needs_to_retry { 1 }
69              
70             # Inherited from Action::Retry::Strategy::HelperRole::RetriesLimit
71              
72              
73             # Inherited from Action::Retry::Strategy::HelperRole::SleepTimeout
74              
75              
76             1;
77              
78             __END__