Backoff/Fibonacci.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 37 / 37 CC 3 SCAR 6.2
CC
3
Cov
100%
_failure
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Backoff.pm ↑ Summary Backoff/LILD.pm »
1 package Algorithm::Backoff::Fibonacci;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use parent qw(Algorithm::Backoff);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9 2 our $DATE = '2024-02-24'; # DATE
10 2 our $DIST = 'Algorithm-Backoff'; # DIST
11 2 our $VERSION = '0.010'; # VERSION
12  
13 2 our %SPEC;
14  
15 $SPEC{new} = {
16 2 v => 1.1,
17 is_class_meth => 1,
18 is_func => 0,
19 args => {
20 %Algorithm::Backoff::attr_consider_actual_delay,
21 %Algorithm::Backoff::attr_max_actual_duration,
22 %Algorithm::Backoff::attr_max_attempts,
23 %Algorithm::Backoff::attr_jitter_factor,
24 %Algorithm::Backoff::attr_delay_on_success,
25 %Algorithm::Backoff::attr_min_delay,
26 %Algorithm::Backoff::attr_max_delay,
27 initial_delay1 => {
28 summary => 'Initial delay for the first attempt after failure, '.
29 'in seconds',
30 schema => 'ufloat*',
31 req => 1,
32 },
33 initial_delay2 => {
34 summary => 'Initial delay for the second attempt after failure, '.
35 'in seconds',
36 schema => 'ufloat*',
37 req => 1,
38 },
39 },
40 result_naked => 1,
41 result => {
42 schema => 'obj*',
43 },
44 };
45  
46 1 ▶sub _success {
Subroutine _success: called CC=1 SCAR=0.0
47 1 my ($self, $timestamp) = @_;
48 1 $self->{delay_on_success};
49 }
50  
51 6 ▶sub _failure {
Subroutine _failure: called CC=3 SCAR=11.0
52 6 my ($self, $timestamp) = @_;
53 6 ▶ if ($self->{_attempts} == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_attempts'} == 1) { } 1 5 6
elsif ($self->{'_attempts'} == 2) { } 1 4 5
54 1 $self->{_delay_n_min_1} = 0;
55 1 $self->{_delay_n} = $self->{initial_delay1};
56 } elsif ($self->{_attempts} == 2) {
57 1 $self->{_delay_n_min_1} = $self->{initial_delay1};
58 1 $self->{_delay_n} = $self->{initial_delay2};
59 } else {
60 4 my $tmp = $self->{_delay_n};
61 4 $self->{_delay_n} = $self->{_delay_n_min_1} + $self->{_delay_n};
62 4 $self->{_delay_n_min_1} = $tmp;
63 4 $self->{_delay_n};
64 }
65 }
66  
67 2 1;
68 # ABSTRACT: Backoff using Fibonacci sequence
69  
70 __END__
« Backoff.pm ↑ Summary Backoff/LILD.pm »