line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/GunghoX-FollowLinks/trunk/lib/GunghoX/FollowLinks/Rule/URI.pm 8923 2007-11-12T03:07:51.610373Z 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
|
|
723
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
9
|
1
|
|
|
1
|
|
4
|
use base qw(GunghoX::FollowLinks::Rule); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
59
|
|
10
|
1
|
|
|
1
|
|
18
|
use GunghoX::FollowLinks::Rule qw(FOLLOW_ALLOW FOLLOW_DENY FOLLOW_DEFER); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
11
|
1
|
|
|
1
|
|
593
|
use URI::Match; |
|
1
|
|
|
|
|
265
|
|
|
1
|
|
|
|
|
9
|
|
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
|
0
|
0
|
|
|
|
|
if ($url->match_parts(%m)) { |
44
|
0
|
|
|
|
|
|
return $action; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if (defined $nomatch) { |
48
|
0
|
|
|
|
|
|
return $nomatch; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
return &GunghoX::FollowLinks::Rule::FOLLOW_DEFER; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
GunghoX::FollowLinks::Rule::URI - Follow Dependig On URI |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use GunghoX::FollowLinks::Rule qw(FOLLOW_ALLOW FOLLOW_DENY); |
65
|
|
|
|
|
|
|
use GunghoX::FollowLinks::Rule::URI; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
GunghoX::FollowLinks::Rule::URI->new( |
68
|
|
|
|
|
|
|
match => [ |
69
|
|
|
|
|
|
|
{ action => FOLLOW_DENY, host => qr/^.+\.example\.org$/ }, |
70
|
|
|
|
|
|
|
{ action => FOLLOW_ALLOW, host => qr/^.+\.example\.com$/ }, |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
action => FOLLOW_ALLOW, |
73
|
|
|
|
|
|
|
action_nomatch => FOLLOW_DENY, |
74
|
|
|
|
|
|
|
host => qr/^.+\.example\.net$/ } |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
] |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This is a rule that matches against a URL using URI::Match. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 new |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 apply |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |