| 1 | package AnyEvent::Retry::Interval; | ||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | $AnyEvent::Retry::Interval::VERSION = '0.03'; | |||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: role representing a time sequence generator for C<AnyEvent::Retry> | ||||||||||
| 6 | 3 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use true; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | with 'AnyEvent::Retry::Interval::API'; | |||||||||
| 12 | |||||||||||
| 13 | 3 | 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 | 3 | requires 'reset'; | |||||||||
| 25 | 3 | requires 'next'; | |||||||||
| 26 | |||||||||||
| 27 | 31 | ▶ | before 'reset' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 31 | my $self = shift; | |||||||||
| 29 | 31 | $self->_reset_counter; | |||||||||
| 30 | 3 | }; | |||||||||
| 31 | |||||||||||
| 32 | 354 | ▶ | around 'next' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 33 | 354 | my ($orig, $self) = @_; | |||||||||
| 34 | 354 | $self->_inc_counter; | |||||||||
| 35 | 354 | my $counter = $self->counter; | |||||||||
| 36 | 354 | my $result = $self->$orig($counter); | |||||||||
| 37 | 354 | ▶ | return ($result, $self->counter) if wantarray; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 295 | return $result; | |||||||||
| 39 | 3 | }; | |||||||||
| 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__ | ||||||||||