X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2FBasicCRUD.pod;h=7ae222ea085b2801fea6ffc350576efa210da90a;hp=0f7e68c6f3b4f78c5a5adea18fedcf72bcb23b3c;hb=a586a09f7f8230a94b28217806c008702a19803e;hpb=4b4d38842b2383a70a54bcadb493505950b469dd diff --git a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod index 0f7e68c..7ae222e 100644 --- a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod @@ -140,7 +140,7 @@ controller methods (at least the ones that directly handle user input), it then sets the template that should handle this request. -=head2 Include a Template for the C Action: +=head2 Include a Template for the 'url_create' Action: Edit C and then enter: @@ -188,7 +188,7 @@ variables. Other than that, the rest of the code should be familiar from the examples in Chapter 3. -=head2 Try the C Feature +=head2 Try the 'url_create' Feature If the application is still running from before, use C to kill it. Then restart the server: @@ -391,7 +391,7 @@ object. Click the "Return to list" link, you should find that there are now seven books shown (two copies of TCPIP_Illustrated_Vol-2). -=head2 Refactor to Use a "Base" Method to Start the Chains +=head2 Refactor to Use a 'base' Method to Start the Chains Let's make a quick update to our initial Chained action to show a little more of the power of chaining. First, open @@ -858,7 +858,7 @@ involves a second request), the C is cleared before it can be displayed. -=head2 Using C to Pass Query Parameters +=head2 Using 'uri_for' to Pass Query Parameters There are several ways to pass information across a redirect. One option is to use the C technique that we will see in Chapter 5 @@ -937,108 +937,6 @@ with Catalyst per se, you will almost certainly want to take advantage of them in your applications. -=head2 Convert to DBIC "load_namespaces" - -If you look back at -L you will recall that we load our DBIC Result Classes -(Books.pm, Authors.pm and BookAuthors.pm) with in -C with the C feature. Although -this method is perfectly valid, the DBIC community has migrated to a -newer C 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. - -If you are following along in Debian 5, you will need to upgrade your -version of -L 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 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 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 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 feature, DBIC automatically looks for -your Result Class files in a subdirectory of the Schema directory -called C (the files in C were already there -from Chapter 3 of the tutorial; the files in C -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 (or from -L) -to the corresponding files in C. If you take -this approach, be sure to add C<::Result> to the end of -C in all three files (for example, in C, the -"peer class" in the C relationship needs to be changed from -C to C). - -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