Skip Menu |

This queue is for tickets about the XML-Simple CPAN distribution.

Report information
The Basics
Id: 89553
Status: resolved
Priority: 0/
Queue: XML-Simple

People
Owner: grantm [...] cpan.org
Requestors: DAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.20
Fixed in: 2.22



Subject: incorrect reference comparison
In order to track circular data structures, XML::Simple uses '==' for comparing references (v2.20, line 1427). This generates warnings or can even produce wrong results when references are blessed objects with overloaded operators (can be implicitly converted into scalars). The code example below demonstrates the problem. Hint1 : use Scalar::Util::refaddr for comparing references Hint2 (optimisation, not related to the problem) : keep track of seen references in a hashref instead of an arrayref. For big datastructures, doing a grep at each time is likely to be slower than an hashref lookup. #====================================== # code example below #====================================== $^W = 1; use XML::Simple; my $data = Foo->new(1, 2, 3); XMLout({Data => $data}); package Foo; use overload '""' => \&_stringify, fallback => 1, ; sub new { my $class = shift; bless [@_], $class; } sub _stringify { my $self = shift; return join ";", @$self; }
Release 2.22 of XML::Simple now compares references using Scalar::Util::refaddr as per your suggestion. Also it tracks the ancestors of a given data element using a hash rather than an array. Thanks for your report. Grant