line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package LWP::UserAgent::Determined; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
$VERSION = '1.07'; |
5
|
2
|
|
|
2
|
|
546302
|
use LWP::UserAgent (); |
|
2
|
|
|
|
|
154090
|
|
|
2
|
|
|
|
|
79
|
|
6
|
|
|
|
|
|
|
@ISA = ('LWP::UserAgent'); |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
26
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1134
|
|
9
|
|
|
|
|
|
|
die "Where's _elem?!!?" unless __PACKAGE__->can('_elem'); |
10
|
|
|
|
|
|
|
|
11
|
24
|
|
|
24
|
1
|
2898
|
sub timing { shift->_elem('timing' , @_) } |
12
|
10
|
|
|
10
|
1
|
1664
|
sub codes_to_determinate { shift->_elem('codes_to_determinate' , @_) } |
13
|
4
|
|
|
4
|
1
|
288
|
sub before_determined_callback { shift->_elem('before_determined_callback' , @_) } |
14
|
4
|
|
|
4
|
1
|
28
|
sub after_determined_callback { shift->_elem( 'after_determined_callback' , @_) } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#========================================================================== |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub simple_request { |
19
|
3
|
|
|
3
|
1
|
15650
|
my ( $self, @args ) = @_; |
20
|
3
|
|
|
|
|
13
|
my (@timing_tries) = ( $self->timing() =~ m<(\d+(?:\.\d+)*)>g ); |
21
|
3
|
|
|
|
|
53
|
my $determination = $self->codes_to_determinate(); |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
22
|
my $resp; |
24
|
3
|
|
|
|
|
15
|
my $before_c = $self->before_determined_callback; |
25
|
3
|
|
|
|
|
28
|
my $after_c = $self->after_determined_callback; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
20
|
my $request = $args[0]; |
28
|
3
|
|
|
|
|
9
|
foreach my $pause_if_unsuccessful ( @timing_tries, undef ) { |
29
|
9
|
|
|
|
|
124
|
$args[0] = $request->clone; |
30
|
9
|
50
|
|
|
|
2526
|
$before_c and $before_c->( |
31
|
|
|
|
|
|
|
$self, \@timing_tries, $pause_if_unsuccessful, $determination, |
32
|
|
|
|
|
|
|
\@args |
33
|
|
|
|
|
|
|
); |
34
|
9
|
|
|
|
|
3699
|
$resp = $self->SUPER::simple_request(@args); |
35
|
9
|
50
|
|
|
|
21020
|
$after_c and $after_c->( |
36
|
|
|
|
|
|
|
$self, \@timing_tries, $pause_if_unsuccessful, $determination, |
37
|
|
|
|
|
|
|
\@args, $resp |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
9
|
|
|
|
|
2756
|
my $code = $resp->code; |
41
|
9
|
100
|
|
|
|
131
|
unless ( $determination->{$code} ) { |
42
|
|
|
|
|
|
|
# normal case: all is well (or 404, etc) |
43
|
1
|
|
|
|
|
6
|
return $resp; |
44
|
|
|
|
|
|
|
} |
45
|
8
|
100
|
|
|
|
29
|
if ( defined $pause_if_unsuccessful ) { |
46
|
|
|
|
|
|
|
# it's undef only on the last |
47
|
6
|
50
|
|
|
|
38005545
|
sleep $pause_if_unsuccessful if $pause_if_unsuccessful; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
13
|
return $resp; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new { |
57
|
1
|
|
|
1
|
1
|
42
|
my $self = shift->SUPER::new(@_); |
58
|
1
|
|
|
|
|
3542
|
$self->_determined_init(); |
59
|
1
|
|
|
|
|
8
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _determined_init { |
65
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
66
|
1
|
|
|
|
|
5
|
$self->timing('1,3,15'); |
67
|
1
|
|
|
|
|
11
|
$self->codes_to_determinate( { map { $_ => 1 } |
|
5
|
|
|
|
|
17
|
|
68
|
|
|
|
|
|
|
'408', # Request Timeout |
69
|
|
|
|
|
|
|
'500', # Internal Server Error |
70
|
|
|
|
|
|
|
'502', # Bad Gateway |
71
|
|
|
|
|
|
|
'503', # Service Unavailable |
72
|
|
|
|
|
|
|
'504', # Gateway Timeout |
73
|
|
|
|
|
|
|
} ); |
74
|
1
|
|
|
|
|
10
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#========================================================================== |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
__END__ |