File Coverage

blib/lib/AnyEvent/Retry/Interval/Fibonacci.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             package AnyEvent::Retry::Interval::Fibonacci;
2             BEGIN {
3 2     2   41731 $AnyEvent::Retry::Interval::Fibonacci::VERSION = '0.03';
4             }
5             # ABSTRACT: fibonacci back-off
6 2     2   970 use Moose;
  2         622354  
  2         22  
7 2     2   15650 use MooseX::Types::Common::Numeric qw(PositiveNum);
  2         170524  
  2         73  
8              
9 2     2   8160 use Math::Fibonacci qw(term);
  2         21268  
  2         140  
10              
11 2     2   843 use true;
  2         9230  
  2         23  
12 2     2   2619 use namespace::autoclean;
  2         5  
  2         23  
13              
14             with 'AnyEvent::Retry::Interval';
15              
16             has 'scale' => (
17             is => 'ro',
18             isa => PositiveNum,
19             default => 1.0,
20             );
21              
22             sub reset {}
23              
24             sub next {
25             my ($self, $i) = @_;
26             return $self->scale * term($i);
27             }
28              
29             __PACKAGE__->meta->make_immutable;
30              
31              
32              
33             =pod
34              
35             =head1 NAME
36              
37             AnyEvent::Retry::Interval::Fibonacci - fibonacci back-off
38              
39             =head1 VERSION
40              
41             version 0.03
42              
43             =head1 SYNOPSIS
44              
45             C<AnyEvent::Retry::Interval> that waits longer and longer after each
46             failed attempt.
47              
48             =head1 INITARGS
49              
50             =head2 scale
51              
52             A number greater than 0 that the fibonacci number is multiplied by
53             before being returned. For example, to wait 1 millisecond, then 1
54             millisecond, then 2 milliseconds, then 3 ..., pass C<scale => 1/1000>.
55              
56             =head1 NOTES
57              
58             The fibonacci number is computed with L<Math::Fibonacci>. This may yield
59             slightly different results from the iterative C<F(n) = F(n-2) + F(n-1)>
60             method.
61              
62             =head1 AUTHOR
63              
64             Jonathan Rockway <jrockway@cpan.org>
65              
66             =head1 COPYRIGHT AND LICENSE
67              
68             This software is copyright (c) 2010 by Jonathan Rockway.
69              
70             This is free software; you can redistribute it and/or modify it under
71             the same terms as the Perl 5 programming language system itself.
72              
73             =cut
74              
75              
76             __END__
77