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;
}