blib/lib/WWW/Sitemap/XML/URL.pm

filter: Statementstmt 87.1% 54 / 62 Branchbran 50.0% 7 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 80.6% 79 / 98 CC 13 SCAR 25.4
CC
13
Cov
79%
as_xml
24.9
__ANON__
3.0
BEGIN
1.0
CRAP 12.7
↑ Summary blib/lib/WWW/Sitemap/XML/Google/Video.pm »
1 #ABSTRACT: XML Sitemap url entry
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package WWW::Sitemap::XML::URL;
5 BEGIN {
6 15 ▶ $WWW::Sitemap::XML::URL::AUTHORITY = 'cpan:AJGB';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 }
8 15 $WWW::Sitemap::XML::URL::VERSION = '2.01';
9 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use WWW::Sitemap::XML::Types qw( Location ChangeFreq Priority ArrayRefOfImageObjects ArrayRefOfVideoObjects );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use MooseX::Types::DateTime::W3C qw( DateTimeW3C );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use WWW::Sitemap::XML::Google::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use WWW::Sitemap::XML::Google::Video;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17  
18 15 has 'loc' => (
19 is => 'rw',
20 isa => Location,
21 required => 1,
22 coerce => 1,
23 predicate => 'has_loc',
24 );
25  
26  
27 15 has 'lastmod' => (
28 is => 'rw',
29 isa => DateTimeW3C,
30 required => 0,
31 coerce => 1,
32 predicate => 'has_lastmod',
33 );
34  
35  
36 15 has 'changefreq' => (
37 is => 'rw',
38 isa => ChangeFreq,
39 required => 0,
40 coerce => 1,
41 predicate => 'has_changefreq',
42 );
43  
44  
45 15 has 'priority' => (
46 is => 'rw',
47 isa => Priority,
48 required => 0,
49 predicate => 'has_priority',
50 );
51  
52  
53 15 has 'images' => (
54 is => 'rw',
55 isa => ArrayRefOfImageObjects,
56 required => 0,
57 coerce => 1,
58 predicate => 'has_images',
59 );
60  
61  
62 15 has 'videos' => (
63 is => 'rw',
64 isa => ArrayRefOfVideoObjects,
65 required => 0,
66 coerce => 1,
67 predicate => 'has_videos',
68 );
69  
70  
71 15 has 'mobile' => (
72 is => 'rw',
73 isa => 'Bool',
74 required => 0,
75 coerce => 0,
76 predicate => 'has_mobile',
77 );
78  
79  
80 sub as_xml {
81 82 ▶ my $self = shift;
Subroutine as_xml: called CC=11 SCAR=32.1
Pod documented
82  
83 82 my $url = XML::LibXML::Element->new('url');
84  
85 do {
86 277 my $name = $_;
87 277 my $e = XML::LibXML::Element->new($name);
88  
89 277 $e->appendText( $self->$name );
90  
91 277 $url->appendChild( $e );
92  
93 82 } for 'loc',grep {
94 246 ▶ eval('$self->has_'.$_) || defined $self->$_()
Branch: 1 branch
BranchTrueFalseTotal
eval '$self->has_' . $_ or defined $self->$_ 51 195 246
95 } qw( lastmod changefreq priority );
96  
97 82 ▶ if ( $self->has_images ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_images) 0 82 82
98 0 ▶ for my $image ( @{ $self->images || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
$self->images or [] 0 0 0
99 0 $url->appendChild( $image->as_xml );
100 }
101 }
102  
103 82 ▶ if ( $self->has_videos ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_videos) 0 82 82
104 0 ▶ for my $video ( @{ $self->videos || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
$self->videos or [] 0 0 0
105 0 $url->appendChild( $video->as_xml );
106 }
107 }
108  
109 82 ▶ if ( $self->has_mobile && $self->mobile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_mobile and $self->mobile) 0 82 82
Condition33%1/3
$self->has_mobile and $self->mobile
!ll&&!rl&&r
8200
MC/DC0%0/2
$self->has_mobile and $self->mobile
$self->has_mobile $self->mobile
Truth table33%1/3
A and B
A= $self->has_mobileB= $self->mobile
ABresult
0X0
100
111
110 0 my $e = XML::LibXML::Element->new('mobile:mobile');
111 0 $url->appendChild( $e );
112 }
113  
114 82 return $url;
115 }
116  
117 around BUILDARGS => sub {
118 91 ▶ my $next = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
119 91 my $class = shift;
120  
121 91 ▶ if ( @_ == 1 && ! ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) 1 90 91
Condition100%3/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
8821
MC/DC100%2/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table100%3/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
122 1 return $class->$next(loc => $_[0]);
123 }
124  
125 90 return $class->$next( @_ );
126 15 };
127  
128 15 with 'WWW::Sitemap::XML::URL::Interface';
129  
130  
131 15 __PACKAGE__->meta->make_immutable;
132  
133 15 1;
134  
135 __END__
136  
137 =pod
138  
139 =encoding UTF-8
140  
141 =head1 NAME
142  
143 WWW::Sitemap::XML::URL - XML Sitemap url entry
144  
145 =head1 VERSION
146  
147 version 2.01
148  
149 =head1 SYNOPSIS
150  
151 my $url = WWW::Sitemap::XML::URL->new(
152 loc => 'http://mywebsite.com/',
153 lastmod => '2010-11-26',
154 changefreq => 'always',
155 priority => 1.0,
156 );
157  
158 XML output:
159  
160 <?xml version="1.0" encoding="UTF-8"?>
161 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
162 <url>
163 <loc>http://mywebsite.com/</loc>
164 <lastmod>2010-11-26</lastmod>
165 <changefreq>always</changefreq>
166 <priority>1.0</priority>
167 </url>
168 </urlset>
169  
170 Google sitemap video, image and mobile extensions:
171  
172 my $url2 = WWW::Sitemap::XML::URL->new(
173 loc => 'http://mywebsite.com/',
174 lastmod => '2010-11-26',
175 changefreq => 'always',
176 priority => 1.0,
177 mobile => 1,
178 images => [
179 {
180 loc => 'http://mywebsite.com/image1.jpg',
181 caption => 'Caption 1',
182 title => 'Title 1',
183 license => 'http://www.mozilla.org/MPL/2.0/',
184 geo_location => 'Town, Region',
185 },
186 {
187 loc => 'http://mywebsite.com/image2.jpg',
188 caption => 'Caption 2',
189 title => 'Title 2',
190 license => 'http://www.mozilla.org/MPL/2.0/',
191 geo_location => 'Town, Region',
192 }
193 ],
194 videos => [
195 content_loc => 'http://mywebsite.com/video1.flv',
196 player => {
197 loc => 'http://mywebsite.com/video_player.swf?video=1',
198 allow_embed => "yes",
199 autoplay => "ap=1",
200 }
201 thumbnail_loc => 'http://mywebsite.com/thumbs/1.jpg',
202 title => 'Video Title 1',
203 description => 'Video Description 1',
204 ]
205  
206 );
207  
208 XML output:
209  
210 <?xml version="1.0" encoding="UTF-8"?>
211 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
212 xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
213 xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
214 xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
215 <url>
216 <loc>http://mywebsite.com/</loc>
217 <lastmod>2010-11-26</lastmod>
218 <changefreq>always</changefreq>
219 <priority>1.0</priority>
220 <mobile:mobile/>
221 <image:image>
222 <image:loc>http://mywebsite.com/image1.jpg</image:loc>
223 <image:caption>Caption 1</image:caption>
224 <image:title>Title 1</image:title>
225 <image:license>http://www.mozilla.org/MPL/2.0/</image:license>
226 <image:geo_location>Town, Region</image:geo_location>
227 </image:image>
228 <image:image>
229 <image:loc>http://mywebsite.com/image2.jpg</image:loc>
230 <image:caption>Caption 2</image:caption>
231 <image:title>Title 2</image:title>
232 <image:license>http://www.mozilla.org/MPL/2.0/</image:license>
233 <image:geo_location>Town, Region</image:geo_location>
234 </image:image>
235 <video:video>
236 <video:content_loc>http://mywebsite.com/video1.flv</video:content_loc>
237 <video:title>Video Title 1</video:title>
238 <video:description>Video Description 1</video:description>
239 <video:thumbnail_loc>http://mywebsite.com/thumbs/1.jpg</video:thumbnail_loc>
240 <video:player_loc allow_embed="yes" autoplay="ap=1">http://mywebsite.com/video_player.swf?video=1</video:player_loc>
241 </video:video>
242  
243 </url>
244 </urlset>
245  
246 =head1 DESCRIPTION
247  
248 WWW::Sitemap::XML::URL represents single url entry in sitemap file.
249  
250 Class implements L<WWW::Sitemap::XML::URL::Interface>.
251  
252 =head1 ATTRIBUTES
253  
254 =head2 loc
255  
256 URL of the page.
257  
258 isa: L<WWW::Sitemap::XML::Types/"Location">
259  
260 Required.
261  
262 =head2 lastmod
263  
264 The date of last modification of the page.
265  
266 isa: L<MooseX::Types::DateTime::W3C/"DateTimeW3C">
267  
268 Optional.
269  
270 =head2 changefreq
271  
272 How frequently the page is likely to change.
273  
274 isa: L<WWW::Sitemap::XML::Types/"ChangeFreq">
275  
276 Optional.
277  
278 =head2 priority
279  
280 The priority of this URL relative to other URLs on your site.
281  
282 isa: L<WWW::Sitemap::XML::Types/"Priority">
283  
284 Optional.
285  
286 =head2 images
287  
288 Array reference of images on page.
289  
290 Note: This is a Google sitemap extension.
291  
292 isa: L<WWW::Sitemap::XML::Types/"ArrayRefOfImageObjects">
293  
294 Optional.
295  
296 =head2 videos
297  
298 Array reference of videos on page.
299  
300 Note: This is a Google sitemap extension.
301  
302 isa: L<WWW::Sitemap::XML::Types/"ArrayRefOfVideoObjects">
303  
304 Optional.
305  
306 =head2 mobile
307  
308 Flag indicating that page serves feature phone content.
309  
310 A mobile sitemap must contain only URLs that serve feature phone web content.
311 All other URLs are ignored by the Google crawling mechanisms so, if you have
312 non-featurephone content, create a separate sitemap for those URLs.
313  
314 Note: This is a Google sitemap extension.
315  
316 isa: C<Bool>
317  
318 Optional.
319  
320 =head1 METHODS
321  
322 =head2 as_xml
323  
324 Returns L<XML::LibXML::Element> object representing the C<E<lt>urlE<gt>> entry in the sitemap.
325  
326 =head1 SEE ALSO
327  
328 L<http://www.sitemaps.org/protocol.php>
329  
330 L<WWW::Sitemap::XML::Google::Image>
331  
332 L<WWW::Sitemap::XML::Google::Video>
333  
334 L<https://support.google.com/webmasters/answer/183668>
335  
336 =head1 AUTHOR
337  
338 Alex J. G. Burzyński <ajgb@cpan.org>
339  
340 =head1 COPYRIGHT AND LICENSE
341  
342 This software is copyright (c) 2014 by Alex J. G. Burzyński <ajgb@cpan.org>.
343  
344 This is free software; you can redistribute it and/or modify it under
345 the same terms as the Perl 5 programming language system itself.
346  
347 =cut
↑ Summary blib/lib/WWW/Sitemap/XML/Google/Video.pm »