X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FSitemap.pm;h=e4a906c981ce501e9753b2cb31e14bbaaa01ec46;hb=4df0ebafa22f06945061356e033a570c3875c737;hp=7f1aee2977d83a1b3e2cbb062e6e4ef1e0cae5c3;hpb=dabe3c9f7123b592f6c1e056a9e2df034610b71a;p=chaz%2Fp5-Catalyst-Plugin-Sitemap diff --git a/lib/Catalyst/Plugin/Sitemap.pm b/lib/Catalyst/Plugin/Sitemap.pm index 7f1aee2..e4a906c 100644 --- a/lib/Catalyst/Plugin/Sitemap.pm +++ b/lib/Catalyst/Plugin/Sitemap.pm @@ -1,4 +1,5 @@ package Catalyst::Plugin::Sitemap; + # ABSTRACT: Sitemap support for Catalyst. =head1 SYNOPSIS @@ -35,7 +36,7 @@ package Catalyst::Plugin::Sitemap; sub sitemap : Path('/sitemap') { my ( $self, $c ) = @_; - $c->res->body( $c->sitemap->xml ); + $c->res->body( $c->sitemap_as_xml ); } =head1 DESCRIPTION @@ -47,10 +48,14 @@ of the sitemap of a Catalyst application. =head2 sitemap() -Returns a L object. The sitemap object is populated by +Returns a L object. The sitemap object is populated by inspecting the controllers of the application for actions with the sub attribute C<:Sitemap>. +=head2 sitemap_as_xml() + +Returns the sitemap as a string containing its XML representation. + =head1 C<:Sitemap> Subroutine Attribute The sitemap is populated by actions ear-marked with the <:Sitemap> sub @@ -89,7 +94,8 @@ resolves in a single url, this will results in an error. ... } -Adds the url with the given entry attributes (as defined by C). +Adds the url with the given entry attributes (as defined by +L). If the action does not resolves in a single url, this will results in an error. @@ -113,21 +119,18 @@ resolving to many urls. =back -=head1 BUGS AND LIMITATIONS - -Currently, each invocation of the method C will -re-generate the C object. A future version -of this module might offer a way to only compute the sitemap -once. - - =head1 SEE ALSO =over +=item L + +Module that C currently uses under the hood. + =item L -Module that C uses under the hood. +Original module that this plugin was using under the hood. + =item L @@ -149,16 +152,26 @@ use Moose::Role; no warnings qw/uninitialized/; -use Search::Sitemap; +use WWW::Sitemap::XML; use List::Util qw/ first /; -sub sitemap { +has sitemap => ( + is => 'ro', + builder => '_build_sitemap', + lazy => 1, +); + +sub sitemap_as_xml { my $self = shift; + return $self->sitemap->as_xml->toString; +} - my $sitemap = Search::Sitemap->new; - $sitemap->pretty(1); +sub _build_sitemap { + my $self = shift; - for my $controller ( $self->controller(qr//) ) { + my $sitemap = WWW::Sitemap::XML->new; + + for my $controller ( map { $self->controller($_) } $self->controllers ) { ACTION: for my $a ( $controller->get_action_methods ) { @@ -185,6 +198,7 @@ sub sitemap { } if ( $attr[0] + 0 > 0 ) { + # it's a number $uri_params{priority} = $attr[0]; } @@ -196,9 +210,7 @@ sub sitemap { $uri_params{loc} = $self->uri_for_action( $action->private_path ); - $sitemap->add( \%uri_params ); - - next ACTION; + $sitemap->add(%uri_params); } }