use strict;
use warnings;
package WWW::SitemapIndex::XML::Sitemap;
BEGIN {
$WWW::SitemapIndex::XML::Sitemap::AUTHORITY = 'cpan:AJGB';
}
{
$WWW::SitemapIndex::XML::Sitemap::VERSION = '1.121160';
}
#ABSTRACT: XML Sitemap index sitemap entry
use Moose;
use WWW::Sitemap::XML::Types qw( Location );
use MooseX::Types::DateTime::W3C qw( DateTimeW3C );
use XML::LibXML;
has 'loc' => (
is => 'rw',
isa => Location,
required => 1,
coerce => 1,
predicate => 'has_loc',
);
has 'lastmod' => (
is => 'rw',
isa => DateTimeW3C,
required => 0,
coerce => 1,
predicate => 'has_lastmod',
);
sub as_xml {
my $self = shift;
my $sitemap = XML::LibXML::Element->new('sitemap');
do {
my $name = $_;
my $e = XML::LibXML::Element->new($name);
$e->appendText( $self->$name );
$sitemap->appendChild( $e );
} for 'loc',grep {
eval('$self->has_'.$_) || defined $self->$_()
} qw( lastmod );
return $sitemap;
}
around BUILDARGS => sub {
my $next = shift;
my $class = shift;
if ( @_ == 1 && ! ref $_[0] ) {
return $class->$next(loc => $_[0]);
}
return $class->$next( @_ );
};
with 'WWW::SitemapIndex::XML::Sitemap::Interface';
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding utf-8
=head1 NAME
WWW::SitemapIndex::XML::Sitemap - XML Sitemap index sitemap entry
=head1 VERSION
version 1.121160
=head1 SYNOPSIS
my $sitemap = WWW::SitemapIndex::XML::Sitemap->new(
loc => 'http://mywebsite.com/sitemap1.xml.gz',
lastmod => '2010-11-26',
);
XML sample:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://mywebsite.com/sitemap1.xml.gz</loc>
<lastmod>2010-11-26</lastmod>
</sitemap>
</sitemapindex>
=head1 DESCRIPTION
WWW::SitemapIndex::XML::Sitemap represents single sitemap entry in sitemap
index file.
Class implements L<WWW::SitemapIndex::XML::Sitemap::Interface>.
=head1 ATTRIBUTES
=head2 loc
$url->loc('http://mywebsite.com/sitemap1.xml.gz')
URL of the sitemap.
isa: L<WWW::Sitemap::XML::Types/"Location">
Required.
=head2 lastmod
The date of last modification of the sitemap.
isa: L<MooseX::Types::DateTime::W3C/"DateTimeW3C">
Optional.
=head1 METHODS
=head2 as_xml
Returns L<XML::LibXML::Element> object representing the C<E<lt>sitemapE<gt>>
entry in the sitemap.
=head1 SEE ALSO
Please see those modules/websites for more information related to this module.
=over 4
=item *
L<WWW::Sitemap::XML|WWW::Sitemap::XML>
=item *
L<http://www.sitemaps.org/protocol.php>
=back
=head1 AUTHOR
Alex J. G. Burzyński <ajgb@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Alex J. G. Burzyński <ajgb@cpan.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut