]>
Dogcows Code - chaz/p5-Catalyst-Plugin-Sitemap/blob - lib/Catalyst/Plugin/Sitemap.pm
1 package Catalyst
::Plugin
::Sitemap
;
3 $Catalyst::Plugin
::Sitemap
::VERSION
= '1.0.0';
6 # ABSTRACT: Sitemap support for Catalyst.
14 no warnings qw
/uninitialized/;
16 use WWW
::Sitemap
::XML
;
17 use List
::Util qw
/ first /;
21 builder
=> '_build_sitemap',
27 return $self->sitemap->as_xml->toString;
33 my $sitemap = WWW
::Sitemap
::XML-
>new;
35 for my $controller ( map { $self->controller($_) } $self->controllers ) {
37 for my $a ( $controller->get_action_methods ) {
39 my $action = $controller->action_for( $a->name );
41 my $attr = $action->attributes->{Sitemap
} or next ACTION
;
43 die "more than one attribute 'Sitemap' for sub ",
44 $a->fully_qualified_name
47 my @attr = split /\s*(?:,|=>)\s*/, $attr->[0];
52 if ( $attr[0] eq '*' ) {
53 my $sitemap_method = $action->name . "_sitemap";
55 if ( $controller->can($sitemap_method) ) {
56 $controller->$sitemap_method( $self, $sitemap );
61 if ( $attr[0] + 0 > 0 ) {
64 $uri_params{priority
} = $attr[0];
72 $uri_params{loc
} = $self->uri_for_action( $action->private_path );
74 $sitemap->add(%uri_params);
90 Catalyst::Plugin::Sitemap - Sitemap support for Catalyst.
100 use Catalyst qw/ Sitemap /;
104 sub alone :Local :Sitemap {
108 sub with_priority :Local :Sitemap(0.75) {
113 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
117 sub with_function :Local :Sitemap(*) {
121 sub with_function_sitemap {
122 $_[2]->add( 'http://localhost/with_function' );
127 sub sitemap : Path('/sitemap') {
128 my ( $self, $c ) = @_;
130 $c->res->body( $c->sitemap_as_xml );
135 L<Catalyst::Plugin::Sitemap> provides a way to semi-automate the creation
136 of the sitemap of a Catalyst application.
138 =head1 CONTEXT METHOD
142 Returns a L<WWW::Sitemap::XML> object. The sitemap object is populated by
143 inspecting the controllers of the application for actions with the
144 sub attribute C<:Sitemap>.
146 =head2 sitemap_as_xml()
148 Returns the sitemap as a string containing its XML representation.
150 =head1 C<:Sitemap> Subroutine Attribute
152 The sitemap is populated by actions ear-marked with the <:Sitemap> sub
153 attribute. It can be invoked in different ways:
159 sub alone :Local :Sitemap {
163 Adds the url of the action to the sitemap.
165 If the action does not
166 resolves in a single url, this will results in an error.
168 =item C<:Sitemap($priority)>
170 sub with_priority :Local :Sitemap(0.9) {
174 Adds the url, with the given number, which has to be between 1 (inclusive)
175 and 0 (exclusive), as its priority.
177 If the action does not
178 resolves in a single url, this will results in an error.
180 =item C<:Sitemap( %attributes )>
183 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
187 Adds the url with the given entry attributes (as defined by
188 L<WWW::Sitemap::XML::URL>).
190 If the action does not
191 resolves in a single url, this will results in an error.
195 sub with_function :Local :Sitemap(*) { }
197 sub with_function_sitemap {
198 my ( $self, $c, $sitemap ) = @_;
200 $sitemap->add( 'http://localhost/with_function' );
203 Calls the function 'I<action>_sitemap', if it exists, and passes it the
204 controller, context and sitemap objects.
206 This is currently the only way to invoke C<:Sitemap> on an action
207 resolving to many urls.
215 =item L<WWW::Sitemap::XML>
217 Module that C<Catalyst::Plugin::Sitemap> currently uses under the hood.
219 =item L<Search::Sitemap>
221 Original module that this plugin was using under the hood.
223 =item L<Dancer::Plugin::SiteMap>
225 Similar plugin for the L<Dancer> framework, which inspired
226 C<Catalyst::Plugin::Sitemap>.
228 =item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap
230 Blog article introducing C<Catalyst::Plugin::Sitemap>.
236 Yanick Champoux <yanick@babyl.dyndns.org>
238 =head1 COPYRIGHT AND LICENSE
240 This software is copyright (c) 2010 by Yanick Champoux.
242 This is free software; you can redistribute it and/or modify it under
243 the same terms as the Perl 5 programming language system itself.
This page took 0.052925 seconds and 5 git commands to generate.