=head1 NAME Catalyst::Manual::Tutorial::Debugging - Catalyst Tutorial - Part 6: Debugging =head1 OVERVIEW This is B for the Catalyst tutorial. L =over 4 =item 1 L =item 2 L =item 3 L =item 4 L =item 5 L =item 6 B =item 7 L =item 8 L =item 9 L =back =head1 DESCRIPTION This part of the tutorial takes a brief look at the primary options available for troubleshooting Catalyst applications. Note that when it comes to debugging and troubleshooting, there are two camps: =over 4 =item * Fans of C and C statements embedded in the code. =item * Fans of interactive debuggers. =back Catalyst is able to easily accommodate both styles of debugging. =head1 LOG STATEMENTS Folks in the former group can use Catalyst's C<$c-Elog> facility. For example, if you add the following code to a controller action method: $c->log->debug("This is a test log message"); Then the Catalyst development server will display your message along with the other debug output. To accomplish the same thing in a TTSite view use: [% Catalyst.log.debug("This is a test log message") %] You can also use L in both Catalyst code (C<$c-Elog-Edumper($myvar)>) and TT templates (C<[% Dumper.dump(book) %]> as discussed in earlier parts of the tutorial. =head1 RUNNING CATALYST UNDER THE PERL DEBUGGER Members of the interactive debuggers fan club will also be at home with Catalyst applications. One approach to this style of Perl debugging is to embed breakpoints in your code. For example, open C in your editor and add the C line as follows inside the C method (I like to "left-justify" my debug statements so I don't forget to remove them, but you can obviously indent them if you prefer): sub list : Local { # 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) = @_; $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('MyAppDB::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'; } 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). To now run the Catalyst development server under the Perl debugger, simply prepend C to the front of C