DEV Community

Discussion on: Debugging a web application in Perl

Collapse
 
grifferz profile image
grifferz • Edited

Would love to learn more about how you actually get a Perl web app to log the code it's executing. I assume you just have to get it to print them to STDERR?

Collapse
 
kes777 profile image
Eugen Konkov • Edited

When execution of the program reaches a subroutine call, a call to &DB::sub(args) is made instead, with $DB::sub set to identify the called subroutine. (This doesn't happen if the calling subroutine was compiled in the DB package.) $DB::sub normally holds the name of the called subroutine, if it has a name by which it can be looked up. Failing that, $DB::sub will hold a reference to the called subroutine. Either way, the &DB::sub subroutine can use $DB::sub as a reference by which to call the called subroutine, which it will normally want to do.

If the call is to an lvalue subroutine, and &DB::lsub is defined &DB::lsub(args) is called instead, otherwise falling back to &DB::sub(args).

perldoc.perl.org/perldebguts

Collapse
 
mjgardner profile image
Mark Gardner

I basically used a slimmed-down version of Devel::Trace::More, writing a DB::DB sub that got the currently-running code from caller() and then outputting the file name, line number and the line of code to STDERR. Then run perl with the -d switch, and you're done.