X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FSitemap.pm;h=4730f200a6f8993a4a827fcc6f57b6be16c09366;hb=d074ab5a56e8e690399d2a01691724fcaf4bc41f;hp=eb6e92bda093e16f5bd7683a2c38323a37b5edd3;hpb=cc84fb8d76fc3e975d2d593c51d4488d530aec6b;p=chaz%2Fp5-Catalyst-Plugin-Sitemap diff --git a/lib/Catalyst/Plugin/Sitemap.pm b/lib/Catalyst/Plugin/Sitemap.pm index eb6e92b..4730f20 100644 --- a/lib/Catalyst/Plugin/Sitemap.pm +++ b/lib/Catalyst/Plugin/Sitemap.pm @@ -1,4 +1,9 @@ package Catalyst::Plugin::Sitemap; +BEGIN { + $Catalyst::Plugin::Sitemap::VERSION = '0.0.1'; +} +# ABSTRACT: Sitemap support for Catalyst. + use strict; use warnings; @@ -61,29 +66,162 @@ sub sitemap { } - return $sitemap->xml; + return $sitemap; } 1; -__END__ -ways I can do it -is Sitemap( ) ? => use it as is -else => has _sitemap? => use it -else => use the uri directly +=pod +=head1 NAME -sitemap => sub { - my ( $self, $c, $sitemap ) = @_; +Catalyst::Plugin::Sitemap - Sitemap support for Catalyst. - ... -}; +=head1 VERSION -sub action_sitemap { - my ( $self, $c, $sitemap ) = @_; -} +version 0.0.1 -sub do_stuff :Local :Sitemap { -} +=head1 SYNOPSIS + + # in MyApp.pm + + use Catalyst qw/ Sitemap /; + + # in the controller + + sub alone :Local :Sitemap { + ... + } + + sub with_priority :Local :Sitemap(0.75) { + ... + } + + sub with_args :Local + :Sitemap( lastmod => 2010-09-27, changefreq => daily ) { + ... + } + + sub with_function :Local :Sitemap(*) { + ... + } + + sub with_function_sitemap { + $_[2]->add( 'http://localhost/with_function' ); + } + + # and then... + + sub sitemap : Path('/sitemap') { + my ( $self, $c ) = @_; + + $c->res->body( $c->sitemap->xml ); + } + +=head1 DESCRIPTION + +L provides a way to semi-automate the creation +of the sitemap of a Catalyst application. + +=head1 CONTEXT METHOD + +=head2 sitemap() + +Returns a L object. The sitemap object is populated by +inspecting the controllers of the application for actions with the +sub attribute C<:Sitemap>. + +=head1 C<:Sitemap> Subroutine Attribute + +The sitemap is populated by actions ear-marked with the <:Sitemap> sub +attribute. It can be invoked in different ways: + +=over + +=item C<:Sitemap> + + sub alone :Local :Sitemap { + ... + } + +Adds the url of the action to the sitemap. + +If the action does not +resolves in a single url, this will results in an error. + +=item C<:Sitemap($priority)> + + sub with_priority :Local :Sitemap(0.9) { + ... + } + +Adds the url, with the given number, which has to be between 1 (inclusive) +and 0 (exclusive), as its priority. + +If the action does not +resolves in a single url, this will results in an error. + +=item C<:Sitemap( %attributes )> + + sub with_args :Local + :Sitemap( lastmod => 2010-09-27, changefreq => daily ) { + ... + } + +Adds the url with the given entry attributes (as defined by C). + +If the action does not +resolves in a single url, this will results in an error. + +=item C<:Sitemap(*)> + + sub with_function :Local :Sitemap(*) { } + + sub with_function_sitemap { + my ( $self, $c, $sitemap ) = @_; + + $sitemap->add( 'http://localhost/with_function' ); + } + +Calls the function 'I_sitemap', if it exists, and passes it the +controller, context and sitemap objects. + +This is currently the only way to invoke C<:Sitemap> on an action +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 + +=item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap + +=back + +=head1 AUTHOR + + Yanick Champoux + +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2010 by Yanick Champoux. + +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 + + +__END__