line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/HTTP-RobotsTag/trunk/lib/HTTP/RobotsTag.pm 31676 2007-12-10T00:06:35.669605Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package HTTP::RobotsTag; |
7
|
2
|
|
|
2
|
|
270198
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
100
|
|
8
|
2
|
|
|
2
|
|
17
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
9
|
2
|
|
|
2
|
|
21
|
use Carp qw(croak); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
139
|
|
10
|
2
|
|
|
2
|
|
2593
|
use DateTime::Format::Strptime; |
|
2
|
|
|
|
|
227057
|
|
|
2
|
|
|
|
|
168
|
|
11
|
2
|
|
|
2
|
|
1570
|
use HTTP::Headers; |
|
2
|
|
|
|
|
13276
|
|
|
2
|
|
|
|
|
67
|
|
12
|
2
|
|
|
2
|
|
1442
|
use HTTP::RobotsTag::Rules; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
953
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.00001'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
1
|
15
|
my $class = shift; |
18
|
1
|
|
|
|
|
5
|
my $self = bless {}, $class; |
19
|
1
|
|
|
|
|
3
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $re = qr{ |
23
|
|
|
|
|
|
|
( |
24
|
|
|
|
|
|
|
(?:no)? |
25
|
|
|
|
|
|
|
(?: |
26
|
|
|
|
|
|
|
index | |
27
|
|
|
|
|
|
|
archive | |
28
|
|
|
|
|
|
|
snippet | |
29
|
|
|
|
|
|
|
follow | |
30
|
|
|
|
|
|
|
unavailable_after:.+ |
31
|
|
|
|
|
|
|
) |
32
|
|
|
|
|
|
|
) |
33
|
|
|
|
|
|
|
(?: |
34
|
|
|
|
|
|
|
\s*,\s* |
35
|
|
|
|
|
|
|
| |
36
|
|
|
|
|
|
|
$ |
37
|
|
|
|
|
|
|
) |
38
|
|
|
|
|
|
|
}x; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub parse_headers |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
|
|
1
|
1
|
773
|
my ($self, $headers) = @_; |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
3
|
if (! eval { $headers->can('header') }) { |
|
1
|
|
|
|
|
10
|
|
45
|
0
|
|
|
|
|
0
|
croak "argument does not implement a header() function"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
11
|
my $fmt = DateTime::Format::Strptime->new( |
49
|
|
|
|
|
|
|
pattern => '%d %b %Y %H:%M:%S %Z' |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
572
|
my %directives; |
53
|
1
|
|
|
|
|
5
|
my @tags = $headers->header( 'x-robots-tag' ); |
54
|
1
|
|
|
|
|
30
|
foreach my $tag (@tags) { |
55
|
1
|
|
|
|
|
14
|
while ($tag =~ /$re/g) { |
56
|
1
|
|
|
|
|
6
|
my($key, $val) = split(/:/, $tag, 2); |
57
|
1
|
|
|
|
|
3
|
$key = lc $key; |
58
|
1
|
50
|
|
|
|
4
|
if ($key eq 'unavailable_after') { |
59
|
1
|
|
|
|
|
3
|
$val =~ s/^\s+//; |
60
|
1
|
|
|
|
|
4
|
$val =~ s/\s+$//; |
61
|
1
|
50
|
|
|
|
6
|
$directives{ $key } = $fmt->parse_datetime($val) or die; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
0
|
|
|
0
|
$directives{ $key } = $val || 1; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
1484
|
return HTTP::RobotsTag::Rules->new(%directives); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |