Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Data-Printer CPAN distribution.

Report information
The Basics
Id: 79731
Status: rejected
Priority: 0/
Queue: Data-Printer

People
Owner: Nobody in particular
Requestors: colink [...] perlDreamer.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.33
Fixed in: (no value)



Subject: Data::Printer breaks cloning variables via Clone
Data::Printer is an awesome and very helpful module, but I found the hard way that using it seems to alter my data so that Clone cannot create copies of scalar references. This bug is a duplicate of the bug that I filed for Clone, since Data::Printer should not be touching/altering the data that it prints, and I'd like Clone to be able to handle as many edge cases as possible.
Subject: trial
Download trial
application/octet-stream 511b

Message body not shown because it is not plain text.

On Tue Sep 18 16:43:42 2012, colink@perlDreamer.com wrote: Show quoted text
> Data::Printer is an awesome and very helpful module, but I found the hard > way that using it seems to alter my data so that Clone cannot create > copies of scalar references. > > This bug is a duplicate of the bug that I filed for Clone, since > Data::Printer should not be touching/altering the data that it prints, > and I'd like Clone to be able to handle as many edge cases as possible.
Hi there! Thanks for the bug report and the test case :) As discussed in the Clone ticket, the data itself is not changed, but due to some mangling and peeking, Perl's internal representation of the data changes - and quite a bit while at it :( I guess this can be split in two issues: 1) why is Data::Printer changing the variable's internal representation; 2) why is Clone not able to clone that particular representation. Let's stick to (1) in this ticket, and leave (2) for the one in Clone's tracker.

Message body is not shown because it is too large.

Ok, it doesn't seem to be a bug in Data::Printer. Perl does not guarantee the internal representation of a variable is immutable during its life span, and Data::Printer of course doesn't write to your variable. However, Hash::Util::FieldHash's fieldhash(), used to keep track of circular references, is changing the variable's internal representation to something Clone's clone() can't process properly. More information is available in http://perldoc.perl.org/Hash/Util/FieldHash.html#How-field-hashes-work. Here's a simple way to reproduce the problem without using DDP: ------------8<------------ use strict; use warnings; use Hash::Util::FieldHash qw(fieldhash); use Clone qw(clone); my $var = {}; fieldhash my %hash; # this line is changing the # internal representation of $var exists $hash{ \$var }; my $cloned = clone($var); die "uh-oh" if $var == $cloned; ------------>8------------ If this turns out to be a bug in Hash::Util::FieldHash (a core module), then I'll change Data::Printer to use Scalar::Util's refaddr or something. But it looks like it's just an issue in Clone. Thanks a lot for letting me know of the issue, though. It's important that Data::Printer works as flawlessly as possible, so feel free to send any potential fixes to this on our end, and/or reopen this ticket if you feel the issue should be handled differently. Cheers!