paperlined.org
dev > perl
document updated 4 months ago, on May 27, 2022

how to debug command-line apps

The built-in Perl debugger is extremely handy, as it lets you single-step through the code, and examine variables along the way.

It does have a learning curve though, so if you want something easier-to-use, there are other Perl debuggers available, including ones with GUIs and ones with browser front-ends.

how to debug cron jobs

Use this technique to capture the environment variables exactly as they are setup when running under cron, and then to restore that same environment when running manually under the command line. The script will pretty much still think it's running under cron.

how to debug CGI scripts and mod_perl scripts

Similar to the method used to debug cron scripts, you can use CGI::Capture to capture the environment when running under your normal webserver, and then restore that environment when running under a normal command-line terminal.

Another way is to use various "remote debugger" methods.

Apache::DB says it can run an interactive debugger under mod_perl, but I'm not sure how this magic works — it doesn't seem to use RemotePort anywhere

There's also CGI::Inspect which uses a slightly different technique.

Yet another way, there are several modules that purport to open an in-browser debugger, without really doing any sort of remote-debugging stuff... all in the same process maybe?