line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::NoIndex; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: add meta tag to HTML output to define a policy for robots |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
3582
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
692
|
use Carp qw(croak); |
|
3
|
|
|
|
|
28
|
|
|
3
|
|
|
|
|
3294
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %routes; |
12
|
|
|
|
|
|
|
my %routes_special; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub register { |
16
|
19
|
|
|
19
|
1
|
109782
|
my ($self, $app, $config) = @_; |
17
|
|
|
|
|
|
|
|
18
|
19
|
100
|
66
|
|
|
106
|
if ( !$config || !%{$config} ) { |
|
19
|
|
|
|
|
115
|
|
19
|
2
|
|
|
|
|
8
|
$config = { all_routes => 1 }; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
19
|
|
100
|
|
|
121
|
my $default_value = $config->{default} // 'noindex'; |
23
|
|
|
|
|
|
|
|
24
|
19
|
|
|
|
|
65
|
%routes = (); |
25
|
19
|
|
|
|
|
68
|
%routes_special = (); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
ROUTENAME: |
28
|
19
|
100
|
|
|
|
49
|
for my $route_name ( keys %{ $config->{routes} || {} } ) { |
|
19
|
|
|
|
|
135
|
|
29
|
14
|
|
|
|
|
34
|
my $value = $config->{routes}->{$route_name}; |
30
|
14
|
100
|
|
|
|
46
|
$value = $default_value if $value eq '1'; |
31
|
|
|
|
|
|
|
|
32
|
14
|
100
|
|
|
|
62
|
if ( $route_name =~ m{\A(.*?)\#\#\#(.*)}xms ) { |
33
|
4
|
|
50
|
|
|
30
|
my %conditions = map{ my ($param, $regex) = split /=/, $_; $param => qr/\A(?:$regex)\z/ } split /\&/, $2 // ''; |
|
5
|
|
|
|
|
48
|
|
|
5
|
|
|
|
|
108
|
|
34
|
4
|
|
|
|
|
14
|
push @{ $routes_special{$1}->{conditions} }, \%conditions; |
|
4
|
|
|
|
|
25
|
|
35
|
4
|
|
|
|
|
16
|
$routes_special{$1}->{value} = $value; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
14
|
next ROUTENAME; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
10
|
|
|
|
|
28
|
$routes{$route_name} = $value; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
19
|
100
|
|
|
|
53
|
for my $value ( keys %{ $config->{by_value} || {} } ) { |
|
19
|
|
|
|
|
120
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
ROUTE: |
46
|
6
|
50
|
|
|
|
16
|
for my $route_name ( @{ $config->{by_value}->{$value} || [] } ) { |
|
6
|
|
|
|
|
33
|
|
47
|
7
|
100
|
|
|
|
42
|
if ( $route_name =~ m{\A(.*?)\#\#\#(.*)}xms ) { |
48
|
2
|
|
50
|
|
|
27
|
my %conditions = map{ my ($param, $regex) = split /=/, $_; $param => qr/\A(?:$regex)\z/ } split /\&/, $2 // ''; |
|
2
|
|
|
|
|
45
|
|
|
2
|
|
|
|
|
82
|
|
49
|
2
|
|
|
|
|
10
|
push @{ $routes_special{$1}->{conditions} }, \%conditions; |
|
2
|
|
|
|
|
16
|
|
50
|
2
|
|
|
|
|
10
|
$routes_special{$1}->{value} = $value; |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
22
|
next ROUTE; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
23
|
$routes{$route_name} = $value; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$app->hook( |
60
|
|
|
|
|
|
|
after_render => sub { |
61
|
418
|
|
|
418
|
|
594724
|
my ($c, $content, $format) = @_; |
62
|
|
|
|
|
|
|
|
63
|
418
|
50
|
|
|
|
1080
|
return if !$format; |
64
|
418
|
50
|
|
|
|
1093
|
return if $format ne 'html'; |
65
|
|
|
|
|
|
|
|
66
|
418
|
|
|
|
|
2591
|
my $route = $c->current_route; |
67
|
418
|
|
|
|
|
22477
|
my $value; |
68
|
|
|
|
|
|
|
|
69
|
418
|
100
|
|
|
|
1270
|
if ( $routes{$route} ) { |
70
|
142
|
|
33
|
|
|
455
|
$value = $routes{$route} // $default_value; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
418
|
100
|
|
|
|
1036
|
if ( $routes_special{$route} ) { |
74
|
94
|
|
|
|
|
172
|
my $matched; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
CONDITION: |
77
|
94
|
50
|
|
|
|
167
|
for my $conditions ( @{ $routes_special{$route}->{conditions} || [] } ) { |
|
94
|
|
|
|
|
365
|
|
78
|
94
|
50
|
|
|
|
168
|
for my $param ( keys %{ $conditions || {} } ) { |
|
94
|
|
|
|
|
363
|
|
79
|
100
|
100
|
|
|
|
587
|
if ( $c->param( $param ) !~ $conditions->{$param} ) { |
80
|
37
|
|
|
|
|
1232
|
next CONDITION; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
57
|
|
33
|
|
|
2313
|
$value = $routes_special{$route}->{value} // $default_value; |
85
|
57
|
|
|
|
|
165
|
last CONDITION; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
418
|
100
|
66
|
|
|
1318
|
if ( $config->{all_routes} && !$value ) { |
90
|
11
|
|
|
|
|
31
|
$value = $default_value; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
418
|
100
|
|
|
|
1215
|
return if !$value; |
94
|
|
|
|
|
|
|
|
95
|
210
|
|
|
|
|
1684
|
$$content =~ s{]+ name="robots" [^>]+ >}{}x; |
96
|
210
|
|
|
|
|
1847
|
$$content =~ s{\K}{}; |
97
|
|
|
|
|
|
|
} |
98
|
19
|
|
|
|
|
219
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |