]> Dogcows Code - chaz/p5-Catalyst-Plugin-Sitemap/commitdiff
change for WWW::Sitemap::XML
authorYanick Champoux <yanick@babyl.dyndns.org>
Wed, 1 Dec 2010 02:37:14 +0000 (21:37 -0500)
committerYanick Champoux <yanick@babyl.dyndns.org>
Wed, 1 Dec 2010 02:40:48 +0000 (21:40 -0500)
.gitignore
Changes
dist.ini
lib/Catalyst/Plugin/Sitemap.pm
t/lib/TestApp/Controller/Root.pm
t/sitemap.t

index 5ecf87140874fb29e8cab496b7f65637f59cdcaa..17a672af2e997860147ed9480658262603c20fcb 100644 (file)
@@ -1 +1,2 @@
 Catalyst-Plugin-Sitemap*
+.build
diff --git a/Changes b/Changes
index b54c2c76d2edf7bd26dd2452f6424918c1540e14..fca072f5c7ea2573f7c947050da148e405c0c34e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for Catalyst-Plugin-Sitemap
 
 {{$NEXT}}
+    - Change sitemap object under the hood to WWW::Sitemap::XML.
     - Add Dancer::Plugin::SiteMap in the 'SEE ALSO' section.
 
 0.0.1     2010-09-29 20:19:12 America/Montreal
index 463aed9801b61b66ea4dcbaf51c6525307a0db72..68bba3b6eba67da13f797f2e54d94b57deef9bb9 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -4,7 +4,7 @@ license = Perl_5
 copyright_holder = Yanick Champoux
 copyright_year   = 2010
 
-version = 0.0.1
+version = 1.0.0
 
 [ModuleBuild]
 
index cb579820480b1c9074115dc33ea92c83ecf21991..e4a906c981ce501e9753b2cb31e14bbaaa01ec46 100644 (file)
@@ -1,4 +1,5 @@
 package Catalyst::Plugin::Sitemap;
+
 # ABSTRACT: Sitemap support for Catalyst.
 
 =head1 SYNOPSIS
@@ -35,7 +36,7 @@ package Catalyst::Plugin::Sitemap;
     sub sitemap : Path('/sitemap') {
         my ( $self, $c ) = @_;
  
-        $c->res->body( $c->sitemap->as_xml->sprint );
+        $c->res->body( $c->sitemap_as_xml );
     }
 
 =head1 DESCRIPTION
@@ -47,10 +48,14 @@ of the sitemap of a Catalyst application.
 
 =head2 sitemap()
 
-Returns a L<WWW::Search::XML> 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
@@ -90,7 +95,7 @@ resolves in a single url, this will results in an error.
     }
 
 Adds the url with the given entry attributes (as defined by
-L<WWW::Search::XML::URL>).
+L<WWW::Sitemap::XML::URL>).
 
 If the action does not
 resolves in a single url, this will results in an error.
@@ -114,21 +119,18 @@ resolving to many urls.
 =back
 
 
-=head1 BUGS AND LIMITATIONS
-
-Currently, each invocation of the method C<sitemap()> will 
-re-generate the C<WWW::Sitemap::XML> 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> uses under the hood.
+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>
 
@@ -153,12 +155,23 @@ no warnings qw/uninitialized/;
 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 = 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 ) {
 
@@ -185,6 +198,7 @@ sub sitemap {
                 }
 
                 if ( $attr[0] + 0 > 0 ) {
+
                     # it's a number
                     $uri_params{priority} = $attr[0];
                 }
@@ -196,9 +210,7 @@ sub sitemap {
 
             $uri_params{loc} = $self->uri_for_action( $action->private_path );
 
-            $sitemap->add( \%uri_params );
-
-            next ACTION;
+            $sitemap->add(%uri_params);
         }
 
     }
index 4852ee18ab82b511b82dc028075442a8e3fee0b6..34aa0be522c5de11b55e88e752b370f5971f0016 100644 (file)
@@ -7,8 +7,15 @@ use parent 'Catalyst::Controller';
 
 sub sitemap : Path('/sitemap') {
     my ( $self, $c ) = @_;
+    $c->res->body( $c->sitemap_as_xml );
+}
+
+sub dynamic :Path('/dynamic') {
+    my ( $self, $c ) = @_;
+
+    $c->sitemap->add( "http://localhost/sumfin" ); #''.$c->uri_for( '/sumfin' ) );
 
-    $c->res->body( $c->sitemap->as_xml->sprint );
+    $c->res->body( 'dynamic it is' );
 }
 
 sub alone :Local :Sitemap { }
index 10f3efe86b0d61e8c53e2a57e0f4a1f1082b2626..27804983cdc79f3f0db2b9122cf4075a8c2c4a14 100644 (file)
@@ -5,12 +5,11 @@ use warnings;
 use Test::More tests => 4;    # last test to print
 
 use lib 't/lib';
-
 use Catalyst::Test 'TestApp';
 
-my $xml = request('/sitemap')->content;
+my $xml = get('/sitemap');
 
-diag $xml;
+note $xml;
 
 $xml =~ s/\s+//g;
 
This page took 0.02471 seconds and 4 git commands to generate.