[Catalyst-commits] r13112 - Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial

xenoterracide at dev.catalyst.perl.org xenoterracide at dev.catalyst.perl.org
Tue Mar 30 12:35:17 GMT 2010


Author: xenoterracide
Date: 2010-03-30 13:35:17 +0100 (Tue, 30 Mar 2010)
New Revision: 13112

Modified:
   Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial/05_Authentication.pod
Log:
Revert "start work on single conroller"

This reverts commit 24815d781d276c8151098d008f28370215aa0e41.

this patch isn't ready yet, accidental commit

Modified: Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial/05_Authentication.pod
===================================================================
--- Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial/05_Authentication.pod	2010-03-30 12:33:26 UTC (rev 13111)
+++ Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial/05_Authentication.pod	2010-03-30 12:35:17 UTC (rev 13112)
@@ -330,29 +330,29 @@
 
 =head2 Add Login and Logout Controllers
 
-Use the Catalyst create script to create a stub controller file:
+Use the Catalyst create script to create two stub controller files:
 
-    $ script/myapp_create.pl controller Authentication
+    $ script/myapp_create.pl controller Login
+    $ script/myapp_create.pl controller Logout
 
-You could easily use multiple controller's here.  For example, you could
-have a C<User> controller for both C<login> and C<logout> actions.
+You could easily use a single controller here.  For example, you could
+have a C<User> controller with both C<login> and C<logout> actions.
 Remember, Catalyst is designed to be very flexible, and leaves such
 matters up to you, the designer and programmer.
 
-Then open C<lib/MyApp/Controller/Authentication.pm>, locate the
+Then open C<lib/MyApp/Controller/Login.pm>, locate the
 C<sub index :Path :Args(0)> method (or C<sub index : Private> if you
 are using an older version of Catalyst) that was automatically
 inserted by the helpers when we created the Login controller above,
-and remove the definition of C<sub index>. Add the following sub:
+and update the definition of C<sub index> to match:
 
-    =head2 login
+    =head2 index
     
     Login logic
     
     =cut
     
-	# global means the path to it will be /login not /authenticaton/login
-    sub login :Global :Args(0) {
+    sub index :Path :Args(0) {
         my ($self, $c) = @_;
     
         # Get the username and password from form
@@ -367,11 +367,13 @@
                 # If successful, then let them use the application
                 $c->response->redirect($c->uri_for(
                     $c->controller('Books')->action_for('list')));
-                return 1;
+                return;
             } else {
+                # Set an error message
                 $c->stash(error_msg => "Bad username or password.");
             }
         } else {
+            # Set an error message
             $c->stash(error_msg => "Empty username or password.");
         }
     
@@ -379,6 +381,10 @@
         $c->stash(template => 'login.tt2');
     }
 
+Be sure to remove the 
+C<$c-E<gt>response-E<gt>body('Matched MyApp::Controller::Login in Login.');>
+line of the C<sub index>.
+
 This controller fetches the C<username> and C<password> values from the
 login form and attempts to authenticate the user.  If successful, it
 redirects the user to the book list page.  If the login fails, the user
@@ -392,11 +398,16 @@
 C<MyApp::Controller::Root>, and then mainly to generate the 404 not
 found page for the application.
 
-Instead, we are using "C<sub somename :Global :Args(0) {...}>" here to
-specifically match the URL C</login>. C<Global> actions create URI matches
-relative to the web root. We make the match even more specific with the
-C<:Args(0)> action modifier -- this forces the match on I<only> C</login>,
-not C</login/somethingelse>.
+Instead, we are using "C<sub somename :Path :Args(0) {...}>" here to
+specifically match the URL C</login>. C<Path> actions (aka, "literal
+actions") create URI matches relative to the namespace of the
+controller where they are defined.  Although C<Path> supports
+arguments that allow relative and absolute paths to be defined, here
+we use an empty C<Path> definition to match on just the name of the
+controller itself.  The method name, C<index>, is arbitrary. We make
+the match even more specific with the C<:Args(0)> action modifier --
+this forces the match on I<only> C</login>, not
+C</login/somethingelse>.
 
 Next, update the corresponding method in
 C<lib/MyApp/Controller/Logout.pm> to match:




More information about the Catalyst-commits mailing list