line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LWP::Throttle; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
224724
|
use LWP; |
|
2
|
|
|
|
|
93860
|
|
|
2
|
|
|
|
|
87
|
|
4
|
2
|
|
|
2
|
|
1113
|
use Sub::Throttle 'throttle'; |
|
2
|
|
|
|
|
1680
|
|
|
2
|
|
|
|
|
403
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @ISA = ('LWP::UserAgent'); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
LWP::Throttle - Throttle requests to a site |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.01 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Some sites with REST APIs, such as openstreetmap.org, will blacklist you if you do too many requests. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use LWP::Throttle; |
25
|
|
|
|
|
|
|
my $ua = LWP::Throttle->new(); |
26
|
|
|
|
|
|
|
$ua->load(1); |
27
|
|
|
|
|
|
|
print $ua->get('http://www.example.com'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Creates a LWP::Throttle object. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
40
|
1
|
|
|
1
|
1
|
172
|
my $class = shift; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
14
|
my $rc = $class->SUPER::new(@_); |
43
|
1
|
|
|
|
|
2307
|
$rc->{'load'} = 1; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
return $rc; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 send_request |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
See L. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub send_request { |
55
|
1
|
|
|
1
|
1
|
8486
|
my $self = shift; |
56
|
1
|
|
|
|
|
8
|
return throttle($self->{'load'}, \&LWP::UserAgent::send_request, ($self, @_)); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 load |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Get/set the number of seconds between each request. The default is one second. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub load { |
66
|
2
|
|
|
2
|
1
|
858
|
my $self = shift; |
67
|
2
|
|
|
|
|
3
|
my $load = shift; |
68
|
|
|
|
|
|
|
|
69
|
2
|
100
|
|
|
|
19
|
if($load) { |
70
|
1
|
|
|
|
|
3
|
$self->{'load'} = $load; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
9
|
return $self->{'load'}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 BUGS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SEE ALSO |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L, |
85
|
|
|
|
|
|
|
L |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SUPPORT |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
perldoc LWP::Throttle |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
You can also look for information at: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * CPAN Ratings |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * Search CPAN |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright 2017 Nigel Horne. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This program is released under the following licence: GPL2 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; # End of LWP-Throttle |