From: Kennedy Clark Date: Sun, 3 May 2009 19:27:11 +0000 (+0000) Subject: Convert to more of a mixture of "DBIC" and "DBIx::Class" as per suggestion from Castaway X-Git-Tag: v5.8005~158 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=commitdiff_plain;h=a46b474eb241c3eac09ac0cd8af400a864de3ee5 Convert to more of a mixture of "DBIC" and "DBIx::Class" as per suggestion from Castaway Remove out of date XSUB hack from Authorization.pod Other minor adjustments --- diff --git a/lib/Catalyst/Manual/Tutorial/Authorization.pod b/lib/Catalyst/Manual/Tutorial/Authorization.pod index e1d5496..7eb2a4e 100644 --- a/lib/Catalyst/Manual/Tutorial/Authorization.pod +++ b/lib/Catalyst/Manual/Tutorial/Authorization.pod @@ -174,14 +174,6 @@ updating C to match the following code: # Assign the Book object to the stash for display in the view $c->stash->{book} = $book; - # This is a hack to disable XSUB processing in Data::Dumper - # (it's used in the view). This is a work-around for a bug in - # the interaction of some versions or Perl, Data::Dumper & DBIC. - # You won't need this if you aren't using Data::Dumper (or if - # you are running DBIC 0.06001 or greater), but adding it doesn't - # hurt anything either. - $Data::Dumper::Useperl = 1; - # Set the TT template to use $c->stash->{template} = 'books/create_done.tt2'; } else { diff --git a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod index 74f7f2a..57e9419 100644 --- a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod @@ -953,7 +953,7 @@ This will modify the C table to include the two new fields and populate those fields with the current time. -=head2 Update DBIC to Automatically Handle the Datetime Columns +=head2 Update DBIx::Class to Automatically Handle the Datetime Columns Next, we should re-run the DBIC helper to update the Result Classes with the new fields: @@ -991,10 +991,11 @@ B the C<1;> on the last line): { data_type => 'datetime', set_on_create => 1, set_on_update => 1 }, ); -This will override the definition for these fields that Schema::Loader -placed at the top of the file. The C and -C options will cause DBIC to automatically update the -timestamps in these columns whenever a row is created or modified. +This will override the definition for these fields that Schema::Loader +placed at the top of the file. The C and +C options will cause DBIx::Class to automatically +update the timestamps in these columns whenever a row is created or +modified. To test this out, restart the development server using the C option: @@ -1039,7 +1040,7 @@ controller code. To illustrate the concept with a fairly simple example, let's create a method that returns books added in the last 10 minutes. Start by -making a directory where DBIC will look for our ResultSet Class: +making a directory where DBIx::Class will look for our ResultSet Class: mkdir lib/MyApp/Schema/ResultSet @@ -1115,20 +1116,20 @@ try a higher or lower value. =head2 Chaining ResultSets -One of the most helpful and powerful features in DBIC is that it allows -you to "chain together" a series of queries (note that this has nothing -to do with the "Chained Dispatch" for Catalyst that we were discussing -above). Because each ResultSet returns another ResultSet, you can take -an initial query and immediately feed that into a second query (and so -on for as many queries you need). Note that no matter how many -ResultSets you chain together, the database itself will not be hit until -you use a method that attempts to access the data. And, because this -technique carries over to the ResultSet Class feature we implemented in -the previous section for our "canned search", we can combine the two -capabilities. For example, let's add an action to our C -controller that lists books that are both recent I have "TCP" in -the title. Open up C and add the -following method: +One of the most helpful and powerful features in DBIx::Class is that +it allows you to "chain together" a series of queries (note that this +has nothing to do with the "Chained Dispatch" for Catalyst that we +were discussing above). Because each ResultSet returns another +ResultSet, you can take an initial query and immediately feed that +into a second query (and so on for as many queries you need). Note +that no matter how many ResultSets you chain together, the database +itself will not be hit until you use a method that attempts to access +the data. And, because this technique carries over to the ResultSet +Class feature we implemented in the previous section for our "canned +search", we can combine the two capabilities. For example, let's add +an action to our C controller that lists books that are both +recent I have "TCP" in the title. Open up +C and add the following method: =head2 list_recent_tcp @@ -1233,16 +1234,16 @@ more flexible at the same time. =head2 Adding Methods to Result Classes -In the previous two sections we saw a good example of how we could use -DBIC ResultSet Classes to clean up our code for an entire query (for -example, our "canned searches" that filtered the entire query). We -can do a similar improvement when working with individual rows as -well. Whereas the ResultSet construct is used in DBIC to correspond -to an entire query, the Result Class construct is used to represent a -row. Therefore, we can add row-specific "helper methods" to our Result -Classes stored in C. For example, open -C and add the following method -(as always, it must be above the closing "C<1;>"): +In the previous two sections we saw a good example of how we could use +DBIx::Class ResultSet Classes to clean up our code for an entire query +(for example, our "canned searches" that filtered the entire query). +We can do a similar improvement when working with individual rows as +well. Whereas the ResultSet construct is used in DBIC to correspond +to an entire query, the Result Class construct is used to represent a +row. Therefore, we can add row-specific "helper methods" to our Result +Classes stored in C. For example, open +C and add the following method (as +always, it must be above the closing "C<1;>"): # # Helper methods diff --git a/lib/Catalyst/Manual/Tutorial/Intro.pod b/lib/Catalyst/Manual/Tutorial/Intro.pod index b51f252..1a091a4 100644 --- a/lib/Catalyst/Manual/Tutorial/Intro.pod +++ b/lib/Catalyst/Manual/Tutorial/Intro.pod @@ -602,7 +602,7 @@ with the following commands: wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/MyApp_Chapter8.tgz tar zxvf MyApp_Chapter8.tgz cd MyApp - CATALYST_DEBUG=0 prove --lib lib t + CATALYST_DEBUG=0 prove --lib lib t If you wish to include the L section in your tests, substitute C for diff --git a/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod b/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod index b6f9e72..f3ff00e 100644 --- a/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod +++ b/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod @@ -499,6 +499,7 @@ Then create C in your editor and enter: [% book.title %] [% book.rating %] + [% END -%] @@ -653,18 +654,18 @@ object-relational mapping (ORM) technology to create objects associated with tables in a relational database. Matt Trout's L (abbreviated as "DBIC") has rapidly emerged as the Perl-based ORM technology of choice. Most new Catalyst -applications rely on DBIC, as will this tutorial. +applications rely on DBIx::Class, as will this tutorial. -Although DBIC has included support for a C mode to -automatically read the database structure every time the application -starts, it's use is no longer recommended. While it can make -for "flashy" demos, the use of the C mode we use below -can be implemented just as quickly and provides many advantages (such -as the ability to add your own methods to the overall DBIC framework, -a technique that we see in Chapter 4). +Although DBIx::Class has included support for a C mode +to automatically read the database structure every time the +application starts, it's use is no longer recommended. While it can +make for "flashy" demos, the use of the C mode we use +below can be implemented just as quickly and provides many advantages +(such as the ability to add your own methods to the overall DBIC +framework, a technique that we see in Chapter 4). -=head2 Make Sure You Have a Recent Version of the DBIC Model +=head2 Make Sure You Have a Recent Version of the DBIx::Class Model First, let's be sure we have a recent version of the DBIC helper, L, by @@ -683,7 +684,7 @@ And re-run the version print command to verify that you are now at 0.23 or higher. -=head2 Create Static DBIC Schema Files +=head2 Create Static DBIx::Class Schema Files Use the model helper with the C option to read the database with @@ -742,7 +743,7 @@ find that C contains a C 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, C, and C). These three -files are called "Result Classes" in DBIC nomenclature. Although the +files are called "Result Classes" in DBIx::Class nomenclature. Although the Result Class files are named after tables in our database, the classes correspond to the I that is returned by DBIC (more on this later, especially in @@ -768,7 +769,7 @@ when you launch the application). B Older versions of L use the -deprecated DBIC C technique instead of the newer +deprecated DBIx::Class C technique instead of the newer C. For new applications, please try to use C since it more easily supports a very useful DBIC technique called "ResultSet Classes." If you need to convert an @@ -990,8 +991,8 @@ books loaded by the C script above without any formatting. The rating for each book should appear on each row, but the "Author(s)" column will still be blank (we will fill that in later). -Also notice in the output of the C