[Catalyst-commits] r7796 - trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial

hkclark at dev.catalyst.perl.org hkclark at dev.catalyst.perl.org
Mon May 26 13:08:41 BST 2008


Author: hkclark
Date: 2008-05-26 13:08:41 +0100 (Mon, 26 May 2008)
New Revision: 7796

Modified:
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authentication.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authorization.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/CatalystBasics.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Debugging.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
   trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Testing.pod
Log:
Convert schema to MyApp::Schema, convert model to DB, misc adjustments

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -83,7 +83,7 @@
 
 =back
 
-B<NOTE>: Please contact the author if you would like to assist with 
+B<NOTE:> Please contact the author if you would like to assist with 
 writing a new module.
 
 

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authentication.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authentication.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authentication.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -125,8 +125,8 @@
 the new tables added in the previous step, let's use the C<create=static>
 option on the DBIC model helper to do most of the work for us:
 
-    $ script/myapp_create.pl model MyAppDB DBIC::Schema MyApp::Schema::MyAppDB create=static dbi:SQLite:myapp.db
-    $ ls lib/MyApp/Schema/MyAppDB
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static dbi:SQLite:myapp.db
+    $ ls lib/MyApp/Schema
     Authors.pm  BookAuthors.pm  Books.pm  Roles.pm  UserRoles.pm  Users.pm
 
 Notice how the helper has added three new table-specific result source 
@@ -142,7 +142,7 @@
 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/MyAppDB/Users.pm>:
+C<lib/MyApp/Schema/Users.pm>:
 
     #
     # Set relationships:
@@ -153,7 +153,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
-    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::MyAppDB::UserRoles', 'user_id');
+    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::UserRoles', 'user_id');
     
     # many_to_many():
     #   args:
@@ -164,7 +164,7 @@
     __PACKAGE__->many_to_many(roles => 'map_user_role', 'role');
 
 
-C<lib/MyApp/Schema/MyAppDB/Roles.pm>:
+C<lib/MyApp/Schema/Roles.pm>:
 
     #
     # Set relationships:
@@ -175,10 +175,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
-    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::MyAppDB::UserRoles', 'role_id');
+    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::UserRoles', 'role_id');
 
 
-C<lib/MyApp/Schema/MyAppDB/UserRoles.pm>:
+C<lib/MyApp/Schema/UserRoles.pm>:
 
     #
     # Set relationships:
@@ -189,14 +189,14 @@
     #     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::MyAppDB::Users', 'user_id');
+    __PACKAGE__->belongs_to(user => 'MyApp::Schema::Users', '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::MyAppDB::Roles', 'role_id');
+    __PACKAGE__->belongs_to(role => 'MyApp::Schema::Roles', 'role_id');
 
 
 The code for these three sets of updates is obviously very similar to 
@@ -204,9 +204,9 @@
 classes created in Part 3.
 
 Note that we do not need to make any change to the 
-C<lib/MyApp/Schema/MyAppDB.pm> schema file.  It simple tells DBIC to 
+C<lib/MyApp/Schema.pm> schema file.  It simple tells DBIC to 
 load all of the result source files it finds in below the 
-C<lib/MyApp/Schema/MyAppDB> directory, so it will automatically pick 
+C<lib/MyApp/Schema> directory, so it will automatically pick 
 up our new table information.
 
 
@@ -227,13 +227,13 @@
     +-------------------------------------------------------------------+----------+
     | MyApp::Controller::Books                                          | instance |
     | MyApp::Controller::Root                                           | instance |
-    | MyApp::Model::MyAppDB                                             | instance |
-    | MyApp::Model::MyAppDB::Author                                     | class    |
-    | MyApp::Model::MyAppDB::Books                                      | class    |
-    | MyApp::Model::MyAppDB::BookAuthors                                | class    |
-    | MyApp::Model::MyAppDB::Roles                                      | class    |
-    | MyApp::Model::MyAppDB::Users                                      | class    |
-    | MyApp::Model::MyAppDB::UserRoles                                  | class    |
+    | 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::View::TT                                                   | instance |
     '-------------------------------------------------------------------+----------'
     ...
@@ -325,19 +325,19 @@
                     # Use DBIC to retrieve username, password & role information
                     class DBIx::Class
                     # This is the model object created by Catalyst::Model::DBIC 
-                    # from your schema (you created 'MyAppDB::User' but as the 
-                    # Catalyst startup debug messages show, it was loaded as 
-                    # 'MyApp::Model::MyAppDB::Users').
+                    # from your schema (you created 'MyApp::Schema::User' but as
+                    # the Catalyst startup debug messages show, it was loaded as 
+                    # 'MyApp::Model::DB::Users').
                     # NOTE: Omit 'MyApp::Model' here just as you would when using 
-                    # '$c->model("MyAppDB::Users)'
-                    user_class MyAppDB::Users
+                    # '$c->model("DB::Users)'
+                    user_class DB::Users
                     # This is the name of the field in your 'users' table that 
                     # contains the user's name
                     id_field username
                 </store>
             </dbic>
-          </realms>
-        </authentication>
+        </realms>
+    </authentication>
 
 Inline comments in the code above explain how each field is being used.
 
@@ -352,7 +352,7 @@
     $ script/myapp_create.pl controller Login
     $ script/myapp_create.pl controller Logout
 
-B<NOTE>: You could easily use a single controller here.  For example,
+B<NOTE:> 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.
@@ -617,7 +617,7 @@
 
     $ script/myapp_server.pl
 
-B<IMPORTANT NOTE>: If you happen to be using Internet Explorer, you may
+B<IMPORTANT NOTE:> If you happen to be using Internet Explorer, you may
 need to use the command C<script/myapp_server.pl -k> to enable the
 keepalive feature in the development server.  Otherwise, the HTTP
 redirect on successful login may not work correctly with IE (it seems to
@@ -684,6 +684,11 @@
     e727d1464ae12436e899a726da5b2f11d8381b26
     $
 
+B<Note:> If you are following along in Ubuntu, you will need to install 
+C<Digest::SHA> with the following command to run the example code above:
+
+    sudo apt-get install libdigest-sha-perl
+
 B<Note:> You should probably modify this code for production use to
 not read the password from the command line.  By having the script
 prompt for the cleartext password, it avoids having the password linger
@@ -719,7 +724,6 @@
 Edit C<myapp.conf> and update it to match (the C<password_type> and
 C<password_hash_type> are new, everything else is the same):
 
-    ---
     name MyApp
     <authentication>
         default_realm dbic
@@ -739,24 +743,24 @@
                     password_type  hashed
                     # Use the SHA-1 hashing algorithm
                     password_hash_type SHA-1
-                 </credential>
+                </credential>
                 <store>
                     # Use DBIC to retrieve username, password & role information
                     class DBIx::Class
                     # This is the model object created by Catalyst::Model::DBIC 
-                    # from your schema (you created 'MyAppDB::User' but as the 
-                    # Catalyst startup debug messages show, it was loaded as 
-                    # 'MyApp::Model::MyAppDB::Users').
+                    # from your schema (you created 'MyApp::Schema::User' but as
+                    # the Catalyst startup debug messages show, it was loaded as 
+                    # 'MyApp::Model::DB::Users').
                     # NOTE: Omit 'MyApp::Model' here just as you would when using 
-                    # '$c->model("MyAppDB::Users)'
-                    user_class MyAppDB::Users
+                    # '$c->model("DB::Users)'
+                    user_class DB::Users
                     # This is the name of the field in your 'users' table that 
                     # contains the user's name
                     id_field username
-                 </store>
-              </dbic>
-           </realms>
-         </authentication>
+                </store>
+            </dbic>
+        </realms>
+    </authentication>
 
 =head2 Try Out the Hashed Passwords
 
@@ -797,7 +801,7 @@
         my ($self, $c, $id) = @_;
     
         # Search for the book and then delete it
-        $c->model('MyAppDB::Books')->search({id => $id})->delete_all;
+        $c->model('DB::Books')->search({id => $id})->delete_all;
     
         # Use 'flash' to save information across requests until it's read
         $c->flash->{status_msg} = "Book deleted";

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authorization.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authorization.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Authorization.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -95,7 +95,6 @@
 Edit C<myapp.conf> and update it to match the following (the 
 C<role_relation> and C<role_field> definitions are new):
 
-    ---
     name MyApp
     <authentication>
         default_realm dbic
@@ -111,19 +110,21 @@
                     # This is the name of the field in the users table with the
                     # password stored in it
                     password_field password
-                    # We are using an unencrypted password now
-                    password_type clear
-                 </credential>
+                    # Switch to more secure hashed passwords
+                    password_type  hashed
+                    # Use the SHA-1 hashing algorithm
+                    password_hash_type SHA-1
+                </credential>
                 <store>
                     # Use DBIC to retrieve username, password & role information
                     class DBIx::Class
                     # This is the model object created by Catalyst::Model::DBIC 
-                    # from your schema (you created 'MyAppDB::User' but as the 
-                    # Catalyst startup debug messages show, it was loaded as 
-                    # 'MyApp::Model::MyAppDB::Users').
+                    # from your schema (you created 'MyApp::Schema::User' but as
+                    # the Catalyst startup debug messages show, it was loaded as 
+                    # 'MyApp::Model::DB::Users').
                     # NOTE: Omit 'MyApp::Model' here just as you would when using 
-                    # '$c->model("MyAppDB::Users)'
-                    user_class MyAppDB::Users
+                    # '$c->model("DB::Users)'
+                    user_class DB::Users
                     # This is the name of the field in your 'users' table that 
                     # contains the user's name
                     id_field username
@@ -133,10 +134,10 @@
                     # This is the name of field in the roles table that contains
                     # the role information
                     role_field role
-                  </store>
-                </dbic>
-              </realms>
-            </authentication>
+                </store>
+            </dbic>
+        </realms>
+    </authentication>
 
 
 =head2 Add Role-Specific Logic to the "Book List" Template
@@ -198,7 +199,7 @@
         if ($c->check_user_roles('admin')) {
             # Call create() on the book model object. Pass the table 
             # columns/field values we want to set as hash values
-            my $book = $c->model('MyAppDB::Books')->create({
+            my $book = $c->model('DB::Books')->create({
                     title   => $title,
                     rating  => $rating
                 });

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -97,7 +97,7 @@
     
         # Call create() on the book model object. Pass the table 
         # columns/field values we want to set as hash values
-        my $book = $c->model('MyAppDB::Books')->create({
+        my $book = $c->model('DB::Books')->create({
                 title  => $title,
                 rating => $rating
             });
@@ -298,7 +298,7 @@
         my $author_id = $c->request->params->{author_id} || '1';
     
         # Create the book
-        my $book = $c->model('MyAppDB::Books')->create({
+        my $book = $c->model('DB::Books')->create({
                 title   => $title,
                 rating  => $rating,
             });
@@ -406,7 +406,7 @@
         my ($self, $c, $id) = @_;
     
         # Search for the book and then delete it
-        $c->model('MyAppDB::Books')->search({id => $id})->delete_all;
+        $c->model('DB::Books')->search({id => $id})->delete_all;
     
         # Set a status message to be displayed at the top of the view
         $c->stash->{status_msg} = "Book deleted.";
@@ -479,7 +479,7 @@
         my ($self, $c, $id) = @_;
     
         # Search for the book and then delete it
-        $c->model('MyAppDB::Books')->search({id => $id})->delete_all;
+        $c->model('DB::Books')->search({id => $id})->delete_all;
     
         # Set a status message to be displayed at the top of the view
         $c->stash->{status_msg} = "Book deleted.";
@@ -521,7 +521,7 @@
         my ($self, $c, $id) = @_;
     
         # Search for the book and then delete it
-        $c->model('MyAppDB::Books')->search({id => $id})->delete_all;
+        $c->model('DB::Books')->search({id => $id})->delete_all;
     
         # Redirect the user back to the list page with status msg as an arg
         $c->response->redirect($c->uri_for('/books/list', 

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/CatalystBasics.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/CatalystBasics.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/CatalystBasics.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -73,7 +73,7 @@
 application. Given that many other documents cover this subject in
 detail, MVC will not be discussed in depth here (for an excellent
 introduction to MVC and general Catalyst concepts, please see
-L<Catalyst::Manual::About>. In short:
+L<Catalyst::Manual::About|Catalyst::Manual::About>. In short:
 
 =over 4
 
@@ -108,7 +108,7 @@
 
 You can checkout the source code for this example from the catalyst
 subversion repository as per the instructions in
-L<Catalyst::Manual::Tutorial::Intro>
+L<Catalyst::Manual::Tutorial::Intro|Catalyst::Manual::Tutorial::Intro>
 
 
 =head1 CREATE A CATALYST PROJECT
@@ -244,18 +244,21 @@
 
     sub default : Path : Args {
         my ( $self, $c ) = @_;
-
+    
         $c->response->body( $c->welcome_message );
     }
 
 The "C<$c>" here refers to the Catalyst context, which is used to 
 access the Catalyst application. In addition to many other things, 
 the Catalyst context provides access to "response" and "request" 
-objects. (See L<Catalyst>, L<Catalyst::Response>, and L<Catalyst::Request>) 
+objects. (See L<Catalyst|Catalyst>, 
+L<Catalyst::Response|Catalyst::Response>, and 
+L<Catalyst::Request|Catalyst::Request>) 
 
 C<$c->response->body> sets the HTTP response (see 
-L<Catalyst::Response>), while C<$c->welcome_message> is a special method 
-that returns the welcome message that you saw in your browser.
+L<Catalyst::Response|Catalyst::Response>), while C<$c->welcome_message> 
+is a special method that returns the welcome message that you saw in 
+your browser.
 
 The ": Path : Args" after the method name are attributes which determine 
 which URLs will be dispatched to this method. (Depending on your version of 
@@ -280,17 +283,19 @@
 method. 
 
 
-Add the following subroutine to your Root.pm file:
+Add the following subroutine to your C<lib/Hello/Controller/Root.pm> 
+file:
 
     sub hello : Global {
         my ( $self, $c ) = @_;
+        
         $c->response->body("Hello, World!");
     }
 
 Here you're sending your own string to the webpage.
 
 Save the file, start the server (stop and restart it if it's still 
-up), and go to L<http://localhost:3000/hello|http://localhost:3000> to 
+up), and go to L<http://localhost:3000/hello> to 
 see "Hello, World!"
 
 =head2 Hello, World! Using a View and a Template
@@ -320,7 +325,7 @@
 
 Template Toolkit is a very full featured template facility, with 
 excellent documentation at 
-L<http://template-tookit.org/|http://template-tookit.org/>, 
+L<http://template-tookit.org/>, 
 but since this is not a TT tutorial, we'll stick to only basic TT 
 usage here (and explore some of the more common TT features in later 
 parts of the tutorial).
@@ -331,16 +336,17 @@
   
     [% META title = 'Hello, World!' %]
     <p>
-        This is a TT view template, located in the root directory.
+        This is a TT view template, located in the 'root/' directory.
     </p>
 
 [% and %] are markers for the TT parts of the template. Inside you can 
 access Perl variables and classes, and use TT directives. The rest of 
-the template is normal HTML. Change the hello method in Root.pm to the 
-following:
+the template is normal HTML. Change the hello method in 
+C<lib/Hello/Controller/Root.pm> to the following:
 
     sub hello : Global {
         my ( $self, $c ) = @_;
+        
         $c->stash->{template} = 'hello.tt';
     }
 
@@ -354,7 +360,7 @@
 template will be magically displayed at the end of your method.
 
 After saving the file, restart the development server, and look at 
-L<http://localhost:3000/hello|http://localhost:3000> again. You should 
+L<http://localhost:3000/hello> again. You should 
 see the template that you just made.
 
 
@@ -369,10 +375,11 @@
 not much there. Most people probably don't bother to use the create 
 script to make controllers after they're used to using Catalyst.
 
-In Site.pm, add the following method:
+In C<lib/Hello/Controller/Site.pm>, add the following method:
 
     sub test : Local {
         my ( $self, $c ) = @_;
+    
         $c->stash->{username} = "John";
         $c->stash->{template} = 'site/test.tt';
     }
@@ -389,14 +396,14 @@
 for use in the template.
 
 Make a subdirectory "site" in the "root" directory. Copy the hello.tt 
-file into the directory as root/site/test.tt, or create a new template 
-file at that location. Include a line like: 
+file into the directory as C<root/site/test.tt>, or create a new 
+template file at that location. Include a line like: 
 
-    <p>Hello, [% username %]!</p> 
+    <p>Hello, [% username %]!</p>
 
 Bring up or restart the server.  Notice in the server output that 
 C</site/test> is listed in the Loaded Path actions. Go to 
-L<http://localhost:3000/site/test|http://localhosst:3000/site/test> 
+L<http://localhost:3000/site/test> 
 
 You should see your test.tt file displayed, including the name "John"
 that you set in the controller.

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Debugging.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Debugging.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Debugging.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -116,7 +116,7 @@
             
         # Retrieve all of the book records as book model objects and store in the
         # stash where they can be accessed by the TT template
-        $c->stash->{books} = [$c->model('MyAppDB::Books')->all];
+        $c->stash->{books} = [$c->model('DB::Books')->all];
             
         # Set the TT template to use.  You will almost always want to do this
         # in your action methods.
@@ -126,6 +126,8 @@
 This causes the Perl Debugger to enter "single step mode" when this command is 
 encountered (it has no effect when Perl is run without the C<-d> flag).
 
+B<NOTE:> The C<DB> here is the Perl Debugger, not the DB model.
+
 To now run the Catalyst development server under the Perl debugger, simply 
 prepend C<perl -d> to the front of C<script/myapp_server.pl>:
 
@@ -155,7 +157,7 @@
 development server will drop to the Perl debugger prompt:
 
     MyApp::Controller::Books::list(/home/me/MyApp/script/../lib/MyApp/Controller/Books.pm:40):
-    40:         $c->stash->{books} = [$c->model('MyAppDB::Books')->all];
+    40:         $c->stash->{books} = [$c->model('DB::Books')->all];
     
       DB<1>
 
@@ -177,7 +179,7 @@
 
 Next, list the methods available on our C<Book> model:
 
-      DB<1> m $c->model('MyAppDB::Books')
+      DB<1> m $c->model('DB::Books')
     ()
     (0+
     (bool
@@ -196,7 +198,7 @@
 
 We can also play with the model directly:
 
-      DB<2> x ($c->model('MyAppDB::Books')->all)[1]->title
+      DB<2> x ($c->model('DB::Books')->all)[1]->title
     SELECT me.id, me.title, me.rating FROM books me:
     0  'TCP/IP Illustrated, Volume 1'
 
@@ -207,7 +209,7 @@
 
       DB<3> x 4 $c->stash->{books}
     0  ARRAY(0xa8f3b7c)
-       0  MyApp::Model::MyAppDB::Book=HASH(0xb8e702c)
+       0  MyApp::Model::DB::Book=HASH(0xb8e702c)
           '_column_data' => HASH(0xb8e5e2c)
              'id' => 1
              'rating' => 5

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -140,7 +140,7 @@
 this feature of Catalyst during the authentication and authorization
 sections (Part 5 and Part 6).
 
-B<IMPORTANT NOTE>: If you are following along in Ubuntu 8.04 or
+B<IMPORTANT NOTE:> If you are following along in Ubuntu 8.04 or
 otherwise using a version of L<Catalyst::Devel|Catalyst::Devel> prior
 to version 1.06, you need to be aware that Catalyst changed from a
 default format of YAML to the more straightforward C<Config::General>
@@ -158,13 +158,16 @@
 automatically look for any of the supported configuration file
 formats.
 
-C<TIP>: This script can be useful for converting between configuration 
+B<TIP>: This script can be useful for converting between configuration 
 formats:
 
     perl -Ilib -e 'use MyApp; use Config::General; 
         Config::General->new->save_file("myapp.conf", MyApp->config);'
 
+B<NOTE:> The default C<myapp.conf> should look like:
 
+    name   MyApp
+
 =item *
 
 L<Catalyst::Plugin::Static::Simple|Catalyst::Plugin::Static::Simple>
@@ -245,7 +248,7 @@
     
         # Retrieve all of the book records as book model objects and store in the
         # stash where they can be accessed by the TT template
-        $c->stash->{books} = [$c->model('MyAppDB::Books')->all];
+        $c->stash->{books} = [$c->model('DB::Books')->all];
         
         # Set the TT template to use.  You will almost always want to do this
         # in your action methods (action methods respond to user input in
@@ -254,7 +257,7 @@
     }
 
 B<Note:> This won't actually work yet since you haven't set up your 
-model yet.
+model yet.  We will be covering the model soon.
 
 B<Note:> Programmers experienced with object-oriented Perl should 
 recognize C<$self> as a reference to the object where this method was 
@@ -264,8 +267,8 @@
 Catalyst components.  It is used to pass information between 
 components and provide access to Catalyst and plugin functionality.
 
-B<TIP>: You may see the C<$c-E<gt>model('MyAppDB::Book')> used above
-written as C<$c-E<gt>model('MyAppDB')-E<gt>resultset('Book)>.  The two
+B<TIP>: You may see the C<$c-E<gt>model('DB::Book')> used above
+written as C<$c-E<gt>model('DB')-E<gt>resultset('Book)>.  The two
 are equivalent.
 
 B<Note:> Catalyst actions are regular Perl methods, but they make use 
@@ -298,11 +301,11 @@
 virtually every aspect of Catalyst, options abound when it comes to 
 the specific view technology you adopt inside your application. 
 However, most Catalyst applications use the Template Toolkit, known as 
-TT (for more information on TT, see L<http://www.template-
-toolkit.org>). Other popular view technologies include Mason 
-(L<http://www.masonhq.com> and L<http://www.masonbook.com>) and 
-L<HTML::Template|HTML::Template> (L<http://html-
-template.sourceforge.net>).
+TT (for more information on TT, see 
+L<http://www.template-toolkit.org>). Other popular view technologies 
+include Mason (L<http://www.masonhq.com> and 
+L<http://www.masonbook.com>) and L<HTML::Template> 
+(L<http://html- template.sourceforge.net>).
 
 =head2 Create a Catalyst View Using C<TTSite>
 
@@ -480,7 +483,7 @@
 Pod documentation, you can access the TT manual at
 L<http://www.template-toolkit.org/docs/default/>.
 
-B<NOTE>: The C<TTSite> helper creates several TT files using an
+B<NOTE:> The C<TTSite> helper creates several TT files using an
 extension of C<.tt2>. Most other Catalyst and TT examples use an
 extension of C<.tt>.  You can use either extension (or no extension at
 all) with TTSite and TT, just be sure to use the appropriate extension
@@ -601,28 +604,27 @@
 dynamically reads your database structure every time the application
 starts:
 
-    $ script/myapp_create.pl model MyAppDB DBIC::Schema MyApp::Schema::MyAppDB create=dynamic dbi:SQLite:myapp.db
-     exists "/home/me/MyApp/script/../lib/MyApp/Model"
-     exists "/home/me/MyApp/script/../t"
-    created "/home/me/MyApp/script/../lib/MyApp/Schema"
-    created "/home/me/MyApp/script/../lib/MyApp/Schema/MyAppDB.pm"
-    created "/home/me/MyApp/script/../lib/MyApp/Model/MyAppDB.pm"
-    created "/home/me/MyApp/script/../t/model_MyAppDB.t"
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=dynamic dbi:SQLite:myapp.db
+     exists "/home/kclark/dev/MyApp/script/../lib/MyApp/Model"
+     exists "/home/kclark/dev/MyApp/script/../t"
+     exists "/home/kclark/dev/MyApp/script/../lib/MyApp"
+    created "/home/kclark/dev/MyApp/script/../lib/MyApp/Schema.pm"
+    created "/home/kclark/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
+    created "/home/kclark/dev/MyApp/script/../t/model_DB.t"
 
 
-C<MyAppDB> is the name of the model class to be created by the helper in 
+C<DB> is the name of the model class to be created by the helper in 
 C<lib/MyApp/Model> (Catalyst has a separate directory under C<lib/MyApp> 
-for each of the three parts of MVC: C<Model>, C<View>, and C<Controller> 
-[although older Catalyst applications often use the directories C<M>, 
-C<V>, and C<C>]).  C<DBIC::Schema> is the type of the model to create. 
-C<MyApp::Schema::MyAppDB> is the name of the DBIC schema file written to 
-C<lib/MyApp/Schema/MyAppDB.pm>.  Because we specified C<create=dynamic> 
+for each of the three parts of MVC: C<Model>, C<View>, and C<Controller>).  
+C<DBIC::Schema> is the type of the model to create. 
+C<MyApp::Schema> is the name of the DBIC schema file written to 
+C<lib/MyApp/Schema.pm>.  Because we specified C<create=dynamic> 
 to the helper, it use L<DBIx::Class::Schema::Loader> to dynamically load 
 the schema information from the database every time the application 
 starts.  And finally, C<dbi:SQLite:myapp.db> is the standard DBI connect 
 string for use with SQLite.
 
-B<NOTE>: Although the C<create=dynamic> option to the DBIC helper
+B<NOTE:> Although the C<create=dynamic> option to the DBIC helper
 makes for a nifty demonstration, is only really suitable for very
 small applications. After this demonstration, you should almost always
 use the C<create=static> option that we switch to below.
@@ -640,7 +642,7 @@
 you are using a different shell (for example, under tcsh, use
 C<setenv DBIC_TRACE 1>).
 
-B<NOTE>: You can also set this in your code using
+B<NOTE:> You can also set this in your code using
 C<$class-E<gt>storage-E<gt>debug(1);>.  See
 L<DBIx::Class::Manual::Troubleshooting> for details (including options
 to log to file instead of displaying to the Catalyst development server
@@ -671,10 +673,10 @@
     +-----------------------------------------------------------------+----------+
     | MyApp::Controller::Books                                        | instance |
     | MyApp::Controller::Root                                         | instance |
-    | MyApp::Model::MyAppDB                                           | instance |
-    | MyApp::Model::MyAppDB::Authors                                  | class    |
-    | MyApp::Model::MyAppDB::BookAuthors                              | class    |
-    | MyApp::Model::MyAppDB::Books                                    | class    |
+    | MyApp::Model::DB                                                | instance |
+    | MyApp::Model::DB::Authors                                       | class    |
+    | MyApp::Model::DB::BookAuthors                                   | class    |
+    | MyApp::Model::DB::Books                                         | class    |
     | MyApp::View::TT                                                 | instance |
     '-----------------------------------------------------------------+----------'
     
@@ -698,7 +700,7 @@
     [info] MyApp powered by Catalyst 5.7011
     You can connect to your server at http://localhost:3000
 
-B<NOTE>: Be sure you run the C<script/myapp_server.pl> command from 
+B<NOTE:> Be sure you run the C<script/myapp_server.pl> command from 
 the 'base' directory of your application, not inside the C<script> 
 directory itself or it will not be able to locate the C<myapp.db> 
 database file.  You can use a fully qualified or a relative path to 
@@ -713,8 +715,8 @@
 
 Catalyst::Model::DBIC::Schema dynamically created three model classes, 
 one to represent each of the three tables in our database 
-(C<MyApp::Model::MyAppDB::Authors>, C<MyApp::Model::MyAppDB::BookAuthors>,
-and C<MyApp::Model::MyAppDB::Books>).
+(C<MyApp::Model::DB::Authors>, C<MyApp::Model::DB::BookAuthors>,
+and C<MyApp::Model::DB::Books>).
 
 =item * 
 
@@ -758,29 +760,29 @@
 used earlier with C<create=dynamic> to build the static files for us.
 First, lets remove the schema file created in Part 2:
 
-    $ rm lib/MyApp/Schema/MyAppDB.pm 
+    $ rm lib/MyApp/Schema.pm 
 
 Now regenerate the schema using the C<create=static> option:
 
-    $ script/myapp_create.pl model MyAppDB DBIC::Schema MyApp::Schema::MyAppDB create=static dbi:SQLite:myapp.db
-     exists "/home/me/MyApp/script/../lib/MyApp/Model"
-     exists "/home/me/MyApp/script/../t"
-    Dumping manual schema for MyApp::Schema::MyAppDB to directory /home/me/MyApp/script/../lib ...
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static dbi:SQLite:myapp.db
+     exists "/home/kclark/dev/MyApp/script/../lib/MyApp/Model"
+     exists "/home/kclark/dev/MyApp/script/../t"
+    Dumping manual schema for MyApp::Schema to directory /home/kclark/dev/MyApp/script/../lib ...
     Schema dump completed.
-     exists "/home/me/MyApp/script/../lib/MyApp/Model/MyAppDB.pm"
+     exists "/home/kclark/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
 
-We could have also deleted C<lib/MyApp/Model/MyAppDB.pm>, but it would 
+We could have also deleted C<lib/MyApp/Model/DB.pm>, but it would 
 have regenerated the same file (note the C<exists> in the output above).
-If you take a look at C<lib/MyApp/Model/MyAppDB.pm>, it simply contains
-a reference to the actual schema file in C<lib/MyApp/Schema/MyAppDB.pm>
+If you take a look at C<lib/MyApp/Model/DB.pm>, it simply contains
+a reference to the actual schema file in C<lib/MyApp/Schema.pm>
 along with the database connect string.
 
 If you look in the C<lib/MyApp/Schema> directory, you will find that 
-C<MyAppDB.pm> is no longer using L<DBIx::Class::Schema::Loader> as its 
+C<DB.pm> is no longer using L<DBIx::Class::Schema::Loader> as its 
 base class (L<DBIx::Class::Schema::Loader> is only being used by the 
 helper to load the schema once and then create the static files for us) 
 and that it only contains a call to the C<load_classes> method.  You 
-will also find that C<lib/MyApp/Schema> contains a C<MyAppDB> 
+will also find that C<lib/MyApp/Schema> contains a C<Schema> 
 subdirectory, with one file inside this directory for each of the tables 
 in our simple database (C<Authors.pm>, C<BookAuthors.pm>, and 
 C<Books.pm>).  These three files were created based on the information
@@ -795,10 +797,10 @@
 
 Also note the "flow" of the model information across the various files 
 and directories.  Catalyst will initially load the model from 
-C<lib/MyApp/Model/MyAppDB.pm>.  This file contains a reference to
-C<lib/MyApp/Schema/MyAppDB.pm>, so that file is loaded next.  Finally,
+C<lib/MyApp/Model/DB.pm>.  This file contains a reference to
+C<lib/MyApp/Schema.pm>, so that file is loaded next.  Finally,
 the call to C<load_classes> in that file will load each of the 
-table-specific "results source" files from the C<lib/MyApp/Schema/MyAppDB>
+table-specific "results source" files from the C<lib/MyApp/Schema>
 subdirectory.  These three table-specific DBIC schema files will then be 
 used to create three table-specific Catalyst models every time the 
 application starts (you can see these three model files listed in
@@ -809,7 +811,7 @@
 
 
 Let's manually add some relationship information to the auto-generated
-schema files.  First edit C<lib/MyApp/Schema/MyAppDB/Books.pm> and
+schema files.  First edit C<lib/MyApp/Schema/Books.pm> and
 add the following text below the C<# You can replace this text...> 
 comment:
 
@@ -822,7 +824,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
-    __PACKAGE__->has_many(book_authors => 'MyApp::Schema::MyAppDB::BookAuthors', 'book_id');
+    __PACKAGE__->has_many(book_authors => 'MyApp::Schema::BookAuthors', 'book_id');
     
     # many_to_many():
     #   args:
@@ -850,7 +852,7 @@
 cannot define a C<many_to_many> relationship without also having the 
 C<has_many> relationship in place.
 
-Then edit C<lib/MyApp/Schema/MyAppDB/Authors.pm> and add relationship
+Then edit C<lib/MyApp/Schema/Authors.pm> and add relationship
 information as follows (again, be careful to put in above the C<1;> but
 below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment):
 
@@ -863,7 +865,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
-    __PACKAGE__->has_many(book_author => 'MyApp::Schema::MyAppDB::BookAuthors', 'author_id');
+    __PACKAGE__->has_many(book_author => 'MyApp::Schema::BookAuthors', 'author_id');
     
     # many_to_many():
     #   args:
@@ -874,7 +876,7 @@
     __PACKAGE__->many_to_many(books => 'book_author', 'book');
 
 Finally, do the same for the "join table," 
-C<lib/MyApp/Schema/MyAppDB/BookAuthors.pm>:
+C<lib/MyApp/Schema/BookAuthors.pm>:
 
     #
     # Set relationships:
@@ -885,14 +887,14 @@
     #     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(book => 'MyApp::Schema::MyAppDB::Books', 'book_id');
+    __PACKAGE__->belongs_to(book => 'MyApp::Schema::Books', 'book_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(author => 'MyApp::Schema::MyAppDB::Authors', 'author_id');
+    __PACKAGE__->belongs_to(author => 'MyApp::Schema::Authors', 'author_id');
 
 
 =head1 RUN THE APPLICATION
@@ -1055,7 +1057,7 @@
     
         # Retrieve all of the book records as book model objects and store in the
         # stash where they can be accessed by the TT template
-        $c->stash->{books} = [$c->model('MyAppDB::Books')->all];
+        $c->stash->{books} = [$c->model('DB::Books')->all];
     
         # Set the TT template to use.  You will almost always want to do this
         # in your action methods (actions methods respond to user input in

Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Testing.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Testing.pod	2008-05-26 12:03:00 UTC (rev 7795)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/Testing.pod	2008-05-26 12:08:41 UTC (rev 7796)
@@ -328,12 +328,12 @@
 it runs your full application; however, this can complicate things when
 you want to support multiple databases.  One solution is to allow the
 database specification to be overridden with an environment variable.
-For example, open C<lib/MyApp/Model/MyAppDB.pm> in your editor and
+For example, open C<lib/MyApp/Model/DB.pm> in your editor and
 change the C<__PACKAGE__-E<gt>config(...> declaration to resemble:
 
     my $dsn = $ENV{MYAPP_DSN} ||= 'dbi:SQLite:myapp.db';
     __PACKAGE__->config(
-        schema_class => 'MyApp::Schema::MyAppDB',
+        schema_class => 'MyApp::Schema',
         connect_info => [
             $dsn,
         ],




More information about the Catalyst-commits mailing list