line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Meta::Robots; |
2
|
|
|
|
|
|
|
############################################################################ |
3
|
|
|
|
|
|
|
# A simple HTML meta tag "robots" generator. |
4
|
|
|
|
|
|
|
# @copyright © 2013, BURNERSK. Some rights reserved. |
5
|
|
|
|
|
|
|
# @license http://www.perlfoundation.org/artistic_license_2_0 Artistic License 2.0 |
6
|
|
|
|
|
|
|
# @author BURNERSK |
7
|
|
|
|
|
|
|
############################################################################ |
8
|
|
|
|
|
|
|
# Perl pragmas. |
9
|
3
|
|
|
3
|
|
90559
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
108
|
|
10
|
3
|
|
|
3
|
|
16
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
117
|
|
11
|
3
|
|
|
3
|
|
13
|
use utf8; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
19
|
|
12
|
3
|
|
|
3
|
|
2454
|
use version 0.77; our $VERSION = version->new('v0.3.3'); |
|
3
|
|
|
|
|
7208
|
|
|
3
|
|
|
|
|
21
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
############################################################################ |
15
|
|
|
|
|
|
|
# Register accessor methods. |
16
|
|
|
|
|
|
|
BEGIN { |
17
|
3
|
|
|
3
|
|
320
|
no strict 'refs'; ## no critic (ProhibitNoStrict ProhibitProlongedStrictureOverride) |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
89
|
|
18
|
3
|
|
|
3
|
|
17
|
use Carp qw( carp ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1075
|
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
12
|
my @simple_accessors = qw( follow archive odp ydir snippet ); |
21
|
3
|
|
|
|
|
11
|
my %deprecated_accessors = ( |
22
|
|
|
|
|
|
|
open_directory_project => 'odp', |
23
|
|
|
|
|
|
|
yahoo => 'ydir', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Register simple accessors which only can get/set boolean values. |
27
|
3
|
|
|
|
|
8
|
foreach my $accessor (@simple_accessors) { |
28
|
15
|
|
|
|
|
86
|
*{"HTML::Meta::Robots::$accessor"} = sub { |
29
|
41
|
|
|
41
|
|
101
|
my ( $self, @params ) = @_; |
30
|
41
|
|
|
|
|
90
|
$self->_accessor( $accessor, @params ); |
31
|
15
|
|
|
|
|
64
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Register index accessor which also sets simple accessors. |
35
|
3
|
|
|
|
|
25
|
*{'HTML::Meta::Robots::index'} = sub { |
36
|
9
|
|
|
9
|
|
22
|
my ( $self, @params ) = @_; |
37
|
9
|
50
|
|
|
|
26
|
if ( scalar @params ) { |
38
|
9
|
|
|
|
|
33
|
$self->_accessor( $_, @params ) for @simple_accessors; |
39
|
|
|
|
|
|
|
} |
40
|
9
|
|
|
|
|
27
|
$self->_accessor( 'index', @params ); |
41
|
3
|
|
|
|
|
21
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Register DEPRECATED accessors. |
44
|
3
|
|
|
|
|
12
|
foreach my $accessor ( keys %deprecated_accessors ) { |
45
|
6
|
|
|
|
|
1934
|
*{"HTML::Meta::Robots::$accessor"} = sub { |
46
|
0
|
|
|
0
|
|
0
|
my ( $self, @params ) = @_; |
47
|
0
|
|
|
|
|
0
|
carp sprintf |
48
|
|
|
|
|
|
|
q{Usage of %s->%s is DEPRECATED and will be removed in future! Use %s->%s instead}, |
49
|
|
|
|
|
|
|
__PACKAGE__, $accessor, |
50
|
|
|
|
|
|
|
__PACKAGE__, $deprecated_accessors{$accessor}; |
51
|
0
|
|
|
|
|
0
|
$self->_accessor( $deprecated_accessors{$accessor}, @params ); |
52
|
6
|
|
|
|
|
22
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
############################################################################ |
57
|
|
|
|
|
|
|
# Class constructor. |
58
|
|
|
|
|
|
|
sub new { |
59
|
13
|
|
|
13
|
1
|
2118
|
my ( $class, %params ) = @_; |
60
|
13
|
|
|
|
|
43
|
my $self = bless {}, $class; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Setup property order. |
63
|
13
|
|
|
|
|
64
|
$self->{order} = [qw( index follow archive odp ydir snippet )]; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Allow all properties by default. |
66
|
13
|
|
|
|
|
18
|
$self->{props}->{$_} = 1 for @{ $self->{order} }; |
|
13
|
|
|
|
|
120
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Set properties configured by init parameters. |
69
|
13
|
|
|
|
|
49
|
$self->$_( $params{$_} ) for grep { exists $self->{props}->{$_} } keys %params; |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
|
71
|
13
|
|
|
|
|
102
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
############################################################################ |
75
|
|
|
|
|
|
|
# INTERNAL - Simple getter/setter for internal fields. |
76
|
|
|
|
|
|
|
sub _accessor { |
77
|
95
|
|
|
95
|
|
153
|
my ( $self, $field, @params ) = @_; |
78
|
95
|
50
|
|
|
|
193
|
if ( scalar @params ) { |
79
|
95
|
100
|
|
|
|
203
|
$self->{props}->{$field} = $params[0] ? 1 : 0; |
80
|
95
|
|
|
|
|
940
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
0
|
return $self->{props}->{$field}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
############################################################################ |
86
|
|
|
|
|
|
|
# Return robots meta tag's content. |
87
|
|
|
|
|
|
|
sub content { |
88
|
16
|
|
|
16
|
1
|
24
|
my ($self) = @_; |
89
|
16
|
100
|
|
|
|
19
|
return join q{,}, map { $self->{props}->{$_} ? $_ : "no$_" } @{ $self->{order} }; |
|
96
|
|
|
|
|
346
|
|
|
16
|
|
|
|
|
37
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
############################################################################ |
93
|
|
|
|
|
|
|
# Return robots meta tag. |
94
|
|
|
|
|
|
|
sub meta { |
95
|
2
|
|
|
2
|
1
|
4
|
my ( $self, $no_xhtml ) = @_; |
96
|
2
|
100
|
|
|
|
7
|
if ( !$no_xhtml ) { |
97
|
1
|
|
|
|
|
3
|
return sprintf '', $self->content; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
1
|
|
|
|
|
3
|
return sprintf '', $self->content; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
############################################################################ |
105
|
|
|
|
|
|
|
# Parses external robot meta tag content. |
106
|
|
|
|
|
|
|
sub parse { |
107
|
3
|
|
|
3
|
1
|
5
|
my ( $self, $content ) = @_; |
108
|
3
|
100
|
|
|
|
46
|
my %props = map { $_ =~ m/^(no)?(.+)$/s; $2 => $1 ? 0 : 1 } split /\s*,\s*/s, lc $content; |
|
19
|
|
|
|
|
47
|
|
|
19
|
|
|
|
|
114
|
|
109
|
3
|
|
50
|
|
|
23
|
$self->index( delete( $props{index} ) // 1 ); |
110
|
3
|
|
|
|
|
9
|
$self->$_( delete $props{$_} ) for grep { exists $self->{props}->{$_} } keys %props; |
|
16
|
|
|
|
|
42
|
|
111
|
3
|
100
|
|
|
|
13
|
$self->{unknown_props} = \%props if scalar keys %props; |
112
|
3
|
|
|
|
|
17
|
return $self; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
############################################################################ |
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
__END__ |