X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2F03_MoreCatalystBasics.pod;h=3b95f04f75fbb6771f1abb3f6e9bdf56fbc2ab60;hp=38497afa9d2383533709e33fc21a36c750ecfdee;hb=61cb69fd002171a4c8a0e6c1188dc3530b918993;hpb=39e260e93560242261572f530288ae0fe81aa4c6 diff --git a/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod b/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod index 38497af..3b95f04 100644 --- a/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod +++ b/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod @@ -200,20 +200,22 @@ For our application, we want to add one new plugin into the mix. To do this, edit C (this file is generally referred to as your I) and delete the lines with: - use Catalyst qw/-Debug - ConfigLoader - Static::Simple/; + use Catalyst qw/ + -Debug + ConfigLoader + Static::Simple + /; Then replace it with: # Load plugins use Catalyst qw/ - -Debug - ConfigLoader - Static::Simple - - StackTrace - /; + -Debug + ConfigLoader + Static::Simple + + StackTrace + /; B Recent versions of C have used a variety of techniques to load these plugins/flags. For example, you might see @@ -233,7 +235,7 @@ browser, not in the console window from which you're running your application, which is where logging output usually goes. Make sure when adding new plugins you also include them as a new -dependancy within the Makefile.PL file. For example, after adding +dependency within the Makefile.PL file. For example, after adding the StackTrace plugin the Makefile.PL should include the following line: @@ -306,7 +308,7 @@ and add the following method to the controller: # 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 # your controllers). - $c->stash->{template} = 'books/list.tt2'; + $c->stash(template => 'books/list.tt2'); } B: See Appendix 1 for tips on removing the leading spaces when @@ -560,11 +562,12 @@ tutorial. =head1 CREATE A SQLITE DATABASE In this step, we make a text file with the required SQL commands to -create a database table and load some sample data. We will use -L, a popular database that is +create a database table and load some sample data. We will use +SQLite (L), a popular database that is lightweight and easy to use. Be sure to get at least version 3. Open C in your editor and enter: + PRAGMA foreign_keys = ON; -- -- Create a very simple database to hold book and author information -- @@ -575,8 +578,8 @@ C in your editor and enter: ); -- 'book_author' is a many-to-many join table between books & authors CREATE TABLE book_author ( - book_id INTEGER, - author_id INTEGER, + book_id INTEGER REFERENCES book(id) ON DELETE CASCADE ON UPDATE CASCADE, + author_id INTEGER REFERENCES author(id) ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY (book_id, author_id) ); CREATE TABLE author ( @@ -648,14 +651,14 @@ required if you do a single SQL statement on the command line). Use ".q" to exit from SQLite from the SQLite interactive mode and return to your OS command prompt. -Please note that here we have chosen to use 'singular' table names. This -is because the default inflection code for L -does NOT handle plurals. There has been much philosophical discussion -on whether table names should be plural or singular. There is no one -correct answer, as long as one makes a choice and remains consistent -with it. If you prefer plural table names (e.g. they are easier and -more natural to read) then you will need to pass it an inflect_map -option. See L for more information. +Please note that here we have chosen to use 'singular' table names. This is +because the default inflection code for older versions of +L does NOT handle plurals. There has been much +philosophical discussion on whether table names should be plural or singular. +There is no one correct answer, as long as one makes a choice and remains +consistent with it. If you prefer plural table names (e.g. you think that they +are easier to read) then see the documentation in +L (version 0.05 or greater). For using other databases, such as PostgreSQL or MySQL, see L. @@ -691,21 +694,23 @@ running this command: $ perl -MCatalyst::Model::DBIC::Schema -e \ 'print "$Catalyst::Model::DBIC::Schema::VERSION\n"' - 0.23 + 0.31 Please note the '\' above. Depending on your environment, you might be able to cut and paste the text as shown or need to remove the '\' character to that the command is all on a single line. -You should have version 0.23 or greater if you are following along +You should have version 0.31 or greater if you are following along with Debian 5. In other environments, you may need to 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. +0.31 or higher. +Please use version C<1.27> of L or later for proper foreign key +support. =head2 Create Static DBIx::Class Schema Files @@ -716,7 +721,8 @@ L and automatically build the required files for us: $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \ - create=static dbi:SQLite:myapp.db + create=static dbi:SQLite:myapp.db \ + on_connect_do="PRAGMA foreign_keys = ON" 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 ... @@ -755,11 +761,6 @@ into files. =item * -C causes the help to include the -L DBIC component. - -=item * - And finally, C is the standard DBI connect string for use with SQLite. @@ -802,32 +803,15 @@ 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 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 as discussed above): +use this process to automate the migration, but first make sure you have +version C<0.39> of L and +L version C<0.05000> or later. - $ # 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" + $ # Re-run the helper to upgrade for you $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \ - create=static 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 - -The "C" script will copy all the customized -relationship (and other) information below "C<# DO NOT MODIFY>" line -from the old files in C to the new files in -C (we will be starting to add some -"customized relationship information in the section below). - + create=static naming=current use_namespaces=1 \ + dbi:SQLite:myapp.db \ + on_connect_do="PRAGMA foreign_keys = ON" =head1 ENABLE THE MODEL IN THE CONTROLLER @@ -855,7 +839,7 @@ and delete the next 2 lines): # 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 # your controllers). - $c->stash->{template} = 'books/list.tt2'; + $c->stash(template => 'books/list.tt2'); } B: You may see the C<$c-Emodel('DB::Book')> un-commented @@ -907,9 +891,9 @@ display something like: [debug] Statistics enabled [debug] Loaded plugins: .----------------------------------------------------------------------------. - | Catalyst::Plugin::ConfigLoader 0.22 | - | Catalyst::Plugin::StackTrace 0.09 | - | Catalyst::Plugin::Static::Simple 0.21 | + | Catalyst::Plugin::ConfigLoader 0.27 | + | Catalyst::Plugin::StackTrace 0.11 | + | Catalyst::Plugin::Static::Simple 0.25 | '----------------------------------------------------------------------------' [debug] Loaded dispatcher "Catalyst::Dispatcher" @@ -950,7 +934,7 @@ display something like: | /books/list | /books/list | '-------------------------------------+--------------------------------------' - [info] MyApp powered by Catalyst 5.80003 + [info] MyApp powered by Catalyst 5.80013 You can connect to your server at http://debian:3000 B Be sure you run the C