]>
Dogcows Code - chaz/p5-Catalyst-Plugin-Sitemap/blob - lib/Catalyst/Plugin/Sitemap.pm
1 package Catalyst
::Plugin
::Sitemap
;
3 # ABSTRACT: Sitemap support for Catalyst.
9 use Catalyst qw/ Sitemap /;
13 sub alone :Local :Sitemap {
17 sub with_priority :Local :Sitemap(0.75) {
22 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
26 sub with_function :Local :Sitemap(*) {
30 sub with_function_sitemap {
31 $_[2]->add( 'http://localhost/with_function' );
36 sub sitemap : Path('/sitemap') {
37 my ( $self, $c ) = @_;
39 $c->res->body( $c->sitemap_as_xml );
44 L<Catalyst::Plugin::Sitemap> provides a way to semi-automate the creation
45 of the sitemap of a Catalyst application.
51 Returns a L<WWW::Sitemap::XML> object. The sitemap object is populated by
52 inspecting the controllers of the application for actions with the
53 sub attribute C<:Sitemap>.
55 =head2 sitemap_as_xml()
57 Returns the sitemap as a string containing its XML representation.
59 =head1 C<:Sitemap> Subroutine Attribute
61 The sitemap is populated by actions ear-marked with the <:Sitemap> sub
62 attribute. It can be invoked in different ways:
68 sub alone :Local :Sitemap {
72 Adds the url of the action to the sitemap.
74 If the action does not
75 resolves in a single url, this will results in an error.
77 =item C<:Sitemap($priority)>
80 sub with_priority :Local :Sitemap(0.9) {
84 Adds the url, with the given number, which has to be between 1 (inclusive)
85 and 0 (exclusive), as its priority.
87 If the action does not
88 resolves in a single url, this will results in an error.
90 =item C<:Sitemap( %attributes )>
93 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
97 Adds the url with the given entry attributes (as defined by
98 L<WWW::Sitemap::XML::URL>).
100 If the action does not
101 resolves in a single url, this will results in an error.
105 sub with_function :Local :Sitemap(*) { }
107 sub with_function_sitemap {
108 my ( $self, $c, $sitemap ) = @_;
110 $sitemap->add( 'http://localhost/with_function' );
113 Calls the function 'I<action>_sitemap', if it exists, and passes it the
114 controller, context and sitemap objects.
116 This is currently the only way to invoke C<:Sitemap> on an action
117 resolving to many urls.
126 =item L<WWW::Sitemap::XML>
128 Module that C<Catalyst::Plugin::Sitemap> currently uses under the hood.
130 =item L<Search::Sitemap>
132 Original module that this plugin was using under the hood.
135 =item L<Dancer::Plugin::SiteMap>
137 Similar plugin for the L<Dancer> framework, which inspired
138 C<Catalyst::Plugin::Sitemap>.
140 =item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap
142 Blog article introducing C<Catalyst::Plugin::Sitemap>.
153 no warnings qw
/uninitialized/;
155 use WWW
::Sitemap
::XML
;
156 use List
::Util qw
/ first /;
160 builder
=> '_build_sitemap',
166 return $self->sitemap->as_xml->toString;
172 my $sitemap = WWW
::Sitemap
::XML-
>new;
174 for my $controller ( map { $self->controller($_) } $self->controllers ) {
176 for my $a ( $controller->get_action_methods ) {
178 my $action = $controller->action_for( $a->name );
180 my $attr = $action->attributes->{Sitemap
} or next ACTION
;
182 die "more than one attribute 'Sitemap' for sub ",
183 $a->fully_qualified_name
186 my @attr = split /\s*(?:,|=>)\s*/, $attr->[0];
191 if ( $attr[0] eq '*' ) {
192 my $sitemap_method = $action->name . "_sitemap";
194 if ( $controller->can($sitemap_method) ) {
195 $controller->$sitemap_method( $self, $sitemap );
200 if ( $attr[0] + 0 > 0 ) {
203 $uri_params{priority
} = $attr[0];
207 elsif ( @attr > 0 ) {
211 $uri_params{loc
} = $self->uri_for_action( $action->private_path );
213 $sitemap->add(%uri_params);
This page took 0.04701 seconds and 5 git commands to generate.