[Catalyst-commits] r10077 - Catalyst-Manual/5.70/branches/depluralise/lib/Catalyst/Manual/Tutorial

kiffin at dev.catalyst.perl.org kiffin at dev.catalyst.perl.org
Mon May 11 15:12:23 GMT 2009


Author: kiffin
Date: 2009-05-11 15:12:23 +0000 (Mon, 11 May 2009)
New Revision: 10077

Modified:
   Catalyst-Manual/5.70/branches/depluralise/lib/Catalyst/Manual/Tutorial/Authentication.pod
Log:
Modifications required for pluralization up to but not including 'USING PASSWORD HASHES' section.


Modified: Catalyst-Manual/5.70/branches/depluralise/lib/Catalyst/Manual/Tutorial/Authentication.pod
===================================================================
--- Catalyst-Manual/5.70/branches/depluralise/lib/Catalyst/Manual/Tutorial/Authentication.pod	2009-05-11 09:10:47 UTC (rev 10076)
+++ Catalyst-Manual/5.70/branches/depluralise/lib/Catalyst/Manual/Tutorial/Authentication.pod	2009-05-11 15:12:23 UTC (rev 10077)
@@ -82,9 +82,9 @@
 C<myapp02.sql> in your editor and insert:
 
     --
-    -- Add users and roles tables, along with a many-to-many join table
+    -- Add user and role tables, along with a many-to-many join table
     --
-    CREATE TABLE users (
+    CREATE TABLE user (
             id            INTEGER PRIMARY KEY,
             username      TEXT,
             password      TEXT,
@@ -93,11 +93,11 @@
             last_name     TEXT,
             active        INTEGER
     );
-    CREATE TABLE roles (
+    CREATE TABLE role (
             id   INTEGER PRIMARY KEY,
             role TEXT
     );
-    CREATE TABLE user_roles (
+    CREATE TABLE user_role (
             user_id INTEGER,
             role_id INTEGER,
             PRIMARY KEY (user_id, role_id)
@@ -105,21 +105,20 @@
     --
     -- Load up some initial test data
     --
-    INSERT INTO users VALUES (1, 'test01', 'mypass', 't01 at na.com', 'Joe',  'Blow', 1);
-    INSERT INTO users VALUES (2, 'test02', 'mypass', 't02 at na.com', 'Jane', 'Doe',  1);
-    INSERT INTO users VALUES (3, 'test03', 'mypass', 't03 at na.com', 'No',   'Go',   0);
-    INSERT INTO roles VALUES (1, 'user');
-    INSERT INTO roles VALUES (2, 'admin');
-    INSERT INTO user_roles VALUES (1, 1);
-    INSERT INTO user_roles VALUES (1, 2);
-    INSERT INTO user_roles VALUES (2, 1);
-    INSERT INTO user_roles VALUES (3, 1);
+    INSERT INTO user VALUES (1, 'test01', 'mypass', 't01 at na.com', 'Joe',  'Blow', 1);
+    INSERT INTO user VALUES (2, 'test02', 'mypass', 't02 at na.com', 'Jane', 'Doe',  1);
+    INSERT INTO user VALUES (3, 'test03', 'mypass', 't03 at na.com', 'No',   'Go',   0);
+    INSERT INTO role VALUES (1, 'user');
+    INSERT INTO role VALUES (2, 'admin');
+    INSERT INTO user_role VALUES (1, 1);
+    INSERT INTO user_role VALUES (1, 2);
+    INSERT INTO user_role VALUES (2, 1);
+    INSERT INTO user_role VALUES (3, 1);
 
 Then load this into the C<myapp.db> database with the following command:
 
     $ sqlite3 myapp.db < myapp02.sql
 
-
 =head2 Add User and Role Information to DBIC Schema
 
 Although we could manually edit the DBIC schema information to include
@@ -135,7 +134,7 @@
      exists "/root/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
     $
     $ ls lib/MyApp/Schema/Result
-    Authors.pm  BookAuthors.pm  Books.pm  Roles.pm  UserRoles.pm  Users.pm
+    Author.pm  BookAuthor.pm  Book.pm  Role.pm  User.pm  UserRole.pm
 
 Notice how the helper has added three new table-specific result source
 files to the C<lib/MyApp/Schema/Result> directory.  And, more
@@ -144,12 +143,12 @@
 MODIFY THIS OR ANYTHING ABOVE!> comment and your hand-edited
 enhancements would have been preserved.
 
-Speaking of "hand-edit ted enhancements," we should now add
+Speaking of "hand-editted enhancements," we should now add
 relationship information to the three new result source files.  Edit
 each of these files and add the following information between the C<#
 DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment and the closing C<1;>:
 
-C<lib/MyApp/Schema/Result/Users.pm>:
+C<lib/MyApp/Schema/Result/User.pm>:
 
     #
     # Set relationships:
@@ -160,7 +159,7 @@
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *foreign* table (aka, foreign key in peer table)
-    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRoles', 'user_id');
+    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRole', 'user_id');
     
     # many_to_many():
     #   args:
@@ -168,10 +167,10 @@
     #     2) Name of has_many() relationship this many_to_many() is shortcut for
     #     3) Name of belongs_to() relationship in model class of has_many() above
     #   You must already have the has_many() defined to use a many_to_many().
-    __PACKAGE__->many_to_many(roles => 'map_user_role', 'role');
+    __PACKAGE__->many_to_many(role => 'map_user_role', 'role');
 
 
-C<lib/MyApp/Schema/Result/Roles.pm>:
+C<lib/MyApp/Schema/Result/Role.pm>:
 
     #
     # Set relationships:
@@ -182,10 +181,10 @@
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *foreign* table (aka, foreign key in peer table)
-    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRoles', 'role_id');
+    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRole', 'role_id');
 
 
-C<lib/MyApp/Schema/Result/UserRoles.pm>:
+C<lib/MyApp/Schema/Result/UserRole.pm>:
 
     #
     # Set relationships:
@@ -196,18 +195,17 @@
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *this* table
-    __PACKAGE__->belongs_to(user => 'MyApp::Schema::Result::Users', 'user_id');
+    __PACKAGE__->belongs_to(user => 'MyApp::Schema::Result::User', 'user_id');
     
     # belongs_to():
     #   args:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *this* table
-    __PACKAGE__->belongs_to(role => 'MyApp::Schema::Result::Roles', 'role_id');
+    __PACKAGE__->belongs_to(role => 'MyApp::Schema::Result::Role', 'role_id');
 
-
 The code for these three sets of updates is obviously very similar to
-the edits we made to the C<Books>, C<Authors>, and C<BookAuthors>
+the edits we made to the C<Book>, C<Author>, and C<BookAuthor>
 classes created in Chapter 3.
 
 Note that we do not need to make any change to the
@@ -236,11 +234,11 @@
     | MyApp::Controller::Root                                           | instance |
     | MyApp::Model::DB                                                  | instance |
     | MyApp::Model::DB::Author                                          | class    |
-    | MyApp::Model::DB::Books                                           | class    |
-    | MyApp::Model::DB::BookAuthors                                     | class    |
-    | MyApp::Model::DB::Roles                                           | class    |
-    | MyApp::Model::DB::Users                                           | class    |
-    | MyApp::Model::DB::UserRoles                                       | class    |
+    | MyApp::Model::DB::Book                                            | class    |
+    | MyApp::Model::DB::BookAuthor                                      | class    |
+    | MyApp::Model::DB::Role                                            | class    |
+    | MyApp::Model::DB::User                                            | class    |
+    | MyApp::Model::DB::UserRole                                        | class    |
     | MyApp::View::TT                                                   | instance |
     '-------------------------------------------------------------------+----------'
     ...
@@ -296,7 +294,7 @@
 
 =head2 Configure Authentication
 
-There are a variety of way to provide configuration information to
+There are a variety of ways to provide configuration information to
 L<Catalyst::Plugin::Authentication|Catalyst::Plugin::Authentication>.
 Here we will use 
 L<Catalyst::Authentication::Realm::SimpleDB|Catalyst::Authentication::Realm::SimpleDB>
@@ -308,7 +306,7 @@
     __PACKAGE__->config->{'Plugin::Authentication'} = {
             default => {
                 class           => 'SimpleDB',
-                user_model      => 'DB::Users',
+                user_model      => 'DB::User',
                 password_type   => 'clear',
             },
         };
@@ -328,7 +326,7 @@
         use_session 1
         <default>
             password_type self_check
-            user_model    DB::Users
+            user_model    DB::User
             class         SimpleDB
         </default>
     </Plugin::Authentication>
@@ -391,6 +389,9 @@
         $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
@@ -752,7 +753,7 @@
     __PACKAGE__->config->{'Plugin::Authentication'} = {
             default => {
                 class           => 'SimpleDB',
-                user_model      => 'DB::Users',
+                user_model      => 'DB::User',
                 password_type   => 'self_check',
             },
         };




More information about the Catalyst-commits mailing list