garu / Data-Printer

colored pretty-print of Perl data structures and objects
100 stars 81 forks source link

Using DDP in Perl debugger prints data twice #176

Open clharrison opened 1 year ago

clharrison commented 1 year ago

I set up to use Data::Printer from the debugger using these instructions. It successfully rebound the debugger's p() command, except that it prints the data twice in succession:

Test program foo.pl:

> > #!/usr/bin/env perl
> > use v5.36;
> > 
> > say "Here is ~/.perldb:\n";
> > say qx(cat ~/.perldb);
> > 
> > my @xx = (qw/a b c d e/);
> > push @xx, [ 1,2,3 ];
> > 
> > my $foo = 1; # set breakpoint here and issue p @xx
> > 

Debug session:

> > $ perl -d ./foo.pl
> > 
> > Loading DB routines from perl5db.pl version 1.73
> > Editor support available.
> > 
> > Enter h or 'h h' for help, or 'man perldebug' for more help.
> > 
> > main::(./foo.pl:4):    say "Here is ~/.perldb:\n";
> >   DB<1> b 10
> >   DB<2> c
> > Here is ~/.perldb:
> > 
> > use DB::Pluggable;
> > DB::Pluggable->run_with_config( \'[DataPrinter]' );
> > 
> > main::(./foo.pl:10):    my $foo = 1; # use as breakpoint
> >   DB<2> p @xx
> > [
> >     [0] "a",
> >     [1] "b",
> >     [2] "c",
> >     [3] "d",
> >     [4] "e",
> >     [5] [
> >             [0] 1,
> >             [1] 2,
> >             [2] 3
> >         ]
> > ]
> > [
> >     [0] "a",
> >     [1] "b",
> >     [2] "c",
> >     [3] "d",
> >     [4] "e",
> >     [5] [
> >             [0] 1,
> >             [1] 2,
> >             [2] 3
> >         ]
> > ]
> > 
> > 
> 

Also note that the same documentation demonstrates how to bind an alias (px) to a subroutine that invokes Data::Printer::p(). The line reading print Data::Printer::p($expr) will print $expr twice; it should read simply Data::Printer::p($expr)

choroba commented 1 year ago

See the discussion at PerlMonks.

kcaran commented 1 year ago

Hi. I stumbled on this a couple of years ago. The issue is with DB::Pluggable. I've finally adopted the module and updated it with a fix. The new version is 1.12 and here is the repository:

github.com/kcaran/DB-Pluggable

You can now add Data::Printer configuration in your .perldb file if you wish. I found that redirecting the output to *DB::OUT helps with displaying unicode characters correctly. Here's mine:

use DB::Pluggable;
DB::Pluggable->run_with_config( \<<EOINI );
[DataPrinter]
sort_keys = 1
colored = 1
output = *DB::OUT
theme = Solarized
string_max = 8192
EOINI