| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package AnyEvent::Retry::Interval::Multi; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
34609
|
$AnyEvent::Retry::Interval::Multi::VERSION = '0.03'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: combine multiple interval objects into one interval |
|
6
|
1
|
|
|
1
|
|
1003
|
use Moose; |
|
|
1
|
|
|
|
|
567201
|
|
|
|
1
|
|
|
|
|
10
|
|
|
7
|
1
|
|
|
1
|
|
12101
|
use AnyEvent::Retry::Types qw(Interval); |
|
|
1
|
|
|
|
|
12491
|
|
|
|
1
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1280
|
use true; |
|
|
1
|
|
|
|
|
15
|
|
|
|
1
|
|
|
|
|
9
|
|
|
10
|
1
|
|
|
1
|
|
1217
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'AnyEvent::Retry::Interval'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has [qw/first then/] => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
isa => Interval, |
|
17
|
|
|
|
|
|
|
required => 1, |
|
18
|
|
|
|
|
|
|
coerce => 1, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has '_source' => ( |
|
22
|
|
|
|
|
|
|
accessor => '_source', |
|
23
|
|
|
|
|
|
|
isa => 'Str', |
|
24
|
|
|
|
|
|
|
lazy => 1, |
|
25
|
|
|
|
|
|
|
default => 'first', |
|
26
|
|
|
|
|
|
|
clearer => '_reset_source', |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'after' => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'Num|CodeRef', |
|
32
|
|
|
|
|
|
|
required => 1, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub reset { |
|
36
|
|
|
|
|
|
|
my $self = shift; |
|
37
|
|
|
|
|
|
|
$self->_reset_source; |
|
38
|
|
|
|
|
|
|
$self->first->reset; |
|
39
|
|
|
|
|
|
|
$self->then->reset; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub next { |
|
43
|
|
|
|
|
|
|
my ($self, $i) = @_; |
|
44
|
|
|
|
|
|
|
my $source = $self->_source; |
|
45
|
|
|
|
|
|
|
return $self->then->next if $self->_source eq 'then'; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $next = $self->first->next; |
|
48
|
|
|
|
|
|
|
my $switch = $self->check_condition($i, $next); |
|
49
|
|
|
|
|
|
|
return $next if !$switch; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->_source('then'); |
|
52
|
|
|
|
|
|
|
return $self->then->next; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub check_condition { |
|
56
|
68
|
|
|
68
|
0
|
96
|
my ($self, $i, $next) = @_; |
|
57
|
68
|
|
|
|
|
2442
|
my $cond = $self->after; |
|
58
|
68
|
|
|
|
|
78
|
my $switch = 0; |
|
59
|
68
|
50
|
|
|
|
143
|
if(ref $cond){ |
|
|
|
100
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
0
|
$switch = $cond->($i, $next) ? 1 : 0; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
elsif($cond < 0){ |
|
63
|
40
|
100
|
|
|
|
87
|
$switch = 1 if $i > abs($cond); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
else { |
|
66
|
28
|
100
|
|
|
|
62
|
$switch = 1 if $next > $cond; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
68
|
|
|
|
|
112
|
return $switch; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=pod |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
AnyEvent::Retry::Interval::Multi - combine multiple interval objects into one interval |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.03 |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $m = AnyEvent::Retry::Interval::Multi->new( |
|
89
|
|
|
|
|
|
|
first => { Constant => { interval => .5 } }, |
|
90
|
|
|
|
|
|
|
after => -2, |
|
91
|
|
|
|
|
|
|
then => { Multi => { |
|
92
|
|
|
|
|
|
|
first => 'Fibonacci', |
|
93
|
|
|
|
|
|
|
after => 10, |
|
94
|
|
|
|
|
|
|
then => { Multi => { |
|
95
|
|
|
|
|
|
|
first => { Constant => { interval => 10 } }, |
|
96
|
|
|
|
|
|
|
after => -6, |
|
97
|
|
|
|
|
|
|
then => { Constant => { interval => 60 } }, |
|
98
|
|
|
|
|
|
|
}}, |
|
99
|
|
|
|
|
|
|
}}, |
|
100
|
|
|
|
|
|
|
); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
C<$m> waits for .5 seconds twice, then it waits for 1 second, 1 |
|
103
|
|
|
|
|
|
|
second, 2 seconds, 3 seconds, 5 seconds, 8 seconds, then 10 seconds 6 |
|
104
|
|
|
|
|
|
|
times, then 60 seconds forever. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
See the code and tests for more detail. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Jonathan Rockway <jrockway@cpan.org> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This software is copyright (c) 2010 by Jonathan Rockway. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
119
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
|
125
|
|
|
|
|
|
|
|