Skip Menu |

This queue is for tickets about the Set-Scalar CPAN distribution.

Report information
The Basics
Id: 13816
Status: resolved
Priority: 0/
Queue: Set-Scalar

People
Owner: Nobody in particular
Requestors: Josh [...] allDucky.com
Cc:
AdminCc:

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



Subject: Set::Scalar blesses unblessed refs
Hi, I seem to have uncovered a bit of a bug in Set::Scalar::Base. The _strval subroutine will rebless unblessed objects. Here's a way to reproduce the error. my $x = new Set::Scalar( [] ) ; print $_ , "\n" foreach $x->members ; You'll notice that the output is ARRAY=ARRAY(0x893ebd4) instead of just ARRAY(0x893ebd4). I suggest the following alternative. use Scalar::Util ; sub _strval { my $class = ref $_[0]; return $_[0] unless $class; return sprintf("%s(%x)", $class, Scalar::Util::refaddr($_[0]) ); } This subroutine has been tested, and appears to work. The only drawback that I can think of is that data will not be serializable between diferent versions of Set::Scalar. If you want to be more creative, you can probably force backwards compatibility. Thanks, Josh
From: Josh [...] allDucky.com
Set::Scalar assumes that any ref is an object. This was a safe assumption in the old code because Set::Scalar inadvertently blessed all refs. However, it appears that this assumption makes my fix introduce new bugs into Set::Scalar. The first instance that I've found of this is in the _elements_as_string function. The original block is (around line 599) ... } elsif (ref $element && Scalar::Util::blessed($element) && $element->isa(__PACKAGE__)) { local $history{ $element_id } = 1; push @complex_elements, $element->as_string( \%history ); ... To fix this, change the the condition of the elsif to } elsif (Scalar::Util::blessed($element) && $element->isa(__PACKAGE__)) { By using the safer Scalar::Util::blessed() call, we avoid the error of calling a function on an unblessed ref. I sincerely hope that these changes can be incorporated into a future version of Scalar::Util. Thanks, Josh Danziger
Please see Set::Scalar 1.20.