use double bracketed formatting codes so < and > don't need to be escaped
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / 07_Debugging.pod
index 8afd049..faca57f 100644 (file)
@@ -59,16 +59,22 @@ L<Appendices|Catalyst::Manual::Tutorial::10_Appendices>
 This chapter of the tutorial takes a brief look at the primary options
 available for troubleshooting Catalyst applications.
 
+Source code for the tutorial in included in the F</home/catalyst/Final>
+directory of the Tutorial Virtual machine (one subdirectory per
+chapter).  There are also instructions for downloading the code in
+L<Catalyst::Manual::Tutorial::01_Intro>.
+
+
 Note that when it comes to debugging and troubleshooting, there are two
 camps:
 
 =over 4
 
-=item * 
+=item *
 
 Fans of C<log> and C<print> statements embedded in the code.
 
-=item * 
+=item *
 
 Fans of interactive debuggers.
 
@@ -79,12 +85,12 @@ Catalyst is able to easily accommodate both styles of debugging.
 
 =head1 LOG STATEMENTS
 
-Folks in the former group can use Catalyst's C<$c-E<gt>log> facility.
+Folks in the former group can use Catalyst's C<< $c->log >> facility.
 (See L<Catalyst::Log> for more detail.) For example, if you add the
 following code to a controller action method:
 
     $c->log->info("Starting the foreach loop here");
-    
+
     $c->log->debug("Value of \$id is: ".$id);
 
 Then the Catalyst development server will display your message along
@@ -103,9 +109,21 @@ severity/importance):
     $c->log->error
     $c->log->fatal
 
-You can also use L<Data::Dumper> in both Catalyst code
-(C<use Data::Dumper; $c-E<gt>log-E<gt>debug("\$var is: ".Dumper($var));)>)
-and TT templates (C<[% Dumper.dump(book) %]>.
+You can also use Data::Dumper in both Catalyst code and in TT templates.
+For use in Catalyst code:
+
+ use Data::Dumper;
+ $c->log->debug("\$var is: ".Dumper($c->stash->{something}));
+
+and TT templates:
+
+ [% USE Dumper ; Dumper.dump(c.stash.something) %].
+
+B<NOTE:> Whether you are a logging fanatic or not, we strongly recommend
+that you take advantage of L<Log::Log4perl> or L<Log::Dispatch>.  It's
+easy to use L<Catalyst::Log> with either of these and they will provide
+a huge amount of extra functionality that you will want in virtually
+every production application you run or support.
 
 
 =head1 RUNNING CATALYST UNDER THE PERL DEBUGGER
@@ -123,13 +141,13 @@ you can obviously indent them if you prefer):
         # 'Context' that's used to 'glue together' the various components
         # that make up the application
         my ($self, $c) = @_;
-    
+
     $DB::single=1;
-    
+
         # 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];
-    
+
         # Set the TT template to use.  You will almost always want to do this
         # in your action methods.
         $c->stash->{template} = 'books/list.tt2';
@@ -152,16 +170,16 @@ simply prepend C<perl -d> to the front of C<script/myapp_server.pl>:
 
 This will start the interactive debugger and produce output similar to:
 
-    $ perl -d script/myapp_server.pl  
-    
+    $ perl -d script/myapp_server.pl
+
     Loading DB routines from perl5db.pl version 1.3
     Editor support available.
-    
+
     Enter h or `h h' for help, or `man perldebug' for more help.
-    
+
     main::(script/myapp_server.pl:16):      my $debug         = 0;
-    
-      DB<1> 
+
+      DB<1>
 
 Press the C<c> key and hit C<Enter> to continue executing the Catalyst
 development server under the debugger.  Although execution speed will be
@@ -173,9 +191,9 @@ in.  Once the breakpoint is encountered in the
 C<MyApp::Controller::list> method, the console session running the
 development server will drop to the Perl debugger prompt:
 
-    MyApp::Controller::Books::list(/home/me/MyApp/script/../lib/MyApp/Controller/Books.pm:48):
+    MyApp::Controller::Books::list(/home/catalyst/MyApp/script/../lib/MyApp/Controller/Books.pm:48):
     48:         $c->stash->{books} = [$c->model('DB::Book')->all];
-    
+
       DB<1>
 
 You now have the full Perl debugger at your disposal.  First use the
@@ -185,9 +203,9 @@ C<single-step> into methods/subroutines):
 
       DB<1> n
     SELECT me.id, me.title, me.rating, me.created, me.updated FROM book me:
-    MyApp::Controller::Books::list(/home/me/MyApp/script/../lib/MyApp/Controller/Books.pm:53):
+    MyApp::Controller::Books::list(/home/catalyst/MyApp/script/../lib/MyApp/Controller/Books.pm:53):
     53:         $c->stash->{template} = 'books/list.tt2';
-    
+
       DB<1>
 
 This takes you to the next line of code where the template name is set.
@@ -208,7 +226,7 @@ Next, list the methods available on our C<Book> model:
     _calculate_score
     _collapse_cond
     <lines removed for brevity>
-    
+
       DB<2>
 
 We can also play with the model directly:
@@ -305,7 +323,7 @@ B<Note:> Matt has also suggested the following tips for Perl debugging:
 
 =over 4
 
-=item * 
+=item *
 
 Check the version of an installed module:
 
@@ -323,7 +341,7 @@ and if you are using bash aliases:
         or die qq(module \"\$m\" is not installed\\n); \
         print \$m->VERSION'"
 
-=item * 
+=item *
 
 Check if a modules contains a given method:
 
@@ -366,17 +384,19 @@ tutorial to leave some variables undefined on purpose).
 
 Happy debugging.
 
+
+You can jump to the next chapter of the tutorial here:
+L<Testing|Catalyst::Manual::Tutorial::08_Testing>
+
+
 =head1 AUTHOR
 
 Kennedy Clark, C<hkclark@gmail.com>
 
 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/>.
+L<https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-Manual>.
 
-Copyright 2006-2010, Kennedy Clark, under the
+Copyright 2006-2011, Kennedy Clark, under the
 Creative Commons Attribution Share-Alike License Version 3.0
 (L<http://creativecommons.org/licenses/by-sa/3.0/us/>).