line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/GunghoX-FollowLinks/trunk/lib/GunghoX/FollowLinks/Rule/URI.pm 39010 2008-01-16T14:50:27.747072Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package GunghoX::FollowLinks::Rule::URI; |
7
|
1
|
|
|
1
|
|
1470
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
6
|
use base qw(GunghoX::FollowLinks::Rule); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
115
|
|
10
|
1
|
|
|
1
|
|
29
|
use GunghoX::FollowLinks::Rule qw(FOLLOW_ALLOW FOLLOW_DENY FOLLOW_DEFER); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
1102
|
use URI::Match; |
|
1
|
|
|
|
|
550
|
|
|
1
|
|
|
|
|
14
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(match); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
18
|
0
|
|
|
|
|
|
my %args = @_; |
19
|
0
|
|
|
|
|
|
my $match = $args{match}; |
20
|
0
|
|
|
|
|
|
foreach my $m (@$match) { |
21
|
0
|
|
0
|
|
|
|
my $action = $m->{action} || FOLLOW_ALLOW; |
22
|
0
|
0
|
|
|
|
|
if ($action eq 'FOLLOW_ALLOW') { |
|
|
0
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$m->{action} = FOLLOW_ALLOW; |
24
|
|
|
|
|
|
|
} elsif ($action eq 'FOLLOW_DENY') { |
25
|
0
|
|
|
|
|
|
$m->{action} = FOLLOW_DENY; |
26
|
|
|
|
|
|
|
} |
27
|
0
|
0
|
|
|
|
|
if ($action eq 'FOLLOW_DEFER') { |
28
|
0
|
|
|
|
|
|
$m->{action} = FOLLOW_DEFER; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
$class->next::method(%args); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub apply |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
1
|
|
my ($self, $c, $response, $url, $attrs) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $match = $self->match; |
39
|
0
|
|
|
|
|
|
foreach my $m (@$match) { |
40
|
0
|
|
|
|
|
|
my %m = %$m; |
41
|
0
|
|
0
|
|
|
|
my $action = delete $m{action} || FOLLOW_ALLOW; |
42
|
0
|
|
|
|
|
|
my $nomatch = delete $m{action_nomatch}; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @match_args; |
45
|
0
|
0
|
|
|
|
|
if ($m{url}) { |
46
|
0
|
|
|
|
|
|
@match_args = ($m{url}); |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
@match_args = %m; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($url->match_parts(@match_args)) { |
52
|
0
|
|
|
|
|
|
return $action; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if (defined $nomatch) { |
56
|
0
|
|
|
|
|
|
return $nomatch; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
return &GunghoX::FollowLinks::Rule::FOLLOW_DEFER; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
GunghoX::FollowLinks::Rule::URI - Follow Dependig On URI |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use GunghoX::FollowLinks::Rule qw(FOLLOW_ALLOW FOLLOW_DENY); |
73
|
|
|
|
|
|
|
use GunghoX::FollowLinks::Rule::URI; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
GunghoX::FollowLinks::Rule::URI->new( |
76
|
|
|
|
|
|
|
match => [ |
77
|
|
|
|
|
|
|
{ action => FOLLOW_DENY, host => qr/^.+\.example\.org$/ }, |
78
|
|
|
|
|
|
|
{ action => FOLLOW_ALLOW, host => qr/^.+\.example\.com$/ }, |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
action => FOLLOW_ALLOW, |
81
|
|
|
|
|
|
|
action_nomatch => FOLLOW_DENY, |
82
|
|
|
|
|
|
|
host => qr/^.+\.example\.net$/ } |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
] |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is a rule that matches against a URL using URI::Match. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 METHODS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 new |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 apply |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |