]> Dogcows Code - chaz/p5-Catalyst-Plugin-Sitemap/blobdiff - lib/Catalyst/Plugin/Sitemap.pm
Build results of 0db120e (on www-sitemap-xml)
[chaz/p5-Catalyst-Plugin-Sitemap] / lib / Catalyst / Plugin / Sitemap.pm
index 4730f200a6f8993a4a827fcc6f57b6be16c09366..7b172711f3807ebe3747a2c7e3768e852f8cd02b 100644 (file)
@@ -1,7 +1,8 @@
 package Catalyst::Plugin::Sitemap;
 BEGIN {
-  $Catalyst::Plugin::Sitemap::VERSION = '0.0.1';
+  $Catalyst::Plugin::Sitemap::VERSION = '1.0.0';
 }
+
 # ABSTRACT: Sitemap support for Catalyst.
 
 
@@ -12,16 +13,26 @@ use Moose::Role;
 
 no warnings qw/uninitialized/;
 
-use Search::Sitemap;
+use WWW::Sitemap::XML;
 use List::Util qw/ first /;
 
-sub sitemap {
+has sitemap => (
+    is      => 'ro',
+    builder => '_build_sitemap',
+    lazy    => 1,
+);
+
+sub sitemap_as_xml {
+    my $self = shift;
+    return $self->sitemap->as_xml->toString;
+}
+
+sub _build_sitemap {
     my $self = shift;
 
-    my $sitemap = Search::Sitemap->new;
-    $sitemap->pretty(1);
+    my $sitemap = WWW::Sitemap::XML->new;
 
-    for my $controller ( $self->controller(qr//) ) {
+    for my $controller ( map { $self->controller($_) } $self->controllers ) {
       ACTION:
         for my $a ( $controller->get_action_methods ) {
 
@@ -48,6 +59,7 @@ sub sitemap {
                 }
 
                 if ( $attr[0] + 0 > 0 ) {
+
                     # it's a number
                     $uri_params{priority} = $attr[0];
                 }
@@ -59,9 +71,7 @@ sub sitemap {
 
             $uri_params{loc} = $self->uri_for_action( $action->private_path );
 
-            $sitemap->add( \%uri_params );
-
-            next ACTION;
+            $sitemap->add(%uri_params);
         }
 
     }
@@ -81,7 +91,7 @@ Catalyst::Plugin::Sitemap - Sitemap support for Catalyst.
 
 =head1 VERSION
 
-version 0.0.1
+version 1.0.0
 
 =head1 SYNOPSIS
 
@@ -117,7 +127,7 @@ version 0.0.1
     sub sitemap : Path('/sitemap') {
         my ( $self, $c ) = @_;
  
-        $c->res->body( $c->sitemap->xml );
+        $c->res->body( $c->sitemap_as_xml );
     }
 
 =head1 DESCRIPTION
@@ -129,10 +139,14 @@ of the sitemap of a Catalyst application.
 
 =head2 sitemap()
 
-Returns a L<Search::Sitemap> object. The sitemap object is populated by 
+Returns a L<WWW::Sitemap::XML> object. The sitemap object is populated by 
 inspecting the controllers of the application for actions with the 
 sub attribute C<:Sitemap>.
 
+=head2 sitemap_as_xml()
+
+Returns the sitemap as a string containing its XML representation.
+
 =head1 C<:Sitemap> Subroutine Attribute
 
 The sitemap is populated by actions ear-marked with the <:Sitemap> sub
@@ -170,7 +184,8 @@ resolves in a single url, this will results in an error.
         ...
     }
 
-Adds the url with the given entry attributes (as defined by C<Search::Sitemap>).
+Adds the url with the given entry attributes (as defined by
+L<WWW::Sitemap::XML::URL>).
 
 If the action does not
 resolves in a single url, this will results in an error.
@@ -193,26 +208,32 @@ resolving to many urls.
 
 =back
 
-=head1 BUGS AND LIMITATIONS
-
-Currently, each invocation of the method C<sitemap()> will 
-re-generate the C<Search::Sitemap> object.  A future version
-of this module might offer a way to only compute the sitemap
-once.
-
 =head1 SEE ALSO
 
 =over
 
+=item L<WWW::Sitemap::XML>
+
+Module that C<Catalyst::Plugin::Sitemap> currently uses under the hood.
+
 =item L<Search::Sitemap>
 
+Original module that this plugin was using under the hood.
+
+=item L<Dancer::Plugin::SiteMap>
+
+Similar plugin for the L<Dancer> framework, which inspired
+C<Catalyst::Plugin::Sitemap>. 
+
 =item http://babyl.dyndns.org/techblog/entry/catalyst-plugin-sitemap
 
+Blog article introducing C<Catalyst::Plugin::Sitemap>.
+
 =back
 
 =head1 AUTHOR
 
-  Yanick Champoux <yanick@babyl.dyndns.org>
+Yanick Champoux <yanick@babyl.dyndns.org>
 
 =head1 COPYRIGHT AND LICENSE
 
This page took 0.025309 seconds and 4 git commands to generate.