X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2FMoreCatalystBasics.pod;h=092b8674cbf1ba386366a9406e1b690b522aa209;hp=c2edcbe1ca79370b75f915cd3d837fb09833f167;hb=98fd8420ab3b60bf830264311beebe0a5f334478;hpb=4d63a0d5e1abea67f1128011988b508f49caa1bc diff --git a/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod b/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod index c2edcbe..092b867 100644 --- a/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod +++ b/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod @@ -344,7 +344,7 @@ path. For example, "C<:Path('list')>" in C would match on the URL C but "C<:Path('/list')>" would match on C. You can use C<:Args()> to specify -how many arguments an action should except. See +how many arguments an action should accept. See L for more information and a few examples. @@ -499,6 +499,7 @@ Then create C in your editor and enter: [% book.title %] [% book.rating %] + [% END -%] @@ -644,33 +645,161 @@ L. =head1 DATABASE ACCESS WITH DBIx::Class -Catalyst can be used with virtually any form of datastore available via -Perl. For example, L can be -used to access databases through the traditional Perl C -interface. However, most Catalyst applications use some form of -object-relational mapping (ORM) technology to create objects associated -with tables in a relational database. Although L -has been a popular choice in the past, 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. +Catalyst can be used with virtually any form of datastore available +via Perl. For example, L +can be used to access databases through the traditional Perl C +interface or you can use a model to access files of any type on the +filesystem. However, most Catalyst applications use some form of +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 DBIx::Class, as will this tutorial. +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 Create a Dynamic DBIC Model -Use the C model helper option to build a model that -dynamically reads your database structure every time the application -starts: +=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 +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 DBIx::Class Schema Files + +Before you continue, make sure your C database file is in +the application's topmost directory. Now use the model helper with +the C option to read the database with +L and +automatically build the required files for us: $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \ - create=dynamic dbi:SQLite:myapp.db + create=static components=TimeStamp 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" - created "/home/me/MyApp/script/../lib/MyApp/Schema.pm" + Dumping manual schema for MyApp::Schema to directory /home/me/MyApp/script/../lib ... + Schema dump completed. created "/home/me/MyApp/script/../lib/MyApp/Model/DB.pm" created "/home/me/MyApp/script/../t/model_DB.t" +The C