Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: [perldebugger] calling perldoc from within the debugger (inifile)

by LanX (Saint)
on Aug 08, 2009 at 00:54 UTC ( [id://786968]=note: print w/replies, xml ) Need Help??


in reply to Re^3: [perldebugger] calling perldoc from within the debugger (inifile)
in thread [perldebugger] calling perldoc from within the debugger

Nice really nice! 8)

But actually I'm using the debugger just as a REPL (without the P) and never for debugging, don't you think that my small alias solution is just appropriate? I'm not sure if I'm going to system the script or better avoid forking by useing it as a module.

Anyway if your a debugger expert, do you know how I can configure that the returnvalue of each eval ist printed with x, such that I get a full REPL out of it?

(see also using perldebugger as REPL?)

Cheers Rolf

Replies are listed 'Best First'.
Re^5: [perldebugger] calling perldoc from within the debugger (inifile)
by pemungkah (Priest) on Sep 02, 2009 at 00:01 UTC
    Hm. Might be able to do it by altering sub eval() ... yes, quite easily!

    Setting $DB::onetimeDump to 'dump' and calling DB::eval will do exactly what you want. Try this in your .perldb:

    sub DB::new_eval { local $DB::onetimeDump = 'dump'; &DB::old_eval(@_); + } *DB::old_eval = \&DB::eval; *DB::eval = \&DB::new_eval;
    It's perldb.ini if you're on Windows. You get output like this:
    [tearought-lm|(none)]04:54 PM $ perl -de0 Loading DB routines from perl5db.pl version 1.31 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> [1..10] 0 ARRAY(0x800cc0) 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 DB<2>
    This is just copying the old eval to a new name, creating a new sub that calls it after setting up $onetimeDump property, and substituting the new sub for the old one. it's not perfect:
    DB<4> print "my father plays dominos\n" my father plays dominos 0 1 DB<5>
    but should basically do what you're looking for. You'd need to patch up the dumping function a little more for perfection.
      Thanx, look really easy ... nice work pemungkah! 8)

      I have to figure out a good automated context strategy...

      ... hmm ...I think it's appropriate to default to list evaluation like with the x-cmd since I can always use scalar to do otherwise.

      But it's somehow useless to get just one line with index 0 for dumping a scalar

      DB<4> print "my father plays dominos\n" my father plays dominos 0 1

      Do you know a way to change this behavior automatically for a one element list like with p-cmd?

      DB<4> print "my father plays dominos\n" 1my father plays dominos

      as far as I can understand from the docs of DB it's neccessary to manipulate dumpvar.pl to achieve this... right?

      Cheers Rolf

        What you're seeing here is an 'x' of the print's return value, which is of course 1 since the print succeeded. We can expand the replacement eval with a crude check for the function being a print, in which case we leave $onetimeDump off.
        sub smarter_eval { local $onetimeDump = 'dump' if $_[0] =~ /\Aprint\s*\(?/; old_eval(@_); }
      Thanks again, I'm using this now regularly! :)

      DB<26> 1..9,[a..b] => (1, 2, 3, 4, 5, 6, 7, 8, 9, ["a", "b"])

      to be precise I tweaked the debugger to use Data::Dump::qq() for printing.

      Cheers Rolf

        I think this is useful enough I should make it into a patch. I'll do that. It'll need a way to toggle it on and off, etc. but that's all a SMOP.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://786968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found