http://www.perlmonks.org?node_id=1037907


in reply to Re: Modifying SelfLoader to save eval() text
in thread Modifying SelfLoader to save eval() text

With Devel::Trepan commit 263c7bfce0 I now have everything solved. There could be a better solution, but this one has certain advantages.

I can now use the debugger to fully debug a little selfloader Perl script. Since the debugger has the text of the eval string now, it writes out a temporary file. You can now list the code or set line number breakpoints in it.

The last missing problem was making sure we hooked into a debugger-enabled version of SelfLoader rather than the one that comes with Perl. In order to do this, I now trap on use statements by inserting a code reference at the beginning of %INC. See the documentation on perldoc on require and how it uses %INC.

Specifically, my code returns a file-handle glob for my debugger-enabled SelfLoader when I see that is requested. It has to be a real glob rather than a scalar reference to a file handle, or else the lookup tacitly fails.

With this custom program added to %INC I can also do other cool things. Like trace or perhaps debug into use code!

So in closing, I'll say that I am amazed at how flexible Perl is. There are lots and lots of mechanisms there. But I am equally amazed at how difficult it is to provide good debugging facility. I think most people just live with things like not being able to list lines of selfloader code or other kinds of eval'd code. Probably many (like myself too often) have to rely on just print statements.

  • Comment on Re^2: Modifying SelfLoader to save eval() text