line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Agent::Plugins::GoldCoasting; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
709
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use Data::Dumper; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
63
|
|
5
|
1
|
|
|
1
|
|
5
|
use POE; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
1
|
|
|
1
|
0
|
13282
|
my $class = shift; |
9
|
1
|
|
|
|
|
6
|
my %options = @_; |
10
|
|
|
|
|
|
|
return bless { |
11
|
|
|
|
|
|
|
hooks => { |
12
|
|
|
|
|
|
|
'init' => sub { |
13
|
1
|
|
|
1
|
|
3
|
my ($kernel, $heap) = (shift, shift); |
14
|
1
|
|
50
|
|
|
5
|
$heap->{laziness}->{wait} = $options{wait} || 10; |
15
|
1
|
|
50
|
|
|
5
|
$heap->{laziness}->{limit} = $options{limit} || 3; |
16
|
1
|
|
|
|
|
265
|
return 1; |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
'cycle_pos_response' => sub { |
19
|
3
|
|
|
3
|
|
6
|
my ($kernel, $heap) = (shift, shift); |
20
|
3
|
|
|
|
|
5
|
my ($tab, $response) = (shift, shift); |
21
|
3
|
|
|
|
|
13
|
my $url = $response->request->uri; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
281
|
warn "# before $url: working very hard for some secs"; |
24
|
3
|
|
|
|
|
3000536
|
sleep $heap->{laziness}->{wait}; # you should not use blocking... |
25
|
3
|
|
|
|
|
38
|
$heap->{laziness}->{counter}++; # we do not care which tab it is |
26
|
3
|
100
|
|
|
|
26
|
if ($heap->{laziness}->{counter} < $heap->{laziness}->{limit}) { |
27
|
2
|
|
|
|
|
24
|
$kernel->yield ('cycle_start', $tab, $response->request); |
28
|
|
|
|
|
|
|
} else { |
29
|
1
|
|
|
|
|
22
|
$kernel->yield ('laziness_end', $tab); |
30
|
|
|
|
|
|
|
} |
31
|
3
|
|
|
|
|
558
|
return $response; |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
'laziness_end' => sub { |
34
|
1
|
|
|
1
|
|
220
|
my ($heap) = $_[HEAP]; |
35
|
1
|
|
|
|
|
31
|
warn "# we call it a life-style to stop after ".$heap->{laziness}->{limit}." requests"; |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
}, |
38
|
1
|
|
|
|
|
28
|
namespace => 'laziness', |
39
|
|
|
|
|
|
|
}, $class; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
43
|
|
|
|
|
|
|
our $REVISION = '$Id: GoldCoasting.pm,v 1.2 2005/03/19 10:04:00 rho Exp $'; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |