Skip Menu |

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

Report information
The Basics
Id: 73063
Status: resolved
Priority: 0/
Queue: Data-Walk

People
Owner: GUIDO [...] cpan.org
Requestors: SREZIC [...] cpan.org
Cc: srezic [...] iconmobile.com
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 1.00
Fixed in: (no value)



Subject: Can ref(...) return a string with "="?
The source code of Data::Walk contains these lines (starting from line 93): my $ref = ref $item; if ($ref) { my $blessed = -1 != index $ref, '='; I wonder if $blessed can ever be true here. As far as I know, ref is just returning strings like HASH, ARRAY, REF, or the class name, but never a string with a "=" in it. In fact, running the test suite with Devel::Cover shows that the line bless $item if $blessed; is never accessed with a true $blessed value. Regards, Slaven
On Wed Dec 07 05:12:38 2011, SREZIC wrote: Show quoted text
> The source code of Data::Walk contains these lines (starting from line > 93): > > my $ref = ref $item; > > if ($ref) { > my $blessed = -1 != index $ref, '='; > > I wonder if $blessed can ever be true here. As far as I know, ref is > just returning strings like HASH, ARRAY, REF, or the class name, but > never a string with a "=" in it.
Not that the code is not wrong, but ref(bless [], "=") returns a string with = in it. :-) Show quoted text
> > In fact, running the test suite with Devel::Cover shows that the line > > bless $item if $blessed; > > is never accessed with a true $blessed value. > > Regards, > Slaven
CC: <SREZIC [...] cpan.org>
Subject: Re: [rt.cpan.org #73063] Can ref(...) return a string with "="?
Date: Fri, 9 Dec 2011 18:36:01 +0100
To: <bug-Data-Walk [...] rt.cpan.org>
From: Slaven Rezic <srezic [...] iconmobile.com>
Father Chrysostomos via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=73063 > > > On Wed Dec 07 05:12:38 2011, SREZIC wrote: >
>> The source code of Data::Walk contains these lines (starting from line >> 93): >> >> my $ref = ref $item; >> >> if ($ref) { >> my $blessed = -1 != index $ref, '='; >> >> I wonder if $blessed can ever be true here. As far as I know, ref is >> just returning strings like HASH, ARRAY, REF, or the class name, but >> never a string with a "=" in it. >>
> > Not that the code is not wrong, but ref(bless [], "=") returns a string with = in it. :-) > >
Fine :-) So I can actually construct a bug. The following script *changes* the data structure: #!perl use strict; use Data::Walk; use Test::More 'no_plan'; my $data = bless { }, '='; my $ref_pre = ref $data; walk +{ wanted => sub { } }, $data; my $ref_post = ref $data; is $ref_post, $ref_pre; __END__ not ok 1 # Failed test at /tmp/dw2.pl line 11. # got: 'Data::Walk' # expected: '=' 1..1 # Looks like you failed 1 test of 1. Bottom line, the "bless" handling can and should be removed from Data::Walk. Regards, Slaven
Please give me a little time for that. I'm migrating my scm from CVS to Git.
Fixed: [master 3c38c53] use Scalar::Util::blessed() for ref check 2 files changed, 10 insertions(+), 3 deletions(-) Actually the comparison was meant to be applied to the stringified $item. But I know use Scalar::Util::blessed() which is more reliable anyway.