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

filter: Statementstmt 100% 40 / 40 Branchbran 100% 4 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 59 / 59 CC 5 SCAR 6.5
CC
5
Cov
100%
as_xml
3.0
__ANON__
3.0
BEGIN
1.0
CRAP 1.9
« blib/lib/WWW/Sitemap/XML/Types.pm ↑ Summary blib/lib/WWW/SitemapIndex/XML.pm »
1 #ABSTRACT: XML Sitemap index sitemap entry
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package WWW::SitemapIndex::XML::Sitemap;
5 BEGIN {
6 8 ▶ $WWW::SitemapIndex::XML::Sitemap::AUTHORITY = 'cpan:AJGB';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 }
8 8 $WWW::SitemapIndex::XML::Sitemap::VERSION = '2.01';
9 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use WWW::Sitemap::XML::Types qw( Location );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use MooseX::Types::DateTime::W3C qw( DateTimeW3C );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16 8 has 'loc' => (
17 is => 'rw',
18 isa => Location,
19 required => 1,
20 coerce => 1,
21 predicate => 'has_loc',
22 );
23  
24  
25 8 has 'lastmod' => (
26 is => 'rw',
27 isa => DateTimeW3C,
28 required => 0,
29 coerce => 1,
30 predicate => 'has_lastmod',
31 );
32  
33  
34 sub as_xml {
35 83 ▶ my $self = shift;
Subroutine as_xml: called CC=3 SCAR=11.0
Pod documented
36  
37 83 my $sitemap = XML::LibXML::Element->new('sitemap');
38  
39 do {
40 151 my $name = $_;
41 151 my $e = XML::LibXML::Element->new($name);
42  
43 151 $e->appendText( $self->$name );
44  
45 151 $sitemap->appendChild( $e );
46  
47 83 } for 'loc',grep {
48 83 ▶ eval('$self->has_'.$_) || defined $self->$_()
Branch: 1 branch
BranchTrueFalseTotal
eval '$self->has_' . $_ or defined $self->$_ 15 68 83
49 } qw( lastmod );
50  
51  
52 83 return $sitemap;
53 }
54  
55 around BUILDARGS => sub {
56 87 ▶ my $next = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
57 87 my $class = shift;
58  
59 87 ▶ if ( @_ == 1 && ! ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) 1 86 87
Condition100%3/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
8421
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
60 1 return $class->$next(loc => $_[0]);
61 }
62 86 return $class->$next( @_ );
63 8 };
64  
65 8 with 'WWW::SitemapIndex::XML::Sitemap::Interface';
66  
67  
68 8 __PACKAGE__->meta->make_immutable;
69  
70 8 1;
71  
72 __END__
73  
74 =pod
75  
76 =encoding UTF-8
77  
78 =head1 NAME
79  
80 WWW::SitemapIndex::XML::Sitemap - XML Sitemap index sitemap entry
81  
82 =head1 VERSION
83  
84 version 2.01
85  
86 =head1 SYNOPSIS
87  
88 my $sitemap = WWW::SitemapIndex::XML::Sitemap->new(
89 loc => 'http://mywebsite.com/sitemap1.xml.gz',
90 lastmod => '2010-11-26',
91 );
92  
93 XML output:
94  
95 <?xml version="1.0" encoding="UTF-8"?>
96 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
97 <sitemap>
98 <loc>http://mywebsite.com/sitemap1.xml.gz</loc>
99 <lastmod>2010-11-26</lastmod>
100 </sitemap>
101 </sitemapindex>
102  
103 =head1 DESCRIPTION
104  
105 WWW::SitemapIndex::XML::Sitemap represents single sitemap entry in sitemaps index file.
106  
107 Class implements L<WWW::SitemapIndex::XML::Sitemap::Interface>.
108  
109 =head1 ATTRIBUTES
110  
111 =head2 loc
112  
113 URL of the sitemap.
114  
115 isa: L<WWW::Sitemap::XML::Types/"Location">
116  
117 Required.
118  
119 =head2 lastmod
120  
121 The date of last modification of the sitemap.
122  
123 isa: L<MooseX::Types::DateTime::W3C/"DateTimeW3C">
124  
125 Optional.
126  
127 =head1 METHODS
128  
129 =head2 as_xml
130  
131 Returns L<XML::LibXML::Element> object representing the C<E<lt>sitemapE<gt>>
132 entry in the sitemaps index.
133  
134 =head1 SEE ALSO
135  
136 L<http://www.sitemaps.org/protocol.php>
137  
138 =head1 AUTHOR
139  
140 Alex J. G. Burzyński <ajgb@cpan.org>
141  
142 =head1 COPYRIGHT AND LICENSE
143  
144 This software is copyright (c) 2014 by Alex J. G. Burzyński <ajgb@cpan.org>.
145  
146 This is free software; you can redistribute it and/or modify it under
147 the same terms as the Perl 5 programming language system itself.
148  
149 =cut
« blib/lib/WWW/Sitemap/XML/Types.pm ↑ Summary blib/lib/WWW/SitemapIndex/XML.pm »