]>
Dogcows Code - chaz/p5-Catalyst-Plugin-Sitemap/blob - lib/Catalyst/Plugin/Sitemap.pm
1 package Catalyst
::Plugin
::Sitemap
;
3 $Catalyst::Plugin
::Sitemap
::VERSION
= '0.0.1';
5 # ABSTRACT: Sitemap support for Catalyst.
13 no warnings qw
/uninitialized/;
16 use List
::Util qw
/ first /;
21 my $sitemap = Search
::Sitemap-
>new;
24 for my $controller ( $self->controller(qr//) ) {
26 for my $a ( $controller->get_action_methods ) {
28 my $action = $controller->action_for( $a->name );
30 my $attr = $action->attributes->{Sitemap
} or next ACTION
;
32 die "more than one attribute 'Sitemap' for sub ",
33 $a->fully_qualified_name
36 my @attr = split /\s*(?:,|=>)\s*/, $attr->[0];
41 if ( $attr[0] eq '*' ) {
42 my $sitemap_method = $action->name . "_sitemap";
44 if ( $controller->can($sitemap_method) ) {
45 $controller->$sitemap_method( $self, $sitemap );
50 if ( $attr[0] + 0 > 0 ) {
52 $uri_params{priority
} = $attr[0];
60 $uri_params{loc
} = $self->uri_for_action( $action->private_path );
62 $sitemap->add( \
%uri_params );
80 Catalyst::Plugin::Sitemap - Sitemap support for Catalyst.
90 use Catalyst qw/ Sitemap /;
94 sub alone :Local :Sitemap {
98 sub with_priority :Local :Sitemap(0.75) {
103 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
107 sub with_function :Local :Sitemap(*) {
111 sub with_function_sitemap {
112 $_[2]->add( 'http://localhost/with_function' );
117 sub sitemap : Path('/sitemap') {
118 my ( $self, $c ) = @_;
120 $c->res->body( $c->sitemap->xml );
125 L<Catalyst::Plugin::Sitemap> provides a way to semi-automate the creation
126 of the sitemap of a Catalyst application.
128 =head1 CONTEXT METHOD
132 Returns a L<Search::Sitemap> object. The sitemap object is populated by
133 inspecting the controllers of the application for actions with the
134 sub attribute C<:Sitemap>.
136 =head1 C<:Sitemap> Subroutine Attribute
138 The sitemap is populated by actions ear-marked with the <:Sitemap> sub
139 attribute. It can be invoked in different ways:
145 sub alone :Local :Sitemap {
149 Adds the url of the action to the sitemap.
151 If the action does not
152 resolves in a single url, this will results in an error.
154 =item C<:Sitemap($priority)>
156 sub with_priority :Local :Sitemap(0.9) {
160 Adds the url, with the given number, which has to be between 1 (inclusive)
161 and 0 (exclusive), as its priority.
163 If the action does not
164 resolves in a single url, this will results in an error.
166 =item C<:Sitemap( %attributes )>
169 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
173 Adds the url with the given entry attributes (as defined by C<Search::Sitemap>).
175 If the action does not
176 resolves in a single url, this will results in an error.
180 sub with_function :Local :Sitemap(*) { }
182 sub with_function_sitemap {
183 my ( $self, $c, $sitemap ) = @_;
185 $sitemap->add( 'http://localhost/with_function' );
188 Calls the function 'I<action>_sitemap', if it exists, and passes it the
189 controller, context and sitemap objects.
191 This is currently the only way to invoke C<:Sitemap> on an action
192 resolving to many urls.
196 =head1 BUGS AND LIMITATIONS
198 Currently, each invocation of the method C<sitemap()> will
199 re-generate the C<Search::Sitemap> object. A future version
200 of this module might offer a way to only compute the sitemap
207 =item L<Search::Sitemap>
209 =item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap
215 Yanick Champoux <yanick@babyl.dyndns.org>
217 =head1 COPYRIGHT AND LICENSE
219 This software is copyright (c) 2010 by Yanick Champoux.
221 This is free software; you can redistribute it and/or modify it under
222 the same terms as the Perl 5 programming language system itself.
This page took 0.044563 seconds and 5 git commands to generate.