Search-Sitemap
view release on metacpan or search on metacpan
lib/Search/Sitemap.pm view on Meta::CPAN
my $loc = $data->{ 'loc' } or croak "Can't call ->update without 'loc'";
if ( my $obj = $self->get_url( $loc ) ) {
for my $key ( keys %{ $data } ) {
next if $key eq 'loc';
$obj->$key( $data->{ $key } );
}
return $obj;
} else {
my $obj = Search::Sitemap::URL->new( $data );
$self->put_url( $obj );
return $obj;
}
}
sub add {
my $self = shift;
my @urls = ();
if ( ref $_[0] ) {
push( @urls, map { to_SitemapURL( $_ ) } @_ );
} elsif ( $_[0] =~ m{://} ) {
push( @urls, map { Search::Sitemap::URL->new( loc => $_ ) } @_ );
} else {
push( @urls, Search::Sitemap::URL->new( @_ ) );
}
$self->put_urls( @urls );
return ( @urls == 1 ) ? $urls[0] : wantarray ? @urls : \@urls;
}
__PACKAGE__->meta->make_immutable;
1;
__END__
=encoding utf-8
=head1 NAME
Search::Sitemap - Perl extension for managing Search Engine Sitemaps
=head1 SYNOPSIS
use Search::Sitemap;
my $map = Search::Sitemap->new();
$map->read( 'sitemap.gz' );
# Main page, changes a lot because of the blog
$map->add( Search::Sitemap::URL->new(
loc => 'http://www.jasonkohles.com/',
lastmod => '2005-06-03',
changefreq => 'daily',
priority => 1.0,
) );
# Top level directories, don't change as much, and have a lower priority
$map->add( {
loc => "http://www.jasonkohles.com/$_/",
changefreq => 'weekly',
priority => 0.9, # lower priority than the home page
} ) for qw(
software gpg hamradio photos scuba snippets tools
);
$map->write( 'sitemap.gz' );
=head1 DESCRIPTION
The Sitemap Protocol allows you to inform search engine crawlers about URLs
on your Web sites that are available for crawling. A Sitemap consists of a
list of URLs and may also contain additional information about those URLs,
such as when they were last modified, how frequently they change, etc.
This module allows you to create and modify sitemaps.
=head1 METHODS
=head2 new()
Creates a new Search::Sitemap object.
my $map = Search::Sitemap->new();
=head2 read( $file )
Read a sitemap in to this object. Reading of compressed files is done
automatically if the filename ends with .gz.
=head2 write( $file )
Write the sitemap out to a file. Writing of compressed files is done
automatically if the filename ends with .gz.
=head2 urls()
Return the L<Search::Sitemap::URLStore> object that make up the sitemap.
To get all urls (L<Search::Sitemap::URL> objects) please use:
my @urls = $map->urls->all;
=head2 add( $item, [$item...] )
Add the L<Search::Sitemap::URL> items listed to the sitemap.
If you pass hashrefs instead of objects, it will turn them into objects for
you. If the first item you pass is a simple scalar that matches \w, it will
assume that the values passed are a hash for a single object. If the first
item passed matches m{^\w+://} (i.e. it looks like a URL) then all the
arguments will be treated as URLs, and L<Search::Sitemap::URL> objects will be
constructed for them, but only the loc field will be populated.
This means you can do any of these:
# create the Search::Sitemap::URL object yourself
my $url = Search::Sitemap::URL->new(
loc => 'http://www.jasonkohles.com/',
priority => 1.0,
);
$map->add($url);
# or
( run in 1.201 second using v1.01-cache-2.11-cpan-df04353d9ac )