Retry/Interval/Multi.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 91.8% 56 / 61 CC 8 SCAR 12.7
CC
8
Cov
92%
check_condition
6.4
next
3.0
BEGIN
1.0
CRAP 3.6
« Retry.pm ↑ Summary Retry/Coro.pm »
1 package AnyEvent::Retry::Interval::Multi;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $AnyEvent::Retry::Interval::Multi::VERSION = '0.03';
4 }
5 # ABSTRACT: combine multiple interval objects into one interval
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use AnyEvent::Retry::Types qw(Interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use true;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'AnyEvent::Retry::Interval';
13  
14 1 has [qw/first then/] => (
15 is => 'ro',
16 isa => Interval,
17 required => 1,
18 coerce => 1,
19 );
20  
21 1 has '_source' => (
22 accessor => '_source',
23 isa => 'Str',
24 lazy => 1,
25 default => 'first',
26 clearer => '_reset_source',
27 );
28  
29 1 has 'after' => (
30 is => 'ro',
31 isa => 'Num|CodeRef',
32 required => 1,
33 );
34  
35 12 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
36 12 my $self = shift;
37 12 $self->_reset_source;
38 12 $self->first->reset;
39 12 $self->then->reset;
40 }
41  
42 224 ▶sub next {
Subroutine next: called CC=3 SCAR=11.0
43 224 my ($self, $i) = @_;
44 224 my $source = $self->_source;
45 224 ▶ return $self->then->next if $self->_source eq 'then';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_source eq "then" 156 68 224
46  
47 68 my $next = $self->first->next;
48 68 my $switch = $self->check_condition($i, $next);
49 68 ▶ return $next if !$switch;
Branch: 1 branch
BranchTrueFalseTotal
unless $switch 56 12 68
50  
51 12 $self->_source('then');
52 12 return $self->then->next;
53 }
54  
55 68 ▶sub check_condition {
Subroutine check_condition: called CC=6 SCAR=18.6
Pod undocumented
56 68 my ($self, $i, $next) = @_;
57 68 my $cond = $self->after;
58 68 my $switch = 0;
59 68 ▶ if(ref $cond){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cond) { } 0 68 68
elsif ($cond < 0) { } 40 28 68
60 0 ▶ $switch = $cond->($i, $next) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$cond($i, $next) ? : 0 0 0
61 }
62 elsif($cond < 0){
63 40 ▶ $switch = 1 if $i > abs($cond);
Branch: 1 branch
BranchTrueFalseTotal
if $i > abs $cond 8 32 40
64 }
65 else {
66 28 ▶ $switch = 1 if $next > $cond;
Branch: 1 branch
BranchTrueFalseTotal
if $next > $cond 4 24 28
67 }
68  
69 68 return $switch;
70 }
71  
72 1 __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__
« Retry.pm ↑ Summary Retry/Coro.pm »