in reply to Debugging a module?

Put $DB::single = 1; just before the first line you want to stop at in the module. I rarely use breakpoints with the perl debugger anymore, since that trick works just as well in BEGIN blocks as in regular code, and it works well as a conditional breakpoint too:

$DB::single = 1 if $name eq 'mark';

which I prefer for no apparent reason to

$DB::single = ($name eq 'mark');

Alternatively, you could put BEGIN { $DB::single = 1; } just before you use the module, but there's a good chance you'll end up stepping through a bunch of other modules you don't care about that way.

Replies are listed 'Best First'.
Re^2: Debugging a module?
by dstar (Scribe) on Apr 06, 2006 at 13:49 UTC
    If I do the $DB::single = 1 with a use statement, it breaks on the last line of the module -- which is '1;'. With a require statement, I get the results I mentioned easily. I haven't tried wrapping it in a BEGIN statement -- that's a good idea.
      Either your perl behaves very differently from mine, or I didn't describe it very well. If I use these two files:

      driver.pl

      use TestModule; print "I am exiting now.\n";

      TestModule.pm

      package TestModule; our $x = 0; $DB::single = 1; our $y = $x + 1; our $z = $y ** 3; sub blah { "blah!" } 1;

      ...and run perl -d driver.pl, the debugger immediately stops at the line our $y = $x + 1. Do you get different results?