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.
-(See L<Catalyst::Log> for more detail.) For example, if you add the
-following code to a controller action method:
+Folks in the former group can use Catalyst's C<$c-E<gt>log> facility.
+(See L<Catalyst::Log|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
-with the other debug output. To accomplish the same thing in a TTSite
-view use:
+with the other debug output. To accomplish the same thing in a TT
+template view use:
- [% Catalyst.log.debug("This is a test log message") %]
+ [% c.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));)>)
and TT templates (C<[% Dumper.dump(book) %]>.
+
=head1 RUNNING CATALYST UNDER THE PERL DEBUGGER
Members of the interactive-debugger fan club will also be at home with
# 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::Books')->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.
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>:
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::Books')->all];
+ 40: $c->stash->{books} = [$c->model('DB::Books')->all];
DB<1>
Next, list the methods available on our C<Book> model:
- DB<1> m $c->model('MyAppDB::Books')
+ DB<1> m $c->model('DB::Books')
()
(0+
(bool
We can also play with the model directly:
- DB<2> x ($c->model('MyAppDB::Books')->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'
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
Check the version of an installed module:
- perl -MModule::Name -e 'print $Module::Name::VERSION;'
+ perl -ME<lt>mod_nameE<gt> -e '"print $E<lt>mod_nameE<gt>::VERSION\n"'
For example:
=back
+=head1 TT DEBUGGING
+
+If you run into issues during the rendering of your template, it might
+be helpful to enable TT C<DEBUG> options. You can do this in a Catalyst
+environment by adding a C<DEBUG> line to the C<__PACKAGE__->config>
+declaration in C<lib/MyApp/View/TT.pm>:
+
+ __PACKAGE__->config({
+ TEMPLATE_EXTENSION => '.tt2',
+ DEBUG => 'undef',
+ });
+
+There are a variety of options you can use, such as 'undef', 'all',
+'service', 'context', 'parser' and 'provider'. See
+L<Template::Constants|Template::Constants> for more information
+(remove the C<DEBUG_> portion of the name shown in the TT docs and
+convert to lower case for use inside Catalyst).
+
+B<NOTE:> B<Please be sure to disable TT debug options before continuing
+with the tutorial> (especially the 'undef' option -- leaving this
+enabled will conflict with several of the conventions used by this
+tutorial to leave some variables undefined on purpose).
+
+
=head1 AUTHOR
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, Kennedy Clark, under Creative Commons License
-(L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).
+Copyright 2006-2008, Kennedy Clark, under Creative Commons License
+(L<http://creativecommons.org/licenses/by-sa/3.0/us/>).