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
|
|
14
|
use Const::Fast; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
12
|
2
|
|
|
2
|
|
156
|
use Try::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
86
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Moose Setup |
15
|
|
|
|
|
|
|
#------------------# |
16
|
2
|
|
|
2
|
|
11
|
use Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
17
|
2
|
|
|
2
|
|
11954
|
use namespace::autoclean; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Moose Pragmas |
20
|
|
|
|
|
|
|
#------------------# |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Custom Modules |
23
|
|
|
|
|
|
|
#------------------# |
24
|
2
|
|
|
2
|
|
826
|
use CrawlerCommons::RobotRules; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
609
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# VARIABLES/CONSTANTS |
28
|
|
|
|
|
|
|
######################################## |
29
|
|
|
|
|
|
|
# Constants |
30
|
|
|
|
|
|
|
#------------------# |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Variables |
33
|
|
|
|
|
|
|
#------------------# |
34
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
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
|
566
|
my ($self, $path, $allow) = @_; |
114
|
254
|
|
|
|
|
7856
|
$self->current_rules->add_rule( $path, $allow ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
117
|
|
|
|
|
|
|
sub add_sitemap { |
118
|
20
|
|
|
20
|
0
|
130
|
my ($self, $sitemap) = @_; |
119
|
20
|
|
|
|
|
580
|
$self->current_rules->add_sitemap( $sitemap ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
122
|
44
|
|
|
44
|
0
|
1246
|
sub clear_rules {$_[0]->current_rules->clear_rules;} |
123
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------# |
124
|
|
|
|
|
|
|
sub set_crawl_delay { |
125
|
9
|
|
|
9
|
0
|
20
|
my ($self, $delay_ms) = @_; |
126
|
9
|
|
|
|
|
282
|
$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__ |