Skip Menu |

This queue is for tickets about the Devel-REPL CPAN distribution.

Report information
The Basics
Id: 59888
Status: resolved
Priority: 0/
Queue: Devel-REPL

People
Owner: Nobody in particular
Requestors: andersk [...] mit.edu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.003011
Fixed in: (no value)



Subject: Can’t distinguish list from array ref
These two subs return different values, but re.pl doesn’t let you distinguish them because it automatically converts lists into arrays: $ sub foo { return 1, 2, 3 } $ sub bar { return [1, 2, 3] } $ foo $ARRAY1 = [ 1, 2, 3 ]; $ bar $ARRAY1 = [ 1, 2, 3 ];
Not true. What you are seeing is the default formatting of the output by Data::Dump::Streamer which requires its arguments to be references. If you print the results directly you get this: $ sub foo { return 1, 2, 3 } $ sub bar { return [1, 2, 3] } $ print foo() . "\n" 3 1 $ print bar() . "\n" ARRAY(0x22fbfc8) 1 $ print scalar(foo) . "\n" 3 1 $ print scalar(bar) . "\n" ARRAY(0x239ed90) 1 $ print @{scalar(bar)} . "\n" 3 1 Cheers, Chris On Fri Jul 30 17:58:15 2010, andersk wrote: Show quoted text
> These two subs return different values, but re.pl doesn’t let you > distinguish them because it automatically converts lists into arrays: > > $ sub foo { return 1, 2, 3 } > > $ sub bar { return [1, 2, 3] } > > $ foo > $ARRAY1 = [ > 1, > 2, > 3 > ]; > > $ bar > $ARRAY1 = [ > 1, > 2, > 3 > ];
Subject: Re: [rt.cpan.org #59888] Can’t distinguish list from array ref
Date: Fri, 30 Jul 2010 18:28:08 -0400 (EDT)
To: Chris Marshall via RT <bug-Devel-REPL [...] rt.cpan.org>
From: Anders Kaseorg <andersk [...] MIT.EDU>
On Fri, 30 Jul 2010, Chris Marshall via RT wrote: Show quoted text
> Not true. What you are seeing is the default formatting of the output > by Data::Dump::Streamer which requires its arguments to be references. > > If you print the results directly you get this:
Yes, obviously I can distinguish the outputs if I know what’s going on and I do something complicated to bypass Data::Dump::Streamer entirely. I don’t question that re.pl is executing the code correctly. I’m just asking for its default output format to be a little more useful. Data::Dump::Streamer itself has no trouble distinguishing these outputs: $ use Data::Dump::Streamer $ sub foo { return 1, 2, 3 } $ sub bar { return [1, 2, 3] } $ print Dump(foo) $VAR1 = 1; $VAR2 = 2; $VAR3 = 3; 1 $ print Dump(bar) $ARRAY1 = [ 1, 2, 3 ]; 1 so why can’t re.pl do that when I ask for just ‘foo’ and ‘bar’? Anders
Subject: Re: [rt.cpan.org #59888] Can’t distinguish list from array ref
Date: Fri, 30 Jul 2010 18:46:47 -0400 (EDT)
To: Chris Marshall via RT <bug-Devel-REPL [...] rt.cpan.org>
From: Anders Kaseorg <andersk [...] MIT.EDU>
On Fri, 30 Jul 2010, Anders Kaseorg wrote: Show quoted text
> so why can’t re.pl do that when I ask for just ‘foo’ and ‘bar’?
In particular, this patch seems to work: --- a/lib/Devel/REPL/Plugin/DDS.pm +++ b/lib/Devel/REPL/Plugin/DDS.pm @@ -6,19 +6,19 @@ use Data::Dump::Streamer (); around 'format_result' => sub { my $orig = shift; my $self = shift; - my $to_dump = (@_ > 1) ? [@_] : $_[0]; + my @to_dump = @_; my $out; - if (ref $to_dump) { - if (overload::Method($to_dump, '""')) { - $out = "$to_dump"; + if (@to_dump != 1 || ref $to_dump[0]) { + if (@to_dump == 1 && overload::Method($to_dump[0], '""')) { + $out = "@to_dump"; } else { my $dds = Data::Dump::Streamer->new; $dds->Freezer(sub { "$_[0]"; }); - $dds->Data($to_dump); + $dds->Data(@to_dump); $out = $dds->Out; } } else { - $out = $to_dump; + $out = $to_dump[0]; } $self->$orig($out); }; Result: $ sub foo { return 1, 2, 3 } $ sub bar { return [1, 2, 3] } $ foo $VAR1 = 1; $VAR2 = 2; $VAR3 = 3; $ bar $ARRAY1 = [ 1, 2, 3 ]; Anders
RT-Send-CC: andersk [...] MIT.EDU
Thanks for the patch. It is applied to Devel::REPL git repository. Assuming it tests ok, it should be available for the next Devel::REPL release. --Chris