[Catalyst-commits] r12381 - in trunk/examples/CatalystAdvent: lib/CatalystAdvent/Controller t

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Dec 15 01:37:34 GMT 2009


Author: t0m
Date: 2009-12-15 01:37:34 +0000 (Tue, 15 Dec 2009)
New Revision: 12381

Modified:
   trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
   trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Root.pm
   trunk/examples/CatalystAdvent/t/01app.t
Log:
Change to chained dispatch throughout

Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2009-12-15 01:28:18 UTC (rev 12380)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2009-12-15 01:37:34 UTC (rev 12381)
@@ -35,7 +35,9 @@
 
 =cut
 
-sub index : Private {
+sub base : Chained('/base') PathPart('') CaptureArgs(0) {}
+
+sub index : Chained('base') PathPart('') Args(0) {
     my ( $self, $c ) = @_;
     opendir DIR, $c->path_to('root') or die "Error opening root: $!";
     my @years = sort grep { /\d{4}/ } readdir DIR;
@@ -51,8 +53,9 @@
 
 =cut
 
-sub year : Regex('^(\d{4})$') {
+sub year : Chained('base') PathPart('') Args(1) {
     my ( $self, $c, $year ) = @_;
+    $c->detach( '/calendar/index' ) unless $year =~ /^\d{4}$/;
     $year ||= $c->req->snippets->[0];
     $c->res->redirect( $c->uri_for('/') )
         unless ( -e $c->path_to( 'root', $year ) );
@@ -68,10 +71,10 @@
 
 =cut
 
-sub day : Regex('^(\d{4})/(\d\d?)$') {
+sub day : Chained('base') PathPart('') Args(2) {
     my ( $self, $c, $year, $day ) = @_;
-    $year ||= $c->req->snippets->[0];
-    $day  ||= $c->req->snippets->[1];
+    $c->detach( '/calendar/index' ) unless $year =~ /^\d{4}$/;
+    $c->detach( '/calendar/index' ) unless $day =~ /^\d{1,2}$/;
 
     $c->detach( 'year', [$year] )
         unless ( -e ( my $file = $c->path_to( 'root', $year, "$day.pod" ) ) );
@@ -107,9 +110,9 @@
 
 =cut
 
-sub rss : Global {
+sub rss : Chained('base') Args() {
     my ( $self, $c, $year ) = @_;
-    $c->forward('feed', [ $year ] );
+    $c->forward('feed', $year );
 }
 
 =head2 feed 
@@ -118,10 +121,10 @@
 
 =cut
 
-sub feed : Global {
+sub feed : Chained('base') Args() {
     my ( $self, $c, $year ) = @_;
+    $c->detach( '/calendar/index' ) unless $year =~ /^\d{4}$/;
     $year ||= $c->stash->{now}->year;
-    $year ||= $c->req->snippets->[0];
     $c->res->redirect( $c->uri_for('/') )
         unless ( -e $c->path_to( 'root', $year ) );
 

Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Root.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Root.pm	2009-12-15 01:28:18 UTC (rev 12380)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Root.pm	2009-12-15 01:37:34 UTC (rev 12381)
@@ -16,14 +16,14 @@
     $c->detach( '/calendar/index' );
 }
 
-=head2 begin
+=head2 base
 
 Simply adds the current date to the stash for some operations needed
 across various methods.
 
 =cut
 
-sub begin : Private {
+sub base : Chained('/') PathPart('') CaptureArgs(0) {
     my( $self, $c )  = @_;
     $c->stash->{now} = DateTime->now();
 }

Modified: trunk/examples/CatalystAdvent/t/01app.t
===================================================================
--- trunk/examples/CatalystAdvent/t/01app.t	2009-12-15 01:28:18 UTC (rev 12380)
+++ trunk/examples/CatalystAdvent/t/01app.t	2009-12-15 01:37:34 UTC (rev 12381)
@@ -7,5 +7,7 @@
 
 ok( request('/rss')->is_success );
 ok( request('/feed')->is_success );
+ok( request('/rss/2008')->is_success );
+ok( request('/feed/2008')->is_success );
 
 done_testing;




More information about the Catalyst-commits mailing list