]>
Dogcows Code - chaz/p5-Catalyst-Plugin-Sitemap/blob - lib/Catalyst/Plugin/Sitemap.pm
1 package Catalyst
::Plugin
::Sitemap
;
2 # ABSTRACT: Sitemap support for Catalyst.
8 use Catalyst qw/ Sitemap /;
12 sub alone :Local :Sitemap {
16 sub with_priority :Local :Sitemap(0.75) {
21 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
25 sub with_function :Local :Sitemap(*) {
29 sub with_function_sitemap {
30 $_[2]->add( 'http://localhost/with_function' );
35 sub sitemap : Path('/sitemap') {
36 my ( $self, $c ) = @_;
38 $c->res->body( $c->sitemap->xml );
43 L<Catalyst::Plugin::Sitemap> provides a way to semi-automate the creation
44 of the sitemap of a Catalyst application.
50 Returns a L<Search::Sitemap> object. The sitemap object is populated by
51 inspecting the controllers of the application for actions with the
52 sub attribute C<:Sitemap>.
54 =head1 C<:Sitemap> Subroutine Attribute
56 The sitemap is populated by actions ear-marked with the <:Sitemap> sub
57 attribute. It can be invoked in different ways:
63 sub alone :Local :Sitemap {
67 Adds the url of the action to the sitemap.
69 If the action does not
70 resolves in a single url, this will results in an error.
72 =item C<:Sitemap($priority)>
75 sub with_priority :Local :Sitemap(0.9) {
79 Adds the url, with the given number, which has to be between 1 (inclusive)
80 and 0 (exclusive), as its priority.
82 If the action does not
83 resolves in a single url, this will results in an error.
85 =item C<:Sitemap( %attributes )>
88 :Sitemap( lastmod => 2010-09-27, changefreq => daily ) {
92 Adds the url with the given entry attributes (as defined by C<Search::Sitemap>).
94 If the action does not
95 resolves in a single url, this will results in an error.
99 sub with_function :Local :Sitemap(*) { }
101 sub with_function_sitemap {
102 my ( $self, $c, $sitemap ) = @_;
104 $sitemap->add( 'http://localhost/with_function' );
107 Calls the function 'I<action>_sitemap', if it exists, and passes it the
108 controller, context and sitemap objects.
110 This is currently the only way to invoke C<:Sitemap> on an action
111 resolving to many urls.
116 =head1 BUGS AND LIMITATIONS
118 Currently, each invocation of the method C<sitemap()> will
119 re-generate the C<Search::Sitemap> object. A future version
120 of this module might offer a way to only compute the sitemap
128 =item L<Search::Sitemap>
130 Module that C<Catalyst::Plugin::Sitemap> uses under the hood.
132 =item L<Dancer::Plugin::SiteMap>
134 Similar plugin for the L<Dancer> framework, which inspired
135 C<Catalyst::Plugin::Sitemap>.
137 =item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap
139 Blog article introducing C<Catalyst::Plugin::Sitemap>.
150 no warnings qw
/uninitialized/;
153 use List
::Util qw
/ first /;
158 my $sitemap = Search
::Sitemap-
>new;
161 for my $controller ( $self->controller(qr//) ) {
163 for my $a ( $controller->get_action_methods ) {
165 my $action = $controller->action_for( $a->name );
167 my $attr = $action->attributes->{Sitemap
} or next ACTION
;
169 die "more than one attribute 'Sitemap' for sub ",
170 $a->fully_qualified_name
173 my @attr = split /\s*(?:,|=>)\s*/, $attr->[0];
178 if ( $attr[0] eq '*' ) {
179 my $sitemap_method = $action->name . "_sitemap";
181 if ( $controller->can($sitemap_method) ) {
182 $controller->$sitemap_method( $self, $sitemap );
187 if ( $attr[0] + 0 > 0 ) {
189 $uri_params{priority
} = $attr[0];
193 elsif ( @attr > 0 ) {
197 $uri_params{loc
} = $self->uri_for_action( $action->private_path );
199 $sitemap->add( \
%uri_params );
This page took 0.045344 seconds and 5 git commands to generate.