line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
package CrawlerCommons::ParseState; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# MODULE IMPORTS |
5
|
|
|
|
|
|
|
######################################## |
6
|
|
|
|
|
|
|
# Pragmas |
7
|
|
|
|
|
|
|
#------------------# |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# CPAN/Core |
10
|
|
|
|
|
|
|
#------------------# |
11
|
2
|
|
|
2
|
|
16
|
use Const::Fast; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
22
|
|
12
|
2
|
|
|
2
|
|
188
|
use Try::Tiny; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
112
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Moose Setup |
15
|
|
|
|
|
|
|
#------------------# |
16
|
2
|
|
|
2
|
|
15
|
use Moose; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
15
|
|
17
|
2
|
|
|
2
|
|
26171
|
use namespace::autoclean; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
21
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Moose Pragmas |
20
|
|
|
|
|
|
|
#------------------# |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Custom Modules |
23
|
|
|
|
|
|
|
#------------------# |
24
|
2
|
|
|
2
|
|
1259
|
use CrawlerCommons::RobotRules; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
803
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# VARIABLES/CONSTANTS |
28
|
|
|
|
|
|
|
######################################## |
29
|
|
|
|
|
|
|
# Constants |
30
|
|
|
|
|
|
|
#------------------# |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Variables |
33
|
|
|
|
|
|
|
#------------------# |
34
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# MOOSE ATTRIBUTES |
38
|
|
|
|
|
|
|
######################################## |
39
|
|
|
|
|
|
|
# Class |
40
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
41
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Instance |
44
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
45
|
|
|
|
|
|
|
has 'current_rules' => ( |
46
|
|
|
|
|
|
|
default => sub { |
47
|
|
|
|
|
|
|
CrawlerCommons::RobotRules->new( |
48
|
|
|
|
|
|
|
_mode => $CrawlerCommons::RobotRules::ALLOW_SOME); |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => 'CrawlerCommons::RobotRules', |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
54
|
|
|
|
|
|
|
has 'is_adding_rules' => ( |
55
|
|
|
|
|
|
|
default => 0, |
56
|
|
|
|
|
|
|
is => 'rw', |
57
|
|
|
|
|
|
|
isa => 'Bool', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
60
|
|
|
|
|
|
|
has 'is_finished_agent_fields' => ( |
61
|
|
|
|
|
|
|
default => 0, |
62
|
|
|
|
|
|
|
is => 'rw', |
63
|
|
|
|
|
|
|
isa => 'Bool', |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
66
|
|
|
|
|
|
|
has 'is_matched_real_name' => ( |
67
|
|
|
|
|
|
|
default => 0, |
68
|
|
|
|
|
|
|
is => 'rw', |
69
|
|
|
|
|
|
|
isa => 'Bool', |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
72
|
|
|
|
|
|
|
has 'is_matched_wildcard' => ( |
73
|
|
|
|
|
|
|
default => 0, |
74
|
|
|
|
|
|
|
is => 'rw', |
75
|
|
|
|
|
|
|
isa => 'Bool', |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
78
|
|
|
|
|
|
|
has 'is_skip_agents' => ( |
79
|
|
|
|
|
|
|
default => 0, |
80
|
|
|
|
|
|
|
is => 'rw', |
81
|
|
|
|
|
|
|
isa => 'Bool', |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
84
|
|
|
|
|
|
|
has 'target_name' => ( |
85
|
|
|
|
|
|
|
is => 'ro', |
86
|
|
|
|
|
|
|
isa => 'Str', |
87
|
|
|
|
|
|
|
required => 1, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
90
|
|
|
|
|
|
|
has 'url' => ( |
91
|
|
|
|
|
|
|
is => 'ro', |
92
|
|
|
|
|
|
|
isa => 'Str', |
93
|
|
|
|
|
|
|
required => 1, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# METHODS |
98
|
|
|
|
|
|
|
######################################## |
99
|
|
|
|
|
|
|
# Construction |
100
|
|
|
|
|
|
|
#------------------# |
101
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
102
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Class Methods |
105
|
|
|
|
|
|
|
#------------------# |
106
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
107
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Instance Methods |
110
|
|
|
|
|
|
|
#------------------# |
111
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
112
|
|
|
|
|
|
|
sub add_rule { |
113
|
254
|
|
|
254
|
0
|
663
|
my ($self, $path, $allow) = @_; |
114
|
254
|
|
|
|
|
8531
|
$self->current_rules->add_rule( $path, $allow ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
117
|
|
|
|
|
|
|
sub add_sitemap { |
118
|
20
|
|
|
20
|
0
|
215
|
my ($self, $sitemap) = @_; |
119
|
20
|
|
|
|
|
693
|
$self->current_rules->add_sitemap( $sitemap ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
122
|
44
|
|
|
44
|
0
|
1478
|
sub clear_rules {$_[0]->current_rules->clear_rules;} |
123
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
124
|
|
|
|
|
|
|
sub set_crawl_delay { |
125
|
9
|
|
|
9
|
0
|
28
|
my ($self, $delay_ms) = @_; |
126
|
9
|
|
|
|
|
298
|
$self->current_rules->set_crawl_delay( $delay_ms ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Private Methods |
131
|
|
|
|
|
|
|
#------------------# |
132
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
133
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
############################################################################### |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
############################################################################### |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |