File Coverage

blib/lib/WWW/SitemapIndex/XML/Sitemap.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1 1     1   99427 use strict;
  1         3  
  1         127  
2 1     1   7 use warnings;
  1         2  
  1         68  
3             package WWW::SitemapIndex::XML::Sitemap;
4             BEGIN {
5 1     1   41 $WWW::SitemapIndex::XML::Sitemap::AUTHORITY = 'cpan:AJGB';
6             }
7             {
8             $WWW::SitemapIndex::XML::Sitemap::VERSION = '1.121160';
9             }
10             #ABSTRACT: XML Sitemap index sitemap entry
11              
12 1     1   517 use Moose;
  0            
  0            
13             use WWW::Sitemap::XML::Types qw( Location );
14             use MooseX::Types::DateTime::W3C qw( DateTimeW3C );
15             use XML::LibXML;
16              
17              
18              
19             has 'loc' => (
20             is => 'rw',
21             isa => Location,
22             required => 1,
23             coerce => 1,
24             predicate => 'has_loc',
25             );
26              
27              
28             has 'lastmod' => (
29             is => 'rw',
30             isa => DateTimeW3C,
31             required => 0,
32             coerce => 1,
33             predicate => 'has_lastmod',
34             );
35              
36              
37             sub as_xml {
38             my $self = shift;
39              
40             my $sitemap = XML::LibXML::Element->new('sitemap');
41              
42             do {
43             my $name = $_;
44             my $e = XML::LibXML::Element->new($name);
45              
46             $e->appendText( $self->$name );
47              
48             $sitemap->appendChild( $e );
49              
50             } for 'loc',grep {
51             eval('$self->has_'.$_) || defined $self->$_()
52             } qw( lastmod );
53              
54              
55             return $sitemap;
56             }
57              
58             around BUILDARGS => sub {
59             my $next = shift;
60             my $class = shift;
61              
62             if ( @_ == 1 && ! ref $_[0] ) {
63             return $class->$next(loc => $_[0]);
64             }
65             return $class->$next( @_ );
66             };
67              
68             with 'WWW::SitemapIndex::XML::Sitemap::Interface';
69              
70              
71             __PACKAGE__->meta->make_immutable;
72              
73             1;
74              
75              
76             __END__
77             =pod
78              
79             =encoding utf-8
80              
81             =head1 NAME
82              
83             WWW::SitemapIndex::XML::Sitemap - XML Sitemap index sitemap entry
84              
85             =head1 VERSION
86              
87             version 1.121160
88              
89             =head1 SYNOPSIS
90              
91             my $sitemap = WWW::SitemapIndex::XML::Sitemap->new(
92             loc => 'http://mywebsite.com/sitemap1.xml.gz',
93             lastmod => '2010-11-26',
94             );
95              
96             XML sample:
97              
98             <?xml version="1.0" encoding="UTF-8"?>
99             <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
100             <sitemap>
101             <loc>http://mywebsite.com/sitemap1.xml.gz</loc>
102             <lastmod>2010-11-26</lastmod>
103             </sitemap>
104             </sitemapindex>
105              
106             =head1 DESCRIPTION
107              
108             WWW::SitemapIndex::XML::Sitemap represents single sitemap entry in sitemap
109             index file.
110              
111             Class implements L<WWW::SitemapIndex::XML::Sitemap::Interface>.
112              
113             =head1 ATTRIBUTES
114              
115             =head2 loc
116              
117             $url->loc('http://mywebsite.com/sitemap1.xml.gz')
118              
119             URL of the sitemap.
120              
121             isa: L<WWW::Sitemap::XML::Types/"Location">
122              
123             Required.
124              
125             =head2 lastmod
126              
127             The date of last modification of the sitemap.
128              
129             isa: L<MooseX::Types::DateTime::W3C/"DateTimeW3C">
130              
131             Optional.
132              
133             =head1 METHODS
134              
135             =head2 as_xml
136              
137             Returns L<XML::LibXML::Element> object representing the C<E<lt>sitemapE<gt>>
138             entry in the sitemap.
139              
140             =head1 SEE ALSO
141              
142             Please see those modules/websites for more information related to this module.
143              
144             =over 4
145              
146             =item *
147              
148             L<WWW::Sitemap::XML|WWW::Sitemap::XML>
149              
150             =item *
151              
152             L<http://www.sitemaps.org/protocol.php>
153              
154             =back
155              
156             =head1 AUTHOR
157              
158             Alex J. G. BurzyÅ„ski <ajgb@cpan.org>
159              
160             =head1 COPYRIGHT AND LICENSE
161              
162             This software is copyright (c) 2010 by Alex J. G. BurzyÅ„ski <ajgb@cpan.org>.
163              
164             This is free software; you can redistribute it and/or modify it under
165             the same terms as the Perl 5 programming language system itself.
166              
167             =cut
168