Debugging Catalyst Applications
For an introduction to Catalyst debugging, see Catalyst::Manual::Tutorial::Debugging.
You may wish to run your application in debug mode with a different configuration file (e.g. specifying a test database). To tell the Config::Loader used by your app to load a different config file, set the MYAPP_CONFIG environment variable:
FOOAPP_CONFIG=fooapp_sqlite.conf script/fooapp_server.pl -d
To get a variable dump in the browser, append
?dump_info=1 at the end of the URL while you run the server in debug mode (
Debugging "live" Catalyst applications is possible with Komodo and might work with Eclipse+EPIC (please chip in if you have experience with the latter).
You don't want to step through all the Catalyst-specific code. Put a breakpoint (F9 in Komodo) directly in the file you wish to start debugging from (most of the time, a controller). Alternatively, you can insert
$DB::single = 1 statements where you want breakpoints in your application.
perl with the
-d flag to enable debugging:
perl -d script/myapp_server.pl
You can also debug how your application handles a request without running an HTTP server. To do this, run the
myapp_test.pl script, or any of the
.t scripts. They all use Catalyst::Test:
perl -d myapp_test.pl /troublemaker_url/foo
To debug remotely with Komodo, refer to ActiveState's article on Remote Debugging Perl with Komodo. In short, here's what to do:
wgetand unpack the perl debugging lib tgz
add the following to your
export PERL5LIB=/path/to/where/you/unpacked/the/tgz export PERLDB_OPTS="RemotePort=[IP of the Komodo machine]:9000"
on the remote host, run
perl -d myapp_test.pl http://mysite.com/troublemaker_url
Komodo will pop-up on your "Komodo machine" and ask to map the file ("Mapped URIs") to a Remote Account (Preferences -> Servers).
If the remote host can't connect to your Komodo machine (e.g. due to a firewall), you can do the following:
- Replace the
<IP of the Komodo machine>above with
- Setup an SSH connection from your debugging machine to your remote server and define the following S2C (server-to-client) forwarding rule:
localhost:9000. For Windows, an excellent SSH client that supports both client-to-server and server-to-client forwarding is Bitvise Tunnelier.
There are/were two issues with Komodo:
- (fixed in Komodo 5.1.3 or earlier) Komodo couldn't step past the
while ( accept( Remote, $daemon ) )loop in Catalyst::Engine::HTTP.
Stepping through scripts that use Catalyst::Test causes the following error message to be dumped in Komodo's Output pane:
Unexpected use of a standard filehandle while debugging: The STDOUT and STDERR handles have been tied for remote debugging, and can't be redirected in the code being debugged. Try adding untie(*STDOUT) if tied(*STDOUT); untie(*STDERR) if tied(*STDERR); to the code at /usr/lib/perl5/site_perl/5.8/HTTP/Request/AsCGI.pm line 124
This is currently tracked on ActiveState's Bugzilla queue for Komodo.
Alternatively, you can debug using perl's integrated debugger:
- start the
- enter the 'r' command to cause the debugger to enter the loop that waits for external actions
- press Ctrl+C
- let's say you want to set a breakpoint. Load the .pm you wish to set the breakpoint in, using
- list its source code with the
- set the breakpoint at the line you wish:
ragain to resume the server's execution
- navigate to http://yoursever:3000/your/url
- the debugger will now stop at your breakpoint
- inspect variables (
p perl_expressionor step through the code (
Catalyst::Plugin::FirePHP - causes Catalyst's debug calls to go to the FirePHP console. If you use Firebug (and you should), this saves having to switch between the remote server's console with the Catalyst application output, and the browser window.
Charles Web Debugging proxy - cross-Platform application, written in Java. It has Firefox/IE/Safari proxy autoconfiguration, AJAX debugging capabilities, and bandwidth throttling simulation.
Paros Proxy - written in Java and geared at evaluating the security of web applications.
If you're using DBIx::Class, set
DBIC_TRACE=1 when running your application.
- Catalyst::Manual::Tutorial::07_Debugging - introduction to Catalyst debugging
Showing changes from previous revision.