Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

by pemungkah (Priest)
on Aug 07, 2009 at 15:41 UTC ( [id://786820] : note . print w/replies, xml ) Need Help??

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

You might look at Devel::Command, which I wrote when I needed to add commands to the debugger.

It's a bit of a hack, as it has to monkeypatch DB::DB with a version that has a Module::Pluggable command loader. A very small command module that just system()s the shell command you want may do it.

Replies are listed 'Best First'.
Re^4: [perldebugger] calling perldoc from within the debugger (inifile)
by LanX (Saint) on Aug 08, 2009 at 00:54 UTC
    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

      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 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 to achieve this... right?

        Cheers Rolf

        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