]>
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 if ( $self->can('uri_disposition') ) {
36 $self->uri_disposition('absolute');
39 for my $controller ( map { $self->controller($_) } $self->controllers ) {
41 for my $a ( $controller->get_action_methods ) {
43 my $action = $controller->action_for( $a->name );
45 my $attr = $action->attributes->{Sitemap
} or next ACTION
;
47 die "more than one attribute 'Sitemap' for sub ",
48 $a->fully_qualified_name
51 my @attr = split /\s*(?:,|=>)\s*/, $attr->[0];
56 if ( $attr[0] eq '*' ) {
57 my $sitemap_method = $action->name . "_sitemap";
59 if ( $controller->can($sitemap_method) ) {
60 $controller->$sitemap_method( $self, $sitemap );
65 if ( $attr[0] + 0 > 0 ) {
68 $uri_params{priority
} = $attr[0];
76 $uri_params{loc
} = ''.$self->uri_for_action( $action->private_path );
78 $sitemap->add(%uri_params);
94 Catalyst::Plugin::Sitemap - Sitemap support for Catalyst.
104 use Catalyst qw/ Sitemap /;
108 sub alone :Local :Sitemap {
112 sub with_priority :Local :Sitemap(0.75) {
117 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
121 sub with_function :Local :Sitemap(*) {
125 sub with_function_sitemap {
126 $_[2]->add( 'http://localhost/with_function' );
131 sub sitemap : Path('/sitemap') {
132 my ( $self, $c ) = @_;
134 $c->res->body( $c->sitemap_as_xml );
139 L<Catalyst::Plugin::Sitemap> provides a way to semi-automate the creation
140 of the sitemap of a Catalyst application.
142 =head1 CONTEXT METHOD
146 Returns a L<WWW::Sitemap::XML> object. The sitemap object is populated by
147 inspecting the controllers of the application for actions with the
148 sub attribute C<:Sitemap>.
150 =head2 sitemap_as_xml()
152 Returns the sitemap as a string containing its XML representation.
154 =head1 C<:Sitemap> Subroutine Attribute
156 The sitemap is populated by actions ear-marked with the <:Sitemap> sub
157 attribute. It can be invoked in different ways:
163 sub alone :Local :Sitemap {
167 Adds the url of the action to the sitemap.
169 If the action does not
170 resolves in a single url, this will results in an error.
172 =item C<:Sitemap($priority)>
174 sub with_priority :Local :Sitemap(0.9) {
178 Adds the url, with the given number, which has to be between 1 (inclusive)
179 and 0 (exclusive), as its priority.
181 If the action does not
182 resolves in a single url, this will results in an error.
184 =item C<:Sitemap( %attributes )>
187 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
191 Adds the url with the given entry attributes (as defined by
192 L<WWW::Sitemap::XML::URL>).
194 If the action does not
195 resolves in a single url, this will results in an error.
199 sub with_function :Local :Sitemap(*) { }
201 sub with_function_sitemap {
202 my ( $self, $c, $sitemap ) = @_;
204 $sitemap->add( 'http://localhost/with_function' );
207 Calls the function 'I<action>_sitemap', if it exists, and passes it the
208 controller, context and sitemap objects.
210 This is currently the only way to invoke C<:Sitemap> on an action
211 resolving to many urls.
219 =item L<WWW::Sitemap::XML>
221 Module that C<Catalyst::Plugin::Sitemap> currently uses under the hood.
223 =item L<Search::Sitemap>
225 Original module that this plugin was using under the hood.
227 =item L<Dancer::Plugin::SiteMap>
229 Similar plugin for the L<Dancer> framework, which inspired
230 C<Catalyst::Plugin::Sitemap>.
232 =item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap
234 Blog article introducing C<Catalyst::Plugin::Sitemap>.
240 Yanick Champoux <yanick@babyl.dyndns.org>
242 =head1 COPYRIGHT AND LICENSE
244 This software is copyright (c) 2010 by Yanick Champoux.
246 This is free software; you can redistribute it and/or modify it under
247 the same terms as the Perl 5 programming language system itself.
This page took 0.04563 seconds and 5 git commands to generate.