line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
909408
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
176
|
|
2
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
259
|
|
3
|
|
|
|
|
|
|
package WWW::SitemapIndex::XML; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
5
|
|
|
5
|
|
158
|
$WWW::SitemapIndex::XML::AUTHORITY = 'cpan:AJGB'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
{ |
8
|
|
|
|
|
|
|
$WWW::SitemapIndex::XML::VERSION = '1.121160'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
#ABSTRACT: XML Sitemap index protocol |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
2495
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
extends qw( WWW::Sitemap::XML ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use WWW::SitemapIndex::XML::Sitemap; |
16
|
|
|
|
|
|
|
use XML::LibXML 1.70; |
17
|
|
|
|
|
|
|
use Scalar::Util qw( blessed ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use WWW::Sitemap::XML::Types qw( SitemapIndexSitemap ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has '+_check_req_interface' => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
default => sub { |
25
|
|
|
|
|
|
|
sub { |
26
|
|
|
|
|
|
|
die 'object does not implement WWW::SitemapIndex::XML::Sitemap::Interface' |
27
|
|
|
|
|
|
|
unless is_SitemapIndexSitemap($_[0]); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has '+_entry_class' => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
default => 'WWW::SitemapIndex::XML::Sitemap' |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has '+_root_ns' => ( |
38
|
|
|
|
|
|
|
is => 'ro', |
39
|
|
|
|
|
|
|
default => sub { |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
'xmlns' => "http://www.sitemaps.org/schemas/sitemap/0.9", |
42
|
|
|
|
|
|
|
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", |
43
|
|
|
|
|
|
|
'xsi:schemaLocation' => join(' ', |
44
|
|
|
|
|
|
|
'http://www.sitemaps.org/schemas/sitemap/0.9', |
45
|
|
|
|
|
|
|
'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' |
46
|
|
|
|
|
|
|
), |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has '+_root_elem' => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
default => 'sitemapindex', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub sitemaps { shift->_entries } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding utf-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
WWW::SitemapIndex::XML - XML Sitemap index protocol |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
version 1.121160 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use WWW::SitemapIndex::XML; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $index = WWW::SitemapIndex::XML->new(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# add new sitemaps |
85
|
|
|
|
|
|
|
$index->add( 'http://mywebsite.com/sitemap1.xml.gz' ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# or |
88
|
|
|
|
|
|
|
$index->add( |
89
|
|
|
|
|
|
|
loc => 'http://mywebsite.com/sitemap1.xml.gz', |
90
|
|
|
|
|
|
|
lastmod => '2010-11-26', |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# or |
94
|
|
|
|
|
|
|
$index->add( |
95
|
|
|
|
|
|
|
WWW::SitemapIndex::XML::Sitemap->new( |
96
|
|
|
|
|
|
|
loc => 'http://mywebsite.com/sitemap1.xml.gz', |
97
|
|
|
|
|
|
|
lastmod => '2010-11-26', |
98
|
|
|
|
|
|
|
) |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# read sitemaps from existing sitemap_index.xml file |
102
|
|
|
|
|
|
|
my @sitemaps = $index->read( 'sitemap_index.xml' ); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# load sitemaps from existing sitemap_index.xml file |
105
|
|
|
|
|
|
|
$index->load( 'sitemap_index.xml' ); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# get XML::LibXML object |
108
|
|
|
|
|
|
|
my $xml = $index->as_xml; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
print $xml->toString(1); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# write to file |
113
|
|
|
|
|
|
|
$index->write( 'sitemap_index.xml', my $pretty_print = 1 ); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# write compressed |
116
|
|
|
|
|
|
|
$index->write( 'sitemap_index.xml.gz' ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Read and write sitemap index xml files as defined at L<http://www.sitemaps.org/>. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 add($sitemap|%attrs) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$index->add( |
127
|
|
|
|
|
|
|
WWW::SitemapIndex::XML::Sitemap->new( |
128
|
|
|
|
|
|
|
loc => 'http://mywebsite.com/sitemap1.xml.gz', |
129
|
|
|
|
|
|
|
lastmod => '2010-11-26', |
130
|
|
|
|
|
|
|
) |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Add the C<$sitemap> object representing single sitemap in the sitemap index. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Accepts blessed objects implementing L<WWW::SitemapIndex::XML::Sitemap::Interface>. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Otherwise the arguments C<%attrs> are passed as-is to create new |
138
|
|
|
|
|
|
|
L<WWW::SitemapIndex::XML::Sitemap> object. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$index->add( |
141
|
|
|
|
|
|
|
loc => 'http://mywebsite.com/sitemap1.xml.gz', |
142
|
|
|
|
|
|
|
lastmod => '2010-11-26', |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# single url argument |
146
|
|
|
|
|
|
|
$index->add( 'http://mywebsite.com/' ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# is same as |
149
|
|
|
|
|
|
|
$index->add( loc => 'http://mywebsite.com/sitemap1.xml.gz' ); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Performs basic validation of sitemaps added: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * maximum of 50 000 sitemaps in single sitemap |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * URL no longer then 2048 characters |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * all URLs should use the same protocol and reside on same host |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 sitemaps |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my @sitemaps = $index->sitemaps; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Returns a list of all Sitemap objects added to sitemap index. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 load(%sitemap_index_location) |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$index->load( location => $sitemap_index_file ); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
It is a shortcut for: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
$index->add($_) for $index->read( location => $sitemap_index_file ); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Please see L<"read"> for details. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 read(%sitemap_index_location) |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# file or url to sitemap index |
182
|
|
|
|
|
|
|
my @sitemaps = $index->read( location => $file_or_url ); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# file handle |
185
|
|
|
|
|
|
|
my @sitemaps = $index->read( IO => $fh ); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# xml string |
188
|
|
|
|
|
|
|
my @sitemaps = $index->read( string => $xml ); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Read the sitemap index from file, URL, open file handle or string and return |
191
|
|
|
|
|
|
|
the list of L<WWW::SitemapIndex::XML::Sitemap> objects representing |
192
|
|
|
|
|
|
|
C<E<lt>sitemapE<gt>> elements. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 write($file, $format = 0) |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# write to file |
197
|
|
|
|
|
|
|
$index->write( 'sitemap_index.xml', my $pretty_print = 1); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# or |
200
|
|
|
|
|
|
|
my $fh = IO::File->new(); |
201
|
|
|
|
|
|
|
$fh->open('sitemap_index.xml', 'w'); |
202
|
|
|
|
|
|
|
$index->write( $fh, my $pretty_print = 1); |
203
|
|
|
|
|
|
|
$cfh->close; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# write compressed |
206
|
|
|
|
|
|
|
$index->write( 'sitemap_index.xml.gz' ); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Write XML sitemap index to C<$file> - a file name or L<IO::Handle> object. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
If file names ends in C<.gz> then the output file will be compressed by |
211
|
|
|
|
|
|
|
setting compression on xml object - please note that it requires I<libxml2> to |
212
|
|
|
|
|
|
|
be compiled with I<zlib> support. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Optional C<$format> is passed to C<toFH> or C<toFile> methods |
215
|
|
|
|
|
|
|
(depending on the type of C<$file>, respectively for file handle and file name) |
216
|
|
|
|
|
|
|
as described in L<XML::LibXML>. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 as_xml |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
my $xml = $index->as_xml; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# pretty print |
223
|
|
|
|
|
|
|
print $xml->toString(1); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# write compressed |
226
|
|
|
|
|
|
|
$xml->setCompression(8); |
227
|
|
|
|
|
|
|
$xml->toFile( "sitemap_index.xml.gz" ); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Returns L<XML::LibXML::Document> object representing the sitemap index in XML |
230
|
|
|
|
|
|
|
format. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
The C<E<lt>sitemapE<gt>> elements are built by calling I<as_xml> on all Sitemap |
233
|
|
|
|
|
|
|
objects added into sitemap index. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 SEE ALSO |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=over 4 |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item * |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
L<WWW::Sitemap::XML|WWW::Sitemap::XML> |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item * |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
L<http://www.sitemaps.org/> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=back |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 AUTHOR |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Alex J. G. BurzyÅski <ajgb@cpan.org> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
This software is copyright (c) 2010 by Alex J. G. BurzyÅski <ajgb@cpan.org>. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
260
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |
263
|
|
|
|
|
|
|
|