Merge from depluralization branch
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / CatalystBasics.pod
index 094813a..764566a 100644 (file)
@@ -1,11 +1,11 @@
 =head1 NAME
 
-Catalyst::Manual::Tutorial::CatalystBasics - Catalyst Tutorial - Part 2: Catalyst Application Development Basics
+Catalyst::Manual::Tutorial::CatalystBasics - Catalyst Tutorial - Chapter 2: Catalyst Application Development Basics
 
 
 =head1 OVERVIEW
 
-This is B<Part 2 of 10> for the Catalyst tutorial.
+This is B<Chapter 2 of 10> for the Catalyst tutorial.
 
 L<Tutorial Overview|Catalyst::Manual::Tutorial>
 
@@ -56,8 +56,9 @@ L<Appendices|Catalyst::Manual::Tutorial::Appendices>
 
 =head1 DESCRIPTION
 
-In this part of the tutorial, we will create a very basic Catalyst web 
-application, demonstrating a number of powerful capabilities, such as:
+In this chapter of the tutorial, we will create a very basic Catalyst 
+web application, demonstrating a number of powerful capabilities, such 
+as:
 
 =over 4
 
@@ -108,7 +109,7 @@ to persist and restore objects to/from a relational database.
 
 You can checkout the source code for this example from the catalyst
 subversion repository as per the instructions in
-L<Catalyst::Manual::Tutorial::Intro|Catalyst::Manual::Tutorial::Intro>
+L<Catalyst::Manual::Tutorial::Intro|Catalyst::Manual::Tutorial::Intro>.
 
 
 =head1 CREATE A CATALYST PROJECT
@@ -121,9 +122,8 @@ Also note that as of Catalyst 5.7000, you will not have the helper
 scripts unless you install both L<Catalyst::Runtime|Catalyst::Runtime> 
 and L<Catalyst::Devel|Catalyst::Devel>.
 
-In this first part of the tutorial, use the Catalyst 
-C<catalyst.pl> script to initialize the framework for an 
-application called C<Hello>:
+In this first chapter of the tutorial, use the Catalyst C<catalyst.pl> 
+script to initialize the framework for an application called C<Hello>:
 
     $ catalyst.pl Hello
     created "Hello"
@@ -179,7 +179,8 @@ the base directory of your application, so change to the Hello
 directory.
 
 Run the following command to start up the built-in development web 
-server:
+server (make sure you didn't forget the "C<cd Hello>" from the 
+previous step):
 
     $ script/hello_server.pl
     [debug] Debug messages enabled
@@ -207,6 +208,7 @@ server:
     +----------------------+--------------------------------------+--------------+
     | /default             | Hello::Controller::Root              | default      |
     | /end                 | Hello::Controller::Root              | end          |
+    | /index               | Hello::Controller::Root              | index        |
     '----------------------+--------------------------------------+--------------'
     
     [debug] Loaded Path actions:
@@ -216,25 +218,25 @@ server:
     | /                                   | /default                             |
     | /                                   | /index                               |
     '-------------------------------------+--------------------------------------'
-        
-    [info] Hello powered by Catalyst 5.7014
-    You can connect to your server at http://localhost:3000
+    
+    [info] Hello powered by Catalyst 5.80003
+    You can connect to your server at http://debian:3000
 
-Point your web browser to 
-L<http://localhost:3000|http://localhost:3000> (substituting a 
+Point your web browser to L<http://localhost:3000> (substituting a 
 different hostname or IP address as appropriate) and you should be 
-greeted by the Catalyst welcome screen.  Information similar to the 
-following should be appended to the logging output of the development 
-server:
-
-    [info] *** Request 1 (1.000/s) [10301] [Sun Nov 23 10:11:36 2008] ***
-    [debug] "GET" request for "/" from "127.0.0.1"
-    [info] Request took 0.017964s (55.667/s)
+greeted by the Catalyst welcome screen (if you get some other welcome 
+screen or an "Index" screen, you probably forgot to specify port 3000 
+in your URL).  Information similar to the following should be appended 
+to the logging output of the development server:
+
+    [info] *** Request 1 (0.005/s) [20712] [Sun Mar  8 15:49:09 2009] ***
+    [debug] "GET" request for "/" from "1.1.1.98"
+    [info] Request took 0.007342s (136.203/s)
     .----------------------------------------------------------------+-----------.
     | Action                                                         | Time      |
     +----------------------------------------------------------------+-----------+
-    | /default                                                       | 0.000540s |
-    | /end                                                           | 0.001246s |
+    | /index                                                         | 0.000491s |
+    | /end                                                           | 0.000595s |
     '----------------------------------------------------------------+-----------'
 
 Press Ctrl-C to break out of the development server.
@@ -302,6 +304,9 @@ file:
         $c->response->body("Hello, World!");
     }
 
+B<TIP>: See Appendix 1 for tips on removing the leading spaces when
+cutting and pasting example code from POD-based documents.
+
 Here you're sending your own string to the webpage.
 
 Save the file, start the server (stop and restart it if it's still 
@@ -323,13 +328,28 @@ To create a TT view, run:
     $ script/hello_create.pl view TT TT
 
 This creates the C<lib/Hello/View/TT.pm> module, which is a subclass of 
-C<Catalyst::View::TT>. The "view" keyword tells the create script that 
-you are creating a view, the second "TT" tells it that you are creating 
-a Template Toolkit view, and the first "TT" tells the script to name 
-the View module "TT.pm", which is a commonly used name for TT views. 
-(You can name it anything you want, such as "HTML.pm".) If you look at 
-TT.pm, you will find that it only contains a config statement to set 
-the TT extension to ".tt".
+C<Catalyst::View::TT>. 
+
+=over 4
+
+=item *
+
+The "view" keyword tells the create script that you are creating a view.
+
+=item *
+
+The first "TT" tells the script to name the View module "TT.pm", which is a
+commonly used name for TT views.  (You can name it anything you want, such as
+"HTML.pm".)
+
+=item *
+
+The final "TT" tells it that you are creating a Template Toolkit view.
+
+=back
+
+If you look at C<lib/Hello/View/TT.pm> you will find that it only contains a
+config statement to set the TT extension to ".tt".
 
 Now that the TT.pm "View" exists, Catalyst will autodiscover it and be 
 able to use it to display the view templates, using the "process" 
@@ -339,21 +359,23 @@ Template Toolkit is a very full featured template facility, with
 excellent documentation at L<http://template-toolkit.org/>, 
 but since this is not a TT tutorial, we'll stick to only basic TT 
 usage here (and explore some of the more common TT features in later 
-parts of the tutorial).
+chapters of the tutorial).
 
 Create a C<root/hello.tt> template file (put it in the C<root> under 
 the C<Hello> directory that is the base of your application). Here is 
 a simple sample:
   
-    [% META title = 'Hello, World!' %]
     <p>
-        This is a TT view template, located in the 'root/' directory.
+        This is a TT view template, called '[% template.name %]'.
     </p>
 
 [% and %] are markers for the TT parts of the template. Inside you can 
-access Perl variables and classes, and use TT directives. The rest of 
-the template is normal HTML. Change the hello method in 
-C<lib/Hello/Controller/Root.pm> to the following:
+access Perl variables and classes, and use TT directives. In this 
+case, we're using a special TT variable that defines the name of the 
+template file (C<hello.tt>).  The rest of the template is normal HTML. 
+
+Change the hello method in C<lib/Hello/Controller/Root.pm> to the 
+following:
 
     sub hello : Global {
         my ( $self, $c ) = @_;
@@ -361,13 +383,13 @@ C<lib/Hello/Controller/Root.pm> to the following:
         $c->stash->{template} = 'hello.tt';
     }
 
-This time, instead of doing C<$c-E<gt>response->body()>, you are setting 
+This time, instead of doing C<$c-E<gt>response-E<gt>body()>, you are setting 
 the value of the "template" hash key in the Catalyst "stash", an area 
 for putting information to share with other parts of your application. 
 The "template" key determines which template will be displayed at the 
 end of the method. Catalyst controllers have a default "end" action 
 for all methods which causes the first (or default) view to be 
-rendered (unless there's a C<$c-E<gt>response->body()> statement). So your 
+rendered (unless there's a C<$c-E<gt>response-E<gt>body()> statement). So your 
 template will be magically displayed at the end of your method.
 
 After saving the file, restart the development server, and look at 
@@ -395,16 +417,23 @@ In C<lib/Hello/Controller/Site.pm>, add the following method:
         $c->stash->{template} = 'site/test.tt';
     }
 
-Notice the "Local" attribute on the method. This will allow the action 
-to be executed on the "controller/method" URL, or, in this case, 
-"site/test", instead of at the root site URL, like "Global". It's not 
-actually necessary to set the template value, since by default TT will 
-attempt to render a template that follows the naming pattern 
-"controller/method.tt", and we're following that pattern here, but in 
-other situations you will need to specify the template (such as if 
-you've "forwarded" to the method, or if it doesn't follow the default 
-naming convention). We've also put the variable "name" into the stash, 
-for use in the template.
+Notice the "Local" attribute on the C<test> method. This will cause 
+the C<test> action (now that we have assigned an action type to the 
+method it appears as a controller "action" to Catalyst) to be executed 
+on the "controller/method" URL, or, in this case, "site/test".  We 
+will see additional information on controller actions throughout the 
+rest of the tutorial, but if you are curious take a look at 
+L<Catalyst::Manual::Intro/Actions>.
+
+It's not actually necessary to set the template value as we do here. 
+By default TT will attempt to render a template that follows the 
+naming pattern "controller/method.tt", and we're following that 
+pattern here. However, in other situations you will need to specify 
+the template (such as if you've "forwarded" to the method, or if it 
+doesn't follow the default naming convention).
+
+We've also put the variable "username" into the stash, for use in the 
+template.
 
 Make a subdirectory "site" in the "root" directory. Copy the hello.tt 
 file into the directory as C<root/site/test.tt>, or create a new 
@@ -427,7 +456,7 @@ 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
-L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/>.
+L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/>.
 
 Copyright 2006-2008, Kennedy Clark & Gerda Shank, under Creative Commons License
 (L<http://creativecommons.org/licenses/by-sa/3.0/us/>).