[Catalyst-commits] r6301 - in trunk/Catalyst-Controller-PathArgs: MyApp/lib/MyApp/Controller MyApp/lib/MyApp/Controller/Book lib/Catalyst/Controller

zby at dev.catalyst.perl.org zby at dev.catalyst.perl.org
Thu Apr 19 17:59:34 GMT 2007


Author: zby
Date: 2007-04-19 17:59:34 +0100 (Thu, 19 Apr 2007)
New Revision: 6301

Modified:
   trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book.pm
   trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book/Edition.pm
   trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Root.pm
   trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm
Log:
Mixing with PathPart added to example and doc.


Modified: trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book/Edition.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book/Edition.pm	2007-04-19 14:45:41 UTC (rev 6300)
+++ trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book/Edition.pm	2007-04-19 16:59:34 UTC (rev 6301)
@@ -5,10 +5,22 @@
 use warnings;
 
 sub view : PathArgs(0) EndPoint {
-    my ( $self, $c, $id ) = @_;
-    my $text = $c->stash->{edition};
-    $c->res->body( ">$text<" );
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book::Edition controller's chained view action. ";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on the stash. ";
+    $out .= "It's edition with id = " . $c->stash->{edition}->{id} . " is on the stash. ";
+    $out .= 'It\'s text is "' . $c->stash->{edition}->{text} . '" .';
+    $c->response->body( $out );
 }
 
+sub chained_index : PathPart('') PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book::Edition controller's chained index action. ";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on the stash. ";
+    $out .= "It's edition with id = " . $c->stash->{edition}->{id} . " is on the stash.";
+    $c->response->body( $out );
+}
+
+
 1;
 

Modified: trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book.pm	2007-04-19 14:45:41 UTC (rev 6300)
+++ trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book.pm	2007-04-19 16:59:34 UTC (rev 6301)
@@ -10,5 +10,25 @@
     $c->stash->{edition} = $edition;
 }
 
+sub edition_mascarade: PathPart('edition') PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book controller's edition_mascarade action with 0 params.";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on stash";
+    $c->response->body( $out );
+}
+
+sub index : Private {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book controller's index action.";
+    $c->response->body( $out );
+}
+
+sub chained_index : PathPart('') PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book controller's chained index action.";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on stash";
+    $c->response->body( $out );
+}
+
 1;
 

Modified: trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Root.pm	2007-04-19 14:45:41 UTC (rev 6300)
+++ trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Root.pm	2007-04-19 16:59:34 UTC (rev 6301)
@@ -26,28 +26,29 @@
 
 =cut
 
-sub default : Private {
+sub index : Private {
     my ( $self, $c ) = @_;
-
-    # Hello World
-    $c->response->body( $c->welcome_message );
+    $c->response->body( "This is the MyApp::Controller::Root controller's index action" );
 }
 
 our $books = {
 1 => {
-1 => 'Book 1 Edition 1',
-2 => 'Book 1 Edition 2',
-3 => 'Book 1 Edition 3',
+id => 1,
+1 => { id => 1, text => 'Book 1 Edition 1' },
+2 => { id => 2, text => 'Book 1 Edition 2' },
+3 => { id => 3, text => 'Book 1 Edition 3' },
 },
-2 => {
-1 => 'Book 2 Edition 1',
-2 => 'Book 2 Edition 2',
-3 => 'Book 2 Edition 3',
+2 => { 
+id =>  2,
+1 => { id => 1, text => 'Book 2 Edition 1' },
+2 => { id => 2, text => 'Book 2 Edition 2' },
+3 => { id => 3, text => 'Book 2 Edition 3' },
 },
-3 => {
-1 => 'Book 3 Edition 1',
-2 => 'Book 3 Edition 2',
-3 => 'Book 3 Edition 3',
+3 => { 
+id =>  3,
+1 => { id => 1, text => 'Book 3 Edition 1' },
+2 => { id => 2, text => 'Book 3 Edition 2' },
+3 => { id => 3, text => 'Book 3 Edition 3' },
 }
 };
 

Modified: trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm	2007-04-19 14:45:41 UTC (rev 6300)
+++ trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm	2007-04-19 16:59:34 UTC (rev 6301)
@@ -73,6 +73,17 @@
 
   sub view : PathArgs(0) EndPoint {
 
+You can also mix PathArgs with PathPart.  For example if you wanted to have an
+action responding for the address "/book/$book_id/edition" you
+would need a subroutine called 'edition' in the Book controller, but there is
+already one routine called 'edition' in that controller.  What you can do in
+that case is make a sub with a different name and declare that from the outside
+it's name should be really 'edition':
+
+  sub edition_mascarade: PathPart('edition') PathArgs(0) EndPoint {
+
+yeah - you need to add EndPoint there as well.
+
 Internally PathArgs and EndPoint are converted to 'Chained(.)' and appriopriate 
 CaptureArgs or Args attributes.  For more sophisticated chaining you might need
 to use L<Catalyst::DispatchType::Chained> directly.




More information about the Catalyst-commits mailing list