line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/GunghoX-FollowLinks/trunk/lib/GunghoX/FollowLinks/Rule/Fresh.pm 31640 2007-12-01T15:48:28.904993Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package GunghoX::FollowLinks::Rule::Fresh; |
7
|
1
|
|
|
1
|
|
1280
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
373
|
use Gungho::Util; |
|
1
|
|
|
|
|
4469
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
26
|
use GunghoX::FollowLinks::Rule qw(FOLLOW_ALLOW FOLLOW_DENY); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
257
|
use base qw(GunghoX::FollowLinks::Rule); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
199
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(storage); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
1
|
86
|
my $class = shift; |
18
|
1
|
|
|
|
|
3
|
my %args = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
2
|
my $storage_config = delete $args{storage}; |
21
|
|
|
|
|
|
|
my $storage_module = Gungho::Util::load_module( |
22
|
1
|
|
50
|
|
|
8
|
$storage_config->{module} || 'Memory', |
23
|
|
|
|
|
|
|
'GunghoX::FollowLinks::Rule::Fresh' |
24
|
|
|
|
|
|
|
); |
25
|
1
|
50
|
|
|
|
10
|
my $storage = $storage_module->new( %{ $storage_config->{config} || {} } ); |
|
1
|
|
|
|
|
11
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
9
|
$class->next::method(storage => $storage); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub apply |
31
|
|
|
|
|
|
|
{ |
32
|
3
|
|
|
3
|
1
|
6792
|
my ($self, $c, $response, $url, $attrs) = @_; |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
10
|
my $storage = $self->storage; |
35
|
3
|
100
|
|
|
|
16
|
if ($storage->get($url)) { |
36
|
2
|
|
|
|
|
14
|
return FOLLOW_DENY; |
37
|
|
|
|
|
|
|
} else { |
38
|
1
|
|
|
|
|
7
|
$storage->put($url); |
39
|
1
|
|
|
|
|
8
|
return FOLLOW_ALLOW; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
GunghoX::FollowLinks::Rule::Fresh - Only Follow Fresh Links |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use GunghoX::FollowLinks::Rule::Fresh; |
54
|
|
|
|
|
|
|
my $rule = GunghoX::FollowLinks::Rule::Fresh->new( |
55
|
|
|
|
|
|
|
storage => { |
56
|
|
|
|
|
|
|
module => "Memory", |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
$rule->apply( $c, $response, $url, $attrs ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This rule allows you to follow links thatyou haven't seen yet. The list of |
64
|
|
|
|
|
|
|
URLs that have been fetched are stored in a storage module of your choise. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
If you want to put it in a memcached instance, for example, you can specify |
67
|
|
|
|
|
|
|
it like this: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $rule = GunghoX::FollowLinks::Rule::Fresh->new( |
70
|
|
|
|
|
|
|
storage => { |
71
|
|
|
|
|
|
|
module => "Cache", |
72
|
|
|
|
|
|
|
config => { |
73
|
|
|
|
|
|
|
cache => { |
74
|
|
|
|
|
|
|
module => "Cache::Memcached", |
75
|
|
|
|
|
|
|
config => { |
76
|
|
|
|
|
|
|
servers => "127.0.0.1:11211", |
77
|
|
|
|
|
|
|
compress_threshold => 10_000, |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 METHODS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 new |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Creates a new rule instance. You must specify the storage backend. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 apply |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Applies the rule. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |