AnyEvent-Retry

 view release on metacpan or  search on metacpan

lib/AnyEvent/Retry/Interval.pm  view on Meta::CPAN

package AnyEvent::Retry::Interval;
BEGIN {
  $AnyEvent::Retry::Interval::VERSION = '0.03';
}
# ABSTRACT: role representing a time sequence generator for C<AnyEvent::Retry>
use Moose::Role;

use true;
use namespace::autoclean;

with 'AnyEvent::Retry::Interval::API';

has 'counter' => (
    is      => 'bare', # has 'Moose' => ( is => 'bug ridden' );
    traits  => ['Counter'],
    reader  => 'counter',
    isa     => 'Num',
    lazy    => 1,
    default => 0,
    clearer => '_reset_counter',
    handles => { _inc_counter => 'inc' },
);

requires 'reset';
requires 'next';

before 'reset' => sub {
    my $self = shift;
    $self->_reset_counter;
};

around 'next' => sub {
    my ($orig, $self) = @_;
    $self->_inc_counter;
    my $counter = $self->counter;
    my $result  = $self->$orig($counter);
    return ($result, $self->counter) if wantarray;
    return $result;
};



=pod

=head1 NAME

AnyEvent::Retry::Interval - role representing a time sequence generator for C<AnyEvent::Retry>

=head1 VERSION

version 0.03

=head1 METHODS

=head1 reset

Reset the sequence generator to its initial state.

C<reset> accepts no arguments.

=head1 next

Return the next element in the sequence.  In scalar context, return
only the next element.  In list context, return a pair of the next
element and the number of times C<next> has been called since
C<reset>.

C<next> accepts no arguments.



( run in 1.189 second using v1.01-cache-2.11-cpan-39bf76dae61 )