| 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::Linear; | ||
| 10 | { | ||
| 11 | 22 | $Action::Retry::Strategy::Linear::VERSION = '0.24'; | |
| 12 | } | ||
| 13 | |||
| 14 | # ABSTRACT: Linear incrementation of sleep time strategy | ||
| 15 | |||
| 16 | 3 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | |||
| 19 | 22 | with 'Action::Retry::Strategy'; | |
| 20 | 25 | with 'Action::Retry::Strategy::HelperRole::RetriesLimit'; | |
| 21 | 3 | with 'Action::Retry::Strategy::HelperRole::SleepTimeout'; | |
| 22 | |||
| 23 | |||
| 24 | has initial_sleep_time => ( | ||
| 25 | is => 'ro', | ||
| 26 | lazy => 1, | ||
| 27 | 0 | ▶ | default => sub { 1000 }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 28 | 3 | ); | |
| 29 | |||
| 30 | # the current sleep time, as it's computed | ||
| 31 | has _current_sleep_time => ( | ||
| 32 | is => 'rw', | ||
| 33 | lazy => 1, | ||
| 34 | 3 | ▶ | default => sub { $_[0]->initial_sleep_time }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 35 | 3 | init_arg => undef, | |
| 36 | clearer => 1, | ||
| 37 | ); | ||
| 38 | |||
| 39 | |||
| 40 | has multiplicator => ( | ||
| 41 | is => 'ro', | ||
| 42 | lazy => 1, | ||
| 43 | 2 | ▶ | default => sub { 2 }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 44 | 3 | ); | |
| 45 | |||
| 46 | 23 | ▶ | sub reset { |
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 47 | 4 | my ($self) = @_; | |
| 48 | 4 | $self->_clear_current_sleep_time; | |
| 49 | 4 | return; | |
| 50 | } | ||
| 51 | |||
| 52 | 22 | ▶ | sub compute_sleep_time { |
|
Subroutine
compute_sleep_time: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 53 | 22 | my ($self) = @_; | |
| 54 | 22 | return $self->_current_sleep_time; | |
| 55 | } | ||
| 56 | |||
| 57 | 24 | ▶ | sub next_step { |
|
Subroutine
next_step: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 58 | 2 | my ($self) = @_; | |
| 59 | $self->_current_sleep_time($self->_current_sleep_time * $self->multiplicator); | ||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub needs_to_retry { 1 } | ||
| 64 | |||
| 65 | # Inherited from Action::Retry::Strategy::HelperRole::RetriesLimit | ||
| 66 | |||
| 67 | |||
| 68 | # Inherited from Action::Retry::Strategy::HelperRole::SleepTimeout | ||
| 69 | |||
| 70 | |||
| 71 | 3 | 1; | |
| 72 | |||
| 73 | __END__ | ||