[Catalyst-commits] r9495 - in Catalyst-Manual/5.70/trunk: . lib/Catalyst lib/Catalyst/Manual lib/Catalyst/Manual/Tutorial

hkclark at dev.catalyst.perl.org hkclark at dev.catalyst.perl.org
Wed Mar 11 17:03:37 GMT 2009


Author: hkclark
Date: 2009-03-11 17:03:37 +0000 (Wed, 11 Mar 2009)
New Revision: 9495

Modified:
   Catalyst-Manual/5.70/trunk/Changes
   Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual.pm
   Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial.pod
   Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
   Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
Log:
Move use of "load_namespaces" for DBIC from BasicCRUD to MoreCatalystBasics
Update the "Table of Contents" in Tutorial.pod to match the current sections
Prep for release


Modified: Catalyst-Manual/5.70/trunk/Changes
===================================================================
--- Catalyst-Manual/5.70/trunk/Changes	2009-03-11 16:46:02 UTC (rev 9494)
+++ Catalyst-Manual/5.70/trunk/Changes	2009-03-11 17:03:37 UTC (rev 9495)
@@ -1,10 +1,15 @@
 Revision history for Catalyst-Manual
 
+5.7019  11 Mar 2009
         - Change from the use of "part" to refer to each .pod file for the
             tutorial in favor of the more intuitive word "chapter."  "Part" 
             was just to ambiguous (e.g., does "prior part" refer to the prior 
             .pod file or the prior section in the current .pod file).
-        - Fix typos
+        - Move use of "load_namespaces" for DBIC from BasicCRUD to 
+            MoreCatalystBasics
+        - Update the "Table of Contents" in Tutorial.pod to match the current
+            sections
+        - Fix a few typos
 
 5.7018  8 Mar 2009
         - Add a new section to BasicCRUD covering more advanced features of 

Modified: Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
===================================================================
--- Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod	2009-03-11 16:46:02 UTC (rev 9494)
+++ Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod	2009-03-11 17:03:37 UTC (rev 9495)
@@ -937,108 +937,6 @@
 of them in your applications.
 
 
-=head2 Convert to DBIC "load_namespaces"
-
-If you look back at
-L<Catalyst::Manual::Tutorial::MoreCatalystBasics/Create Static DBIC
-Schema Files> you will recall that we load our DBIC Result Classes
-(Books.pm, Authors.pm and BookAuthors.pm) with  in
-C<lib/MyApp/Schema.pm> with the C<load_classes> feature.  Although
-this method is perfectly valid, the DBIC community has migrated to a
-newer C<load_namespaces> technique because it more easily supports a
-variety of advanced features.  Since we want to explore some of these
-features below, let's first migrate our configuration over to use
-C<load_namespaces>.
-
-If you are following along in Debian 5, you will need to upgrade your
-version of
-L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> to 0.23
-or higher.  To do this, we can install directly from CPAN via the
-following command:
-
-    $ sudo cpan Catalyst::Model::DBIC::Schema
-
-Then make sure you are running an appropriate version:
-
-    $ perl -MCatalyst::Model::DBIC::Schema -e \
-        'print "$Catalyst::Model::DBIC::Schema::VERSION\n"'
-    0.23
-
-Make sure you get version 0.23 or higher.
-
-B<Note:> Debian will automatically "do the right thing" and use the
-module we installed from CPAN and ignore the older version we picked
-up via the C<aptitude> command.  If you are using a different
-environment, you will need to make sure you are using v0.23 or higher
-with the command above.
-
-While we are at it, let's install a few other modules from CPAN for
-some of the other work we will be doing below:
-
-    $ cpan Time::Warp DBICx::TestDatabase \
-        DBIx::Class::DynamicDefault DBIx::Class::TimeStamp
-
-Next, we need to delete the existing C<lib/MyApp/Schema.pm> so that
-the Catalyst DBIC helper will recreate it.  Then we re-generate
-the model and schema information:
-
-    $ rm lib/MyApp/Schema.pm
-    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
-        create=static components=TimeStamp dbi:SQLite:myapp.db
-     exists "/root/dev/MyApp/script/../lib/MyApp/Model"
-     exists "/root/dev/MyApp/script/../t"
-    Dumping manual schema for MyApp::Schema to directory /root/dev/MyApp/script/../lib ...
-    Schema dump completed.
-     exists "/root/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
-    $
-    $ ls lib/MyApp/Schema
-    Authors.pm  BookAuthors.pm  Books.pm  Result
-    $ ls lib/MyApp/Schema/Result
-    Authors.pm  BookAuthors.pm  Books.pm
-
-Notice that we now have a duplicate set of Result Class files.  With
-the newer C<load_namespaces> feature, DBIC automatically looks for
-your Result Class files in a subdirectory of the Schema directory
-called C<Result> (the files in C<lib/MyApp/Schema> were already there
-from Chapter 3 of the tutorial; the files in C<lib/MyApp/Schema/Result>
-are new).
-
-If you are using SQLite, you will need to manually re-enter the
-relationship configuration as we did in Chapter 3 of the tutorial (if you
-are using different database, the relationships might have been auto-
-generated by Schema::Loader).  One option is to use the following
-command-line perl script to migrate the information across
-automatically:
-
-    $ cd lib/MyApp/Schema
-    $ perl -MIO::All -e 'for (@ARGV) { my $s < io($_); $s =~ s/.*\n\# You can replace.*?\n//s;
-          $s =~ s/'MyApp::Schema::/'MyApp::Schema::Result::/g; my $d < io("Result/$_");
-          $d =~ s/1;\n?//; "$d$s" > io("Result/$_"); }' *.pm
-    $ cd ../../..
-
-If you prefer, you can do the migration by hand using "cut and paste"
-from the files in C<lib/MyApp/Schema> (or from
-L<Catalyst::Manual::Tutorial::MoreCatalystBasics/Updating the Generated DBIC Schema Files>)
-to the corresponding files in C<lib/MyApp/Schema/Result>.  If you take
-this approach, be sure to add C<::Result> to the end of
-C<MyApp::Schema> in all three files (for example, in C<Books.pm>, the
-"peer class" in the C<has_many> relationship needs to be changed from
-C<MyApp::Schema::BookAuthors> to C<MyApp::Schema::BookAuthors::Result>).
-
-Now we can remove the original set of Result Class files that we no
-longer need:
-
-    $ rm lib/MyApp/Schema/*.pm
-    $ ls lib/MyApp/Schema
-    Result
-
-Finally, test the application to be sure everything is still
-working under our new configuration.  Use the
-C<script/myapp_server.pl> command to start the development server and
-point your browser to L<http://localhost:3000/books/list>.  Make sure
-you see the existing list of books.
-
-
 =head2 Add Datetime Columns to Our Existing Books Table
 
 Let's add two columns to our existing C<books> table to track when

Modified: Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
===================================================================
--- Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod	2009-03-11 16:46:02 UTC (rev 9494)
+++ Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod	2009-03-11 17:03:37 UTC (rev 9495)
@@ -655,7 +655,8 @@
 dynamically reads your database structure every time the application
 starts:
 
-    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=dynamic dbi:SQLite:myapp.db
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
+        create=dynamic dbi:SQLite:myapp.db
      exists "/home/me/MyApp/script/../lib/MyApp/Model"
      exists "/home/me/MyApp/script/../t"
      exists "/home/me/MyApp/script/../lib/MyApp"
@@ -1047,6 +1048,23 @@
 
 =head1 A STATIC DATABASE MODEL WITH C<DBIx::Class>
 
+First, let's be sure we have a recent versino of the DBIC helper,
+L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema>, by
+running this command:
+
+    $ perl -MCatalyst::Model::DBIC::Schema -e \
+        'print "$Catalyst::Model::DBIC::Schema::VERSION\n"'
+    0.23
+
+If you don't have version 0.23 or higher, please run this command
+to install it directly from CPAN:
+
+    $ sudo cpan Catalyst::Model::DBIC::Schema
+
+And re-run the version print command to verify that you are now at 
+0.23 or higher.
+
+
 =head2 Create Static DBIC Schema Files
 
 Unlike the previous DBIC section where we had C<create=dynamic>
@@ -1064,7 +1082,8 @@
 
 Now regenerate the schema using the C<create=static> option:
 
-    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static dbi:SQLite:myapp.db
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
+        create=static components=TimeStamp dbi:SQLite:myapp.db
      exists "/home/me/MyApp/script/../lib/MyApp/Model"
      exists "/home/me/MyApp/script/../t"
     Dumping manual schema for MyApp::Schema to directory /home/me/MyApp/script/../lib ...
@@ -1083,8 +1102,9 @@
 class (L<DBIx::Class::Schema::Loader|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 C<Schema.pm> only contains a call to the 
-C<load_classes> method.  You will also find that C<lib/MyApp> contains 
-a C<Schema> subdirectory, with files inside this directory named 
+C<load_namespaces> method.  You will also find that C<lib/MyApp> 
+contains a C<Schema> subdirectory, which then has a subdirectory 
+called "Result".  This "Result" subdirectory then has files named 
 according to each of the tables in our simple database (C<Authors.pm>, 
 C<BookAuthors.pm>, and C<Books.pm>).  These three files are called 
 "Result Classes" in DBIC nomenclature. Although the Result Class files 
@@ -1094,39 +1114,64 @@
 L<Catalyst::Manual::Tutorial::BasicCRUD/EXPLORING THE POWER OF DBIC>.
 
 The idea with the Result Source files created under 
-C<lib/MyApp/Schema> by the C<create=static> option is to only edit the 
-files below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> warning. 
-If you place all of your changes below that point in the file, you can 
-regenerate the automatically created information at the top of each 
-file should your database structure get updated.
+C<lib/MyApp/Schema/Result> by the C<create=static> option is to only 
+edit the files below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> 
+warning. If you place all of your changes below that point in the 
+file, you can regenerate the automatically created information at the 
+top of each file should your database structure get updated.
 
 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/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 C<Schema.pm> will load each of the "result 
-class" files from the C<lib/MyApp/Schema> subdirectory.  The end 
-result is that Catalyst will dynamically create three table-specific 
-Catalyst models every time the application starts (you can see these 
-three model files listed in the debug output generated when you launch 
-the application).
+call to C<load_namespaces> in C<Schema.pm> will load each of the 
+"Result Class" files from the C<lib/MyApp/Schema/Result> subdirectory. 
+The final outcome is that Catalyst will dynamically create three 
+table-specific Catalyst models every time the application starts (you 
+can see these three model files listed in the debug output generated 
+when you launch the application).
 
-B<NOTE:> The version of 
-L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> in 
-Debian 5 uses the older DBIC C<load_classes> vs. the newer 
-C<load_namspaces> technique.  For new applications, please try to use 
-C<load_namespaces> since it more easily supports a very useful DBIC
-technique called "ResultSet Classes."  We will migrate to 
-C<load_namespaces> in Chapter 4 (BasicCRUD) of this tutorial.
+B<NOTE:> Older versions of 
+L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> use the 
+deprecated DBIC C<load_classes> technique instead of the newer 
+C<load_namspaces>.  For new applications, please try to use 
+C<load_namespaces> since it more easily supports a very useful DBIC 
+technique called "ResultSet Classes."  If you need to convert an 
+existing application from "load_classes" to "load_namespaces," you can 
+use this process to automate the migration (but first make sure you 
+have v0.23 C<Catalyst::Model::DBIC::Schema> as discussed above):
 
+    $ # First delete the existing schema file to disable "compatibility" mode
+    $ rm lib/MyApp/Schema.pm
+    $
+    $ # Then re-run the helper to build the files for "load_namespaces"
+    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
+        create=static components=TimeStamp dbi:SQLite:myapp.db
+    $
+    $ # Now convert the existing files over
+    $ cd lib/MyApp/Schema
+    $ perl -MIO::All -e 'for (@ARGV) { my $s < io($_); $s =~ s/.*\n\# You can replace.*?\n//s;
+          $s =~ s/'MyApp::Schema::/'MyApp::Schema::Result::/g; my $d < io("Result/$_");
+          $d =~ s/1;\n?//; "$d$s" > io("Result/$_"); }' *.pm
+    $ cd ../../..
+    $
+    $ # And finally delete the old files
+    $ rm lib/MyApp/Schema/*.pm
 
-=head2 Updating the Generated DBIC Schema Files
+The "C<perl -MIO::ALL ...>" script will copy all the customized 
+relationship (and other) information below "C<# DO NOT MODIFY>" line 
+from the old files in C<lib/MyApp/Schema> to the new files in 
+C<lib/MyApp/Schema/Result> (we will be starting to add some 
+"customized relationship information in the section below).
 
+
+=head2 Updating the Generated DBIC Result Class Files
+
 Let's manually add some relationship information to the auto-generated 
 Result Class files. (Note: if you are using a database other than 
 SQLite, such as PostgreSQL, then the relationship could have been 
 automatically placed in the Result Class files.  If so, you can skip 
-this step.)  First edit C<lib/MyApp/Schema/Books.pm> and add the 
+this step.)  First edit C<lib/MyApp/Schema/Result/Books.pm> and add the 
 following text below the C<# You can replace this text...> comment:
 
     #
@@ -1138,7 +1183,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(book_authors => 'MyApp::Schema::BookAuthors', 'book_id');
+    __PACKAGE__->has_many(book_authors => 'MyApp::Schema::Result::BookAuthors', 'book_id');
     
     # many_to_many():
     #   args:
@@ -1178,7 +1223,7 @@
 Note that you cannot define a C<many_to_many> relationship without 
 also having the C<has_many> relationship in place.
 
-Then edit C<lib/MyApp/Schema/Authors.pm> and add relationship
+Then edit C<lib/MyApp/Schema/Result/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):
 
@@ -1191,7 +1236,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(book_author => 'MyApp::Schema::BookAuthors', 'author_id');
+    __PACKAGE__->has_many(book_author => 'MyApp::Schema::Result::BookAuthors', 'author_id');
     
     # many_to_many():
     #   args:
@@ -1202,7 +1247,7 @@
     __PACKAGE__->many_to_many(books => 'book_author', 'book');
 
 Finally, do the same for the "join table,"
-C<lib/MyApp/Schema/BookAuthors.pm>:
+C<lib/MyApp/Schema/Result/BookAuthors.pm>:
 
     #
     # Set relationships:
@@ -1213,14 +1258,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::Books', 'book_id');
+    __PACKAGE__->belongs_to(book => 'MyApp::Schema::Result::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::Authors', 'author_id');
+    __PACKAGE__->belongs_to(author => 'MyApp::Schema::Result::Authors', 'author_id');
 
 
 =head2 Run The Application
@@ -1233,7 +1278,7 @@
 
 Make sure that the application loads correctly and that you see the
 three dynamically created model class (one for each of the
-table-specific schema classes we created).
+Result Classes we created).
 
 Then hit the URL L<http://localhost:3000/books/list> with your browser 
 and be sure that the book list is displayed via the relationships 

Modified: Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial.pod
===================================================================
--- Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial.pod	2009-03-11 16:46:02 UTC (rev 9494)
+++ Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial.pod	2009-03-11 17:03:37 UTC (rev 9495)
@@ -153,15 +153,15 @@
 
 =item *
 
-Create a Catalyst View Using TTSite
+Create a Catalyst View
 
 =item *
 
-Globally Customize Every View
+Create a TT Template Page
 
 =item *
 
-Create a TT Template Page
+Test Run The Application
 
 =back
 
@@ -183,10 +183,38 @@
 
 =item *
 
-RUN THE APPLICATION
+ENABLE THE MODEL IN THE CONTROLLER
 
+=over 4
+
 =item *
 
+Test Run The Application
+
+=back
+
+=item *
+
+CREATE A WRAPPER FOR THE VIEW
+
+=over 4
+
+=item *
+
+Configure TT.pm For The Wrapper
+
+=item *
+
+Create the Wrapper Template File and Stylesheet
+
+=item *
+
+Test Run The Application
+
+=back
+
+=item *
+
 A STATIC DATABASE MODEL WITH DBIx::Class
 
 =over 4
@@ -199,11 +227,15 @@
 
 Updating the Generated DBIC Schema Files
 
+=item *
+
+Run The Application
+
 =back
 
 =item *
 
-RUN THE APPLICATION
+UPDATING THE VIEW
 
 =item *
 
@@ -211,7 +243,7 @@
 
 =item *
 
-UPDATING THE VIEW
+OPTIONAL INFORMATION
 
 =over 4
 
@@ -261,6 +293,22 @@
 
 =item *
 
+CONVERT TO A CHAINED ACTION
+
+=over 4
+
+=item *
+
+Try the Chained Action
+
+=item *
+
+Refactor to Use a "Base" Method to Start the Chains
+
+=back
+
+=item *
+
 MANUALLY BUILDING A CREATE FORM
 
 =over 4
@@ -295,6 +343,10 @@
 
 =item *
 
+Add a Common Method to Retrieve a Book for the Chain
+
+=item *
+
 Add a Delete Action to the Controller
 
 =item *
@@ -319,9 +371,37 @@
 
 =back
 
+=item *
+
+EXPLORING THE POWER OF DBIC
+
+=over 4
+
+=item *
+
+Add Datetime Columns to Our Existing Books Table
+
+=item *
+
+Update DBIC to Automatically Handle the Datetime Columns
+
+=item *
+
+Create a ResultSet Class
+
+=item *
+
+Chaining ResultSets
+
+=item *
+
+Adding Methods to Result Classes
+
 =back
 
+=back
 
+
 =head2 L<Chapter 5: Authentication|Catalyst::Manual::Tutorial::Authentication>
 
 Note: Click on the heading in the previous line to jump to the actual 
@@ -457,27 +537,11 @@
 
 =item *
 
-ENABLE ACL-BASED AUTHORIZATION
+ENABLE MODEL-BASED AUTHORIZATION
 
-=over 4
-
-=item *
-
-Add the Catalyst::Plugin::Authorization::ACL Plugin
-
-=item *
-
-Add ACL Rules to the Application Class
-
-=item *
-
-Add a Method to Handle Access Violations
-
 =back
 
-=back
 
-
 =head2 L<Chapter 7: Debugging|Catalyst::Manual::Tutorial::Debugging>
 
 Note: Click on the heading in the previous line to jump to the actual 
@@ -497,6 +561,10 @@
 
 DEBUGGING MODULES FROM CPAN
 
+=item *
+
+TT DEBUGGING
+
 =back
 
 

Modified: Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual.pm
===================================================================
--- Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual.pm	2009-03-11 16:46:02 UTC (rev 9494)
+++ Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual.pm	2009-03-11 17:03:37 UTC (rev 9495)
@@ -6,6 +6,8 @@
 use strict;
 use warnings;
 
+our $VERSION = '5.7019';
+
 =head1 NAME
 
 Catalyst::Manual - The Catalyst developer's manual
@@ -67,6 +69,4 @@
 
 =cut
 
-our $VERSION = '5.7018';
-
 1;




More information about the Catalyst-commits mailing list