Convert schema to MyApp::Schema, convert model to DB, misc adjustments
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / Debugging.pod
index 6a958d3..90222e9 100644 (file)
@@ -1,10 +1,11 @@
 =head1 NAME
 
-Catalyst::Manual::Tutorial::Debugging - Catalyst Tutorial - Part 6: Debugging
+Catalyst::Manual::Tutorial::Debugging - Catalyst Tutorial - Part 7: Debugging
+
 
 =head1 OVERVIEW
 
-This is B<Part 6 of 9> for the Catalyst tutorial.
+This is B<Part 7 of 10> for the Catalyst tutorial.
 
 L<Tutorial Overview|Catalyst::Manual::Tutorial>
 
@@ -20,30 +21,34 @@ L<Catalyst Basics|Catalyst::Manual::Tutorial::CatalystBasics>
 
 =item 3
 
-L<Basic CRUD|Catalyst::Manual::Tutorial_BasicCRUD>
+L<More Catalyst Basics|Catalyst::Manual::Tutorial::MoreCatalystBasics>
 
 =item 4
 
-L<Authentication|Catalyst::Manual::Tutorial::Authentication>
+L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>
 
 =item 5
 
-L<Authorization|Catalyst::Manual::Tutorial::Authorization>
+L<Authentication|Catalyst::Manual::Tutorial::Authentication>
 
 =item 6
 
-B<Debugging>
+L<Authorization|Catalyst::Manual::Tutorial::Authorization>
 
 =item 7
 
-L<Testing|Catalyst::Manual::Tutorial::Testing>
+B<Debugging>
 
 =item 8
 
-L<AdvancedCRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
+L<Testing|Catalyst::Manual::Tutorial::Testing>
 
 =item 9
 
+L<Advanced CRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
+
+=item 10
+
 L<Appendices|Catalyst::Manual::Tutorial::Appendices>
 
 =back
@@ -79,7 +84,7 @@ following code to a controller action method:
 
     $c->log->info("Starting the foreach loop here");
 
-    $c->log->debug("Value of $id is: ".$id);
+    $c->log->debug("Value of \$id is: ".$id);
 
 Then the Catalyst development server will display your message along
 with the other debug output. To accomplish the same thing in a TTSite
@@ -88,7 +93,7 @@ view use:
     [% Catalyst.log.debug("This is a test log message") %]
 
 You can also use L<Data::Dumper|Data::Dumper> in both Catalyst code 
-(C<use Data::Dumper; $c-E<gt>log-E<gt>debug("$var is: ".Dumper($var));)>) 
+(C<use Data::Dumper; $c-E<gt>log-E<gt>debug("\$var is: ".Dumper($var));)>) 
 and TT templates (C<[% Dumper.dump(book) %]>.
 
 =head1 RUNNING CATALYST UNDER THE PERL DEBUGGER
@@ -102,7 +107,7 @@ C<DB::single=1> line as follows inside the C<list> method (I like to
 you can obviously indent them if you prefer):
 
     sub list : Local {
-        # Retrieve the usual perl OO '$self' for this object. $c is the Catalyst
+        # Retrieve the usual Perl OO '$self' for this object. $c is the Catalyst
         # 'Context' that's used to 'glue together' the various components
         # that make up the application
         my ($self, $c) = @_;
@@ -111,7 +116,7 @@ you can obviously indent them if you prefer):
             
         # 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('MyAppDB::Book')->all];
+        $c->stash->{books} = [$c->model('DB::Books')->all];
             
         # Set the TT template to use.  You will almost always want to do this
         # in your action methods.
@@ -121,6 +126,8 @@ you can obviously indent them if you prefer):
 This causes the Perl Debugger to enter "single step mode" when this command is 
 encountered (it has no effect when Perl is run without the C<-d> flag).
 
+B<NOTE:> The C<DB> here is the Perl Debugger, not the DB model.
+
 To now run the Catalyst development server under the Perl debugger, simply 
 prepend C<perl -d> to the front of C<script/myapp_server.pl>:
 
@@ -150,7 +157,7 @@ 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:40):
-    40:         $c->stash->{books} = [$c->model('MyAppDB::Book')->all];
+    40:         $c->stash->{books} = [$c->model('DB::Books')->all];
     
       DB<1>
 
@@ -172,7 +179,7 @@ output also shows up in the development server debug information.
 
 Next, list the methods available on our C<Book> model:
 
-      DB<1> m $c->model('MyAppDB::Book')
+      DB<1> m $c->model('DB::Books')
     ()
     (0+
     (bool
@@ -191,7 +198,7 @@ Next, list the methods available on our C<Book> model:
 
 We can also play with the model directly:
 
-      DB<2> x ($c->model('MyAppDB::Book')->all)[1]->title
+      DB<2> x ($c->model('DB::Books')->all)[1]->title
     SELECT me.id, me.title, me.rating FROM books me:
     0  'TCP/IP Illustrated, Volume 1'
 
@@ -202,7 +209,7 @@ argument to the C<x> command limits the depth of the dump to 4 levels):
 
       DB<3> x 4 $c->stash->{books}
     0  ARRAY(0xa8f3b7c)
-       0  MyApp::Model::MyAppDB::Book=HASH(0xb8e702c)
+       0  MyApp::Model::DB::Book=HASH(0xb8e702c)
           '_column_data' => HASH(0xb8e5e2c)
              'id' => 1
              'rating' => 5
@@ -249,6 +256,10 @@ copy of an installed module:
 
     mkdir -p lib/Module; cp `perldoc -l Module::Name` lib/Module/
 
+Note: If you are following along in Ubuntu, you will need to install
+the C<perl-doc> package to use the C<perldoc> command.  Use 
+C<sudo apt-get install perl-doc> to do that.
+
 For example, you could make a copy of 
 L<Catalyst::Plugin::Authentication|Catalyst::Plugin::Authentication>
 with the following command:
@@ -256,6 +267,9 @@ with the following command:
     mkdir -p lib/Catalyst/Plugin; cp \
         `perldoc -l Catalyst::Plugin::Authentication` lib/Catalyst/Plugin
 
+You can then use the local copy inside your project to place logging
+messages and/or breakpoints for further study of that module.
+
 B<Note:> Matt has also suggested the following tips for Perl 
 debugging:
 
@@ -282,7 +296,7 @@ Check if a modules contains a given method:
 For example:
 
     $ perl -MCatalyst::Plugin::Authentication -e \
-        'print Catalyst::Plugin::Authentication->can("prepare");'
+        'print Catalyst::Plugin::Authentication->can("user");'
     CODE(0x9c8db2c)
 
 If the method exists, the Perl C<can> method returns a coderef.
@@ -297,7 +311,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-Runtime/lib/Catalyst/Manual/Tutorial/>.
+L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/>.
 
 Copyright 2006, Kennedy Clark, under Creative Commons License
 (L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).