Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Differences CPAN distribution.

Report information
The Basics
Id: 59210
Status: rejected
Priority: 0/
Queue: Test-Differences

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
Cc:
AdminCc:

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



Subject: Bad code for _isnt_ARRAY_of_scalars, _isnt_HASH_of_scalars
There are some errors in the definitions for _isnt_ARRAY_of_scalars() and _isnt_HASH_of_scalars() which lead to "interesting" results... I discovered this when comparing arrays of objects which have stringification overloads... The code in 0.5 is: sub _isnt_ARRAY_of_scalars { return 1 if ref ne "ARRAY"; return scalar grep ref, @$_; } sub _isnt_HASH_of_scalars { return 1 if ref ne "HASH"; return scalar grep ref, values %$_; } When it should actually be: sub _isnt_ARRAY_of_scalars { return 1 if ref $_[0] ne "ARRAY"; return scalar grep ref, @$_{[0]}; } sub _isnt_HASH_of_scalars { return 1 if ref $_[0] ne "HASH"; return scalar grep { ref } values %{$_[0]}; } Note that $_ is not normally defined in the body of a function -- instead of $_ you should use $_[0].
On Thu Jul 08 18:30:17 2010, bitcard@froods.org wrote: Show quoted text
> There are some errors in the definitions for _isnt_ARRAY_of_scalars() > and _isnt_HASH_of_scalars() which lead to "interesting" results... I > discovered this when comparing arrays of objects which have > stringification overloads... > > The code in 0.5 is: > > sub _isnt_ARRAY_of_scalars { > return 1 if ref ne "ARRAY"; > return scalar grep ref, @$_; > } > sub _isnt_HASH_of_scalars { > return 1 if ref ne "HASH"; > return scalar grep ref, values %$_; > } > > When it should actually be: > sub _isnt_ARRAY_of_scalars { > return 1 if ref $_[0] ne "ARRAY"; > return scalar grep ref, @$_{[0]}; > } > > sub _isnt_HASH_of_scalars { > return 1 if ref $_[0] ne "HASH"; > return scalar grep { ref } values %{$_[0]}; > } > > Note that $_ is not normally defined in the body of a function -- > instead of $_ you should use $_[0].
Hi, thanks for the bug report. I'm sorry I've gotten to this so late. I'm actually the maintainer of this code and not the author, so when I saw that, I was surprised to see it written like that. However, the original author originally called this after this: local $_ = shift @_; That allows the above functions to work, even though it looks strange and this is not, in fact, a bug. Cheers, Ovid