| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package AnyEvent::HTTP::LWP::UserAgent::Determined; |
|
3
|
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
291260
|
use strict; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
118
|
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
159
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: a virtual browser that retries errors with AnyEvent |
|
8
|
|
|
|
|
|
|
our $VERSION = 'v0.05.1.06'; # VERSION |
|
9
|
3
|
|
|
3
|
|
3793
|
use AnyEvent::HTTP::LWP::UserAgent 0.08 (); |
|
|
3
|
|
|
|
|
358129
|
|
|
|
3
|
|
|
|
|
83
|
|
|
10
|
3
|
|
|
3
|
|
3328
|
use LWP::UserAgent::Determined (); |
|
|
3
|
|
|
|
|
1705
|
|
|
|
3
|
|
|
|
|
1249
|
|
|
11
|
|
|
|
|
|
|
our (@ISA) = ('AnyEvent::HTTP::LWP::UserAgent', 'LWP::UserAgent::Determined'); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#========================================================================== |
|
15
|
|
|
|
|
|
|
# extracted from LWP::UserAgent::Determined with little modification |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub simple_request_async { |
|
18
|
12
|
|
|
12
|
1
|
101076
|
my($self, @args) = @_; |
|
19
|
12
|
|
|
|
|
68
|
my(@timing_tries) = ( $self->timing() =~ m<(\d+(?:\.\d+)*)>g ); |
|
20
|
12
|
|
|
|
|
262
|
my $determination = $self->codes_to_determinate(); |
|
21
|
|
|
|
|
|
|
|
|
22
|
12
|
|
|
|
|
472
|
my $cv = AE::cv; |
|
23
|
12
|
|
|
|
|
108
|
my $before_c = $self->before_determined_callback; |
|
24
|
12
|
|
|
|
|
158
|
my $after_c = $self->after_determined_callback; |
|
25
|
12
|
|
|
|
|
120
|
push @timing_tries, undef; |
|
26
|
|
|
|
|
|
|
|
|
27
|
12
|
|
|
|
|
20
|
my $loop; |
|
28
|
|
|
|
|
|
|
$loop = sub { |
|
29
|
18
|
|
|
18
|
|
67
|
my $pause_if_unsuccessful = shift @timing_tries; |
|
30
|
|
|
|
|
|
|
|
|
31
|
18
|
50
|
|
|
|
367
|
$before_c and $before_c->( |
|
32
|
|
|
|
|
|
|
$self, \@timing_tries, $pause_if_unsuccessful, $determination, \@args); |
|
33
|
|
|
|
|
|
|
$self->SUPER::simple_request_async(@args)->cb(sub { |
|
34
|
18
|
|
|
|
|
290364
|
my $resp = shift->recv; |
|
35
|
18
|
50
|
|
|
|
436
|
$after_c and $after_c->( |
|
36
|
|
|
|
|
|
|
$self, \@timing_tries, $pause_if_unsuccessful, $determination, \@args, $resp); |
|
37
|
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
9889
|
my $code = $resp->code; |
|
39
|
18
|
100
|
|
|
|
364
|
unless( $determination->{$code} ) { # normal case: all is well (or 404, etc) |
|
40
|
10
|
|
|
|
|
56
|
$cv->send($resp); return; |
|
|
10
|
|
|
|
|
13048
|
|
|
41
|
|
|
|
|
|
|
} |
|
42
|
8
|
100
|
|
|
|
51
|
if(defined $pause_if_unsuccessful) { # it's undef only on the last |
|
43
|
|
|
|
|
|
|
|
|
44
|
6
|
50
|
|
|
|
12019097
|
sleep $pause_if_unsuccessful if $pause_if_unsuccessful; |
|
45
|
6
|
|
|
|
|
81
|
$loop->(); |
|
46
|
|
|
|
|
|
|
} else { |
|
47
|
2
|
|
|
|
|
12
|
$cv->send($resp); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
18
|
|
|
|
|
7466
|
}); |
|
50
|
12
|
|
|
|
|
95
|
}; |
|
51
|
12
|
|
|
|
|
37
|
$loop->(); # First invoke |
|
52
|
|
|
|
|
|
|
|
|
53
|
12
|
|
|
|
|
58457
|
return $cv; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
|
57
|
|
|
|
|
|
|
# extracted from LWP::UserAgent::Determined |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
|
60
|
2
|
|
|
2
|
1
|
18078
|
my $self = shift->SUPER::new(@_); |
|
61
|
2
|
|
|
|
|
15442
|
$self->_determined_init(); |
|
62
|
2
|
|
|
|
|
491
|
return $self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#========================================================================== |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |