File Coverage

blib/lib/AnyEvent/Retry/Interval.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 14 100.0


line stmt bran cond sub pod time code
1             package AnyEvent::Retry::Interval;
2             BEGIN {
3 3     3   2332 $AnyEvent::Retry::Interval::VERSION = '0.03';
4             }
5             # ABSTRACT: role representing a time sequence generator for C<AnyEvent::Retry>
6 3     3   3377 use Moose::Role;
  3         18953  
  3         25  
7              
8 3     3   23301 use true;
  3         10  
  3         31  
9 3     3   5842 use namespace::autoclean;
  3         9  
  3         34  
10              
11             with 'AnyEvent::Retry::Interval::API';
12              
13             has 'counter' => (
14             is => 'bare', # has 'Moose' => ( is => 'bug ridden' );
15             traits => ['Counter'],
16             reader => 'counter',
17             isa => 'Num',
18             lazy => 1,
19             default => 0,
20             clearer => '_reset_counter',
21             handles => { _inc_counter => 'inc' },
22             );
23              
24             requires 'reset';
25             requires 'next';
26              
27             before 'reset' => sub {
28             my $self = shift;
29             $self->_reset_counter;
30             };
31              
32             around 'next' => sub {
33             my ($orig, $self) = @_;
34             $self->_inc_counter;
35             my $counter = $self->counter;
36             my $result = $self->$orig($counter);
37             return ($result, $self->counter) if wantarray;
38             return $result;
39             };
40              
41              
42              
43             =pod
44              
45             =head1 NAME
46              
47             AnyEvent::Retry::Interval - role representing a time sequence generator for C<AnyEvent::Retry>
48              
49             =head1 VERSION
50              
51             version 0.03
52              
53             =head1 METHODS
54              
55             =head1 reset
56              
57             Reset the sequence generator to its initial state.
58              
59             C<reset> accepts no arguments.
60              
61             =head1 next
62              
63             Return the next element in the sequence. In scalar context, return
64             only the next element. In list context, return a pair of the next
65             element and the number of times C<next> has been called since
66             C<reset>.
67              
68             C<next> accepts no arguments.
69              
70             =head1 IMPLEMENTING YOUR OWN INTERVAL CLASS
71              
72             Consume this role.
73              
74             Your C<next> method only needs to return the next value in the
75             sequence; the list context behavior is automatically added when you
76             consume this role. It is automatically passed the counter as the only
77             argument, which is C<1> the first time after a reset.
78              
79             =head1 AUTHOR
80              
81             Jonathan Rockway <jrockway@cpan.org>
82              
83             =head1 COPYRIGHT AND LICENSE
84              
85             This software is copyright (c) 2010 by Jonathan Rockway.
86              
87             This is free software; you can redistribute it and/or modify it under
88             the same terms as the Perl 5 programming language system itself.
89              
90             =cut
91              
92              
93             __END__
94