Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by LanX (Saint)
on Aug 06, 2009 at 13:26 UTC ( [id://786422]=note: print w/replies, xml ) Need Help??


in reply to Re: [perldebugger] calling perldoc from within the debugger
in thread [perldebugger] calling perldoc from within the debugger

Thanks!

And I just figured out how to preset aliases at startup.

There is a ini-file called .perldb sourced!

lanx@nc10-ubuntu:~$ cat .perldb sub afterinit { $DB::alias{ALIAS}='s/ALIAS/command/' }

so with your approach I may write

sub afterinit { $DB::doccmd='perldoc'; $DB::alias{doc}='s/doc/perldoc/'; }

so now I can type:

DB<2> doc -f print

and get better results...

... now I just have to figure out the best way to call a shellscript called doc, such that I have the same syntax from shellprompt (and than I can enrich the features of perldoc for my needs 8)

lanx@nc10-ubuntu:~$ doc -k '=='

Cheers Rolf

Replies are listed 'Best First'.
Re^3: [perldebugger] calling perldoc from within the debugger (inifile)
by pemungkah (Priest) on Aug 07, 2009 at 15:41 UTC
    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.

      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 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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-03-19 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found