Point users to RT
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / 03_MoreCatalystBasics.pod
index 23c6077..89f6330 100644 (file)
@@ -145,7 +145,7 @@ The C<-d> option to C<script/myapp_server.pl>
 =item *
 
 The C<CATALYST_DEBUG=1> environment variable (or set it to
-zero to templorarily disable debug output).
+zero to temporarily disable debug output).
 
 =back
 
@@ -229,7 +229,7 @@ Don't let these variations confuse you -- they all accomplish the same
 result.
 
 This tells Catalyst to start using one additional plugin, 
-L<Catalyst::Plugin::StackTrace|Catalyst::Plugin::StackTrace>, to add a 
+L<Catalyst::Plugin::StackTrace>, to add a 
 stack trace to the standard Catalyst "debug screen" (the screen 
 Catalyst sends to your browser when an error occurs). Be aware that 
 L<StackTrace|Catalyst::Plugin::StackTrace> output appears in your 
@@ -303,9 +303,9 @@ and add the following method to the controller:
     
         # Retrieve all of the book records as book model objects and store in the
         # stash where they can be accessed by the TT template
-        # $c->stash->{books} = [$c->model('DB::Book')->all];
+        # $c->stash(books => [$c->model('DB::Book')->all]);
         # But, for now, use this code until we create the model later
-        $c->stash->{books} = '';
+        $c->stash(books => '');
     
         # 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
@@ -345,7 +345,7 @@ method" that you don't want to be an action at all, then just define
 the method without any attribute -- you can call it in your code, but 
 the Catalyst dispatcher will ignore it.)
 
-There are five types of "special" build-in C<:Private> actions: 
+There are five types of "special" built-in C<:Private> actions:
 C<begin>, C<end>, C<default>, C<index>, and C<auto>.
 
 =over 4
@@ -436,45 +436,74 @@ but its use is now deprecated.
 Enter the following command to enable the C<TT> style of view
 rendering for this tutorial:
 
-    $ script/myapp_create.pl view TT TT
+    $ script/myapp_create.pl view HTML TT
      exists "/home/me/MyApp/script/../lib/MyApp/View"
      exists "/home/me/MyApp/script/../t"
-     created "/home/me/MyApp/script/../lib/MyApp/View/TT.pm"
-     created "/home/me/MyApp/script/../t/view_TT.t"
+     created "/home/me/MyApp/script/../lib/MyApp/View/HTML.pm"
+     created "/home/me/MyApp/script/../t/view_HTML.t"
 
-This simply creates a view called C<TT> (the second 'TT' argument) in 
-a file called C<TT.pm> (the first 'TT' argument). It is now up to you 
-to decide how you want to structure your view layout.  For the 
-tutorial, we will start with a very simple TT template to initially 
-demonstrate the concepts, but quickly migrate to a more typical 
-"wrapper page" type of configuration (where the "wrapper" controls the 
-overall "look and feel" of your site from a single file or set of 
-files).
+This simply creates a view called C<HTML> in a file called C<HTML.pm> (the first
+argument). It is now up to you to decide how you want to structure your view
+layout.  For the tutorial, we will start with a very simple TT template to
+initially demonstrate the concepts, but quickly migrate to a more typical
+"wrapper page" type of configuration (where the "wrapper" controls the overall
+"look and feel" of your site from a single file or set of files).
 
-Edit C<lib/MyApp/View/TT.pm> and you should see that the default
-contents contains something similar to the following:
+Edit C<lib/MyApp/View/HTML.pm> and you should see
+something similar to the following:
 
-    __PACKAGE__->config(TEMPLATE_EXTENSION => '.tt');
+    __PACKAGE__->config(
+        TEMPLATE_EXTENSION => '.tt',
+        render_die => 1,
+    );
 
 And update it to match:
 
     __PACKAGE__->config(
         # Change default TT extension
         TEMPLATE_EXTENSION => '.tt2',
-        # Set the location for TT files
-        INCLUDE_PATH => [
-                MyApp->path_to( 'root', 'src' ),
+        render_die => 1,
+    );
+
+This changes the default extension for Template Toolkit from '.tt' to
+'.tt2'.
+
+You can also configure components in your application class. For example,
+Edit C<lib/MyApp.pm> and you should see that the default:
+
+    __PACKAGE__->setup;
+
+Above this, add config:
+
+    __PACKAGE__->config(
+        'View::HTML' => {
+            #Set the location for TT files
+            INCLUDE_PATH => [
+                __PACKAGE__->path_to( 'root', 'src' ),
             ],
+        },
     );
+    # This line was here already
+    __PACKAGE__->setup;
+
+This changes the base directory for your template files from
+C<root> to C<root/src>.
+
+The reason to do this outside the C<lib/MyApp/View/HTML.pm> file
+is that the template path is found with the C<path_to> method,
+to get a path relative to the application root (no matter where it
+is installed), but this requires the application to be loaded...
 
-B<NOTE:> Make sure to add a comma after '.tt2' outside the single
-quote.
+Trying to set this setting in the view means that you have a chicken
+and egg problem, in that the view requires the application to be loaded,
+but loading the application loads the view.
 
-This changes the default extension for Template Toolkit from '.tt' to 
-'.tt2' and changes the base directory for your template files from 
-C<root> to C<root/src>.  Stick with these conventions for the 
-tutorial, but feel free to use whatever options you desire in your 
-applications (as with most things Perl, there's more than one way to 
+Putting the configuration which depends on the application class into
+that class is the neatest way to avoid this issue.
+
+Please stick with the settings above for the duration of the
+tutorial, but feel free to use whatever options you desire in your
+applications (as with most things Perl, there's more than one way to
 do it...).
 
 B<Note:> We will use C<root/src> as the base directory for our 
@@ -483,7 +512,6 @@ C<root/src/_controller_name_/_action_name_.tt2>.  Another popular option is to
 use C<root/> as the base (with a full filename pattern of 
 C<root/_controller_name_/_action_name_.tt2>).
 
-
 =head2 Create a TT Template Page
 
 First create a directory for book-related TT templates:
@@ -523,10 +551,10 @@ looping, conditional logic, etc.  In general, TT simplifies the usual
 range of Perl operators down to the single dot (".") operator.  This
 applies to operations as diverse as method calls, hash lookups, and list
 index values (see
-L<http://search.cpan.org/perldoc?Template::Manual::Variables> for
+L<https://metacpan.org/module/Template::Manual::Variables> for
 details and examples).  In addition to the usual L<Template> module Pod
 documentation, you can access the TT manual at
-L<http://search.cpan.org/perldoc?Template::Manual>.
+L<https://metacpan.org/module/Template::Manual>.
 
 B<TIP:> While you can build all sorts of complex logic into your TT 
 templates, you should in general keep the "code" part of your 
@@ -682,7 +710,7 @@ applications rely on DBIx::Class, as will this tutorial.
 
 Although DBIx::Class has included support for a C<create=dynamic> mode 
 to automatically read the database structure every time the 
-application starts, it's use is no longer recommended.  While it can 
+application starts, its use is no longer recommended.  While it can
 make for "flashy" demos, the use of the C<create=static> 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 
@@ -692,23 +720,25 @@ framework, a technique that we see in Chapter 4).
 =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<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema>, so
+L<Catalyst::Model::DBIC::Schema>, so
 that we can take advantage of some recent enhancements in how
 foreign keys are handled with SQLite.  To check your version, 
 run this command:
 
     $ perl -MCatalyst::Model::DBIC::Schema -e \
         'print "$Catalyst::Model::DBIC::Schema::VERSION\n"'
-    0.39
+    0.4
 
 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.
 
-If you have less than v0.39, you will need to run this command to 
-install it directly from CPAN:
+If you are following along in Debian 5, you should have version 0.40 or 
+higher (shown above as "0.4" with the tailing zero removed). If you have 
+less than v0.39, you will need to run this command to install it 
+directly from CPAN: 
 
-    $ sudo cpan Catalyst::Model::DBIC::Schema
+    $ cpan -i Catalyst::Model::DBIC::Schema
 
 And re-run the version print command to verify that you are now at 
 0.39 or higher.
@@ -721,6 +751,8 @@ please be sure that you use version C<1.27> of L<DBD::SQLite> or later:
 
 Upgrade if you are not at version C<1.27> or higher.
 
+Also, remember to put a line requiring the version of the module
+you just installed into your Makefile.PL
 
 =head2 Create Static DBIx::Class Schema Files
 
@@ -821,7 +853,7 @@ when you launch the application).
 B<NOTE:> Older versions of 
 L<Catalyst::Model::DBIC::Schema|Catalyst::Model::DBIC::Schema> use the 
 deprecated DBIx::Class C<load_classes> technique instead of the newer 
-C<load_namspaces>.  For new applications, please try to use 
+C<load_namespaces>.  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 
@@ -857,7 +889,7 @@ and delete the next 2 lines):
     
         # Retrieve all of the book records as book model objects and store
         # in the stash where they can be accessed by the TT template
-        $c->stash->{books} = [$c->model('DB::Book')->all];
+        $c->stash(books => [$c->model('DB::Book')->all]);
     
         # 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
@@ -897,7 +929,7 @@ enter:
 
     $ export DBIC_TRACE=1
     $ script/myapp_server.pl -r 
-    
+
 This assumes you are using bash as your shell -- adjust accordingly if
 you are using a different shell (for example, under tcsh, use
 C<setenv DBIC_TRACE 1>).
@@ -934,7 +966,7 @@ display something like:
     | MyApp::Model::DB::Author                                        | class    |
     | MyApp::Model::DB::Book                                          | class    |
     | MyApp::Model::DB::BookAuthor                                    | class    |
-    | MyApp::View::TT                                                 | instance |
+    | MyApp::View::HTML                                               | instance |
     '-----------------------------------------------------------------+----------'
     
     [debug] Loaded Private actions:
@@ -1016,12 +1048,12 @@ will appear across your entire site/application instead of having to
 edit many individual files.
 
 
-=head2 Configure TT.pm For The Wrapper
+=head2 Configure HTML.pm For The Wrapper
 
 In order to create a wrapper, you must first edit your TT view and
 tell it where to find your wrapper file. 
 
-Edit you TT view in C<lib/MyApp/View/TT.pm> and change it to match the 
+Edit your TT view in C<lib/MyApp/View/HTML.pm> and change it to match the 
 following:
 
     __PACKAGE__->config(
@@ -1174,7 +1206,7 @@ provide lots of high-quality CSS functionality.
 Hit "Reload" in your web browser and you should now see a formatted 
 version of our basic book list. (Again, the development server should 
 have automatically restarted when you made changes to 
-C<lib/MyApp/View/TT.pm>. If you are not using the "-r" option, you will 
+C<lib/MyApp/View/HTML.pm>. If you are not using the "-r" option, you will 
 need to hit C<Ctrl-C> and manually restart it. Also note that the 
 development server does I<NOT> need to restart for changes to the TT and 
 static files we created and edited in the C<root> directory -- those 
@@ -1282,20 +1314,20 @@ above:
       { join_type => "LEFT" },
     );
 
-
 The arguments are similar, but see 
 L<DBIx::Class::Relationship/belongs_to> for the details.
-    
+
 Although recent versions of SQLite and L<DBIx::Class::Schema::Loader> 
 automatically handle the C<has_many> and C<belongs_to> relationships, 
-C<many_to_many> relationships currently need to be manually inserted. 
-To add a C<many_to_many> relationship, first edit 
+C<many_to_many> relationship bridges (not technically a relationship)
+currently need to be manually inserted. 
+To add a C<many_to_many> relationship bridge, first edit 
 C<lib/MyApp/Schema/Result/Book.pm> and add the following text below 
 the C<# You can replace this text...> comment:
 
     # many_to_many():
     #   args:
-    #     1) Name of relationship, DBIC will create accessor with this name
+    #     1) Name of relationship bridge, DBIC will create accessor with this name
     #     2) Name of has_many() relationship this many_to_many() is shortcut for
     #     3) Name of belongs_to() relationship in model class of has_many() above
     #   You must already have the has_many() defined to use a many_to_many().
@@ -1306,26 +1338,26 @@ file.  As with any Perl package, we need to end the last line with
 a statement that evaluates to C<true>.  This is customarily done with
 C<1;> on a line by itself.
 
-The C<many_to_many> relationship is optional, but it makes it
+The C<many_to_many> relationship bridge is optional, but it makes it
 easier to map a book to its collection of authors.  Without 
-it, we would have to "walk" though the C<book_author> table as in 
+it, we would have to "walk" through the C<book_author> table as in 
 C<$book-E<gt>book_author-E<gt>first-E<gt>author-E<gt>last_name> (we 
 will see examples on how to use DBIx::Class objects in your code soon, 
 but note that because C<$book-E<gt>book_author> can return multiple 
 authors, we have to use C<first> to display a single author). 
 C<many_to_many> allows us to use the shorter 
 C<$book-E<gt>author-E<gt>first-E<gt>last_name>. Note that you cannot 
-define a C<many_to_many> relationship without also having the 
+define a C<many_to_many> relationship bridge without also having the 
 C<has_many> relationship in place.
 
 Then edit C<lib/MyApp/Schema/Result/Author.pm> and add the reverse 
-C<many_to_many> relationship for C<Author> as follows (again, be careful 
+C<many_to_many> relationship bridge for C<Author> as follows (again, be careful 
 to put in above the C<1;> but below the C<# DO NOT MODIFY THIS OR 
 ANYTHING ABOVE!> comment): 
 
     # many_to_many():
     #   args:
-    #     1) Name of relationship, DBIC will create accessor with this name
+    #     1) Name of relationship bridge, DBIC will create accessor with this name
     #     2) Name of has_many() relationship this many_to_many() is shortcut for
     #     3) Name of belongs_to() relationship in model class of has_many() above
     #   You must already have the has_many() defined to use a many_to_many().
@@ -1336,7 +1368,7 @@ ANYTHING ABOVE!> comment):
 
 Run the Catalyst development server script with the C<DBIC_TRACE> option
 (it might still be enabled from earlier in the tutorial, but here is an
-alternate way to specify the option just in case):
+alternate way to specify the trace option just in case):
 
     $ DBIC_TRACE=1 script/myapp_server.pl -r
 
@@ -1345,8 +1377,7 @@ three dynamically created model class (one for each of the
 Result Classes we created).
 
 Then hit the URL L<http://localhost:3000/books/list> with your browser 
-and be sure that the book list still displays correctly. You can leave 
-the development server running for the next step if you wish.
+and be sure that the book list still displays correctly.
 
 B<Note:> You will not see the authors yet because the view does not yet 
 use the new relations. Read on to the next section where we update the 
@@ -1555,7 +1586,7 @@ has changed):
     
         # Retrieve all of the book records as book model objects and store in the
         # stash where they can be accessed by the TT template
-        $c->stash->{books} = [$c->model('DB::Book')->all];
+        $c->stash(books => [$c->model('DB::Book')->all]);
     
         # Set the TT template to use.  You will almost always want to do this
         # in your action methods (actions methods respond to user input in
@@ -1582,10 +1613,10 @@ In order to be able to use C<$c-E<gt>forward> and C<$c-E<gt>detach>
 later in the tutorial, you should remove the comment from the
 statement in C<sub list> in C<lib/MyApp/Controller/Books.pm>:
 
-    $c->stash->{template} = 'books/list.tt2';
+    $c->stash(template => 'books/list.tt2');
 
 Then delete the C<TEMPLATE_EXTENSION> line in
-C<lib/MyApp/View/TT.pm>.
+C<lib/MyApp/View/HTML.pm>.
 
 Check the L<http://localhost:3000/books/list> URL in your browser.
 It should look the same manner as with earlier sections.
@@ -1595,9 +1626,13 @@ It should look the same manner as with earlier sections.
 
 Kennedy Clark, C<hkclark@gmail.com>
 
-Please report any errors, issues or suggestions to the author.  The
-most recent version of the Catalyst Tutorial can be found at
+Feel free to contact the author for any errors or suggestions, but the
+best way to report issues is via the CPAN RT Bug system at
+<https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-Manual>.
+
+The most recent version of the Catalyst Tutorial can be found at
 L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial/>.
 
-Copyright 2006-2008, Kennedy Clark, under Creative Commons License
+Copyright 2006-2010, Kennedy Clark, under the
+Creative Commons Attribution Share-Alike License Version 3.0
 (L<http://creativecommons.org/licenses/by-sa/3.0/us/>).