Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Using Data::Printer from the Perl debugger

by LanX (Saint)
on Feb 25, 2023 at 17:55 UTC ( [id://11150601]=note: print w/replies, xml ) Need Help??


in reply to Using Data::Printer from the Perl debugger

Well I'd say you have to file a big report with those two modules involved.

DB::Pluggable and Data::Printer

I have a hunch that your problem here is that the debugger prints the result of your command while you trigger an internal print too.

If I were you I'd go with the approach to define an alias px

FWIW I successfully patched perl5db in the past to use Data::Dump you can find the discussions in the archives here.

HTH :)

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Using Data::Printer from the Perl debugger
by ibm1620 (Hermit) on Feb 25, 2023 at 21:00 UTC
    Thanks! Interestingly, the documentation specifies putting this into .perldb:
    $DB::alias{px} = 's/px/DB::px/'; sub px { my $expr = shift; require Data::Printer; print Data::Printer::p($expr); }
    Which causes $expr to be printed twice, once colorized, and once uncolorized, as one might expect. Changing that last line to
    Data::Printer::p($expr);
    fixes it.
      IMHO someone should file a bug report with both modules.

      I think one of the authors had the behavior of Data::Dump::pp() in mind which doesn't print by itself when called in a non void context.

      And the other one just copied the doc without testing.

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

        I'll be glad to, but I haven't done so before. Could you point me in the right direction?
Re^2: Using Data::Printer from the Perl debugger
by ibm1620 (Hermit) on Mar 02, 2023 at 02:42 UTC
    Using pure guesswork, I made one change to DB::Pluggable::Plugin::DataPrinter.pm:
    sub initialize { no warnings 'once'; # $DB::alias{p} = 's/^/use Data::Printer; /; eval $cmd'; $DB::alias{p} = 's/^/use Data::Printer; /'; }
    Now the p command prints its argument only once.

    I inserted print $cmd; before eval $cmd, entered p $my_var in the debugger, and it printed "p $my_var". Apparently the eval was unnecessary.

    FWIW.

      You are mangling internal p command and aliases, here are dragons.

      If I were you I'd stick with px

      Otherwise you need to look into the code of perl5db.pl

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

        You are mangling internal p command and aliases

        But isn't that exactly what the author(s) of DB::Pluggable::Plugin::DataPrinter.pm are doing? Or are you saying that approach isn't advisable?

        My only objection to px is I have to explicitly en-reference non-scalars, and I've become used to using the p command without doing that. Not a big deal.... :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-20 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found