blib/lib/WWW/Sitemap/XML/Google/Image.pm

filter: Statementstmt 75.0% 30 / 40 Branchbran 25.0% 1 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 70.6% 41 / 58 CC 5 SCAR 14.6
CC
5
Cov
70%
as_xml
12.0
__ANON__
3.2
BEGIN
1.0
CRAP 4.3
« blib/lib/WWW/Sitemap/XML.pm ↑ Summary Build »
1 #ABSTRACT: XML Sitemap Google extension image entry
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package WWW::Sitemap::XML::Google::Image;
5 BEGIN {
6 22 ▶ $WWW::Sitemap::XML::Google::Image::AUTHORITY = 'cpan:AJGB';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 }
8 22 $WWW::Sitemap::XML::Google::Image::VERSION = '2.01';
9 22 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use WWW::Sitemap::XML::Types qw( Location );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14  
15 22 has 'loc' => (
16 is => 'rw',
17 isa => Location,
18 required => 1,
19 coerce => 1,
20 predicate => 'has_loc',
21 );
22  
23  
24 22 has 'caption' => (
25 is => 'rw',
26 isa => 'Str',
27 required => 0,
28 predicate => 'has_caption',
29 );
30  
31  
32 22 has 'title' => (
33 is => 'rw',
34 isa => 'Str',
35 required => 0,
36 predicate => 'has_title',
37 );
38  
39  
40 22 has 'geo_location' => (
41 is => 'rw',
42 isa => 'Str',
43 required => 0,
44 predicate => 'has_geo_location',
45 );
46  
47  
48 22 has 'license' => (
49 is => 'rw',
50 isa => Location,
51 required => 0,
52 coerce => 1,
53 predicate => 'has_license',
54 );
55  
56  
57 sub as_xml {
58 0 ▶ my $self = shift;
Subroutine as_xml: not called CC=3 SCAR=24.8
Pod documented
59  
60 0 my $image = XML::LibXML::Element->new('image:image');
61  
62 do {
63 0 my $name = $_;
64 0 my $e = XML::LibXML::Element->new("image:$name");
65  
66 0 $e->appendText( $self->$name );
67  
68 0 $image->appendChild( $e );
69  
70 0 } for 'loc',grep {
71 0 ▶ eval('$self->has_'.$_) || defined $self->$_()
Branch: 1 branch
BranchTrueFalseTotal
eval '$self->has_' . $_ or defined $self->$_ 0 0 0
72 } qw( caption title license geo_location );
73  
74 0 return $image;
75 }
76  
77 around BUILDARGS => sub {
78 8 ▶ my $next = shift;
Subroutine __ANON__: called CC=3 SCAR=11.8
79 8 my $class = shift;
80  
81 8 ▶ if ( @_ == 1 && ! ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) 0 8 8
Condition66%2/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
440
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
82 0 return $class->$next(loc => $_[0]);
83 }
84 8 return $class->$next( @_ );
85 22 };
86  
87 22 with 'WWW::Sitemap::XML::Google::Image::Interface';
88  
89  
90 22 __PACKAGE__->meta->make_immutable;
91  
92 22 1;
93  
94 __END__
95  
96 =pod
97  
98 =encoding UTF-8
99  
100 =head1 NAME
101  
102 WWW::Sitemap::XML::Google::Image - XML Sitemap Google extension image entry
103  
104 =head1 VERSION
105  
106 version 2.01
107  
108 =head1 SYNOPSIS
109  
110 my $image = WWW::Sitemap::XML::Google::Image->new(
111 {
112 loc => 'http://mywebsite.com/image1.jpg',
113 caption => 'Caption 1',
114 title => 'Title 1',
115 license => 'http://www.mozilla.org/MPL/2.0/',
116 geo_location => 'Town, Region',
117 },
118 );
119  
120 XML output:
121  
122 <?xml version="1.0" encoding="UTF-8"?>
123 <image:image>
124 <image:loc>http://mywebsite.com/image1.jpg</image:loc>
125 <image:caption>Caption 1</image:caption>
126 <image:title>Title 1</image:title>
127 <image:license>http://www.mozilla.org/MPL/2.0/</image:license>
128 <image:geo_location>Town, Region</image:geo_location>
129 </image:image>
130  
131 =head1 DESCRIPTION
132  
133 WWW::Sitemap::XML::Google::Image represents single image entry in sitemap file.
134  
135 Class implements L<WWW::Sitemap::XML::Google::Image::Interface>.
136  
137 =head1 ATTRIBUTES
138  
139 =head2 loc
140  
141 The URL of the image.
142  
143 isa: L<WWW::Sitemap::XML::Types/"Location">
144  
145 Required.
146  
147 =head2 caption
148  
149 The caption of the image.
150  
151 isa: C<Str>
152  
153 Optional.
154  
155 =head2 title
156  
157 The title of the image.
158  
159 isa: C<Str>
160  
161 Optional.
162  
163 =head2 geo_location
164  
165 The geographic location of the image.
166  
167 isa: C<Str>
168  
169 Optional.
170  
171 =head2 license
172  
173 A URL to the license of the image.
174  
175 isa: L<WWW::Sitemap::XML::Types/"Location">
176  
177 Optional.
178  
179 =head1 METHODS
180  
181 =head2 as_xml
182  
183 Returns L<XML::LibXML::Element> object representing the C<E<lt>image:imageE<gt>> entry in the sitemap.
184  
185 =head1 SEE ALSO
186  
187 L<https://support.google.com/webmasters/answer/183668>
188  
189 =head1 AUTHOR
190  
191 Alex J. G. Burzyński <ajgb@cpan.org>
192  
193 =head1 COPYRIGHT AND LICENSE
194  
195 This software is copyright (c) 2014 by Alex J. G. Burzyński <ajgb@cpan.org>.
196  
197 This is free software; you can redistribute it and/or modify it under
198 the same terms as the Perl 5 programming language system itself.
199  
200 =cut
« blib/lib/WWW/Sitemap/XML.pm ↑ Summary Build »