Skip Menu |

This queue is for tickets about the Tk-ObjScanner CPAN distribution.

Report information
The Basics
Id: 5197
Status: resolved
Priority: 0/
Queue: Tk-ObjScanner

People
Owner: DDUMONT [...] cpan.org
Requestors: Marek.Rouchal [...] gmx.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.007
Fixed in: 2.010



Subject: Better handling of pseudo-hashes
Yes, I have read the documentation and the note about pseudohashes being deprecated. However in perl/5.8.3 with "use fields" still pseudohashes are used, and this little patch greatly enhances the support of that; here some comments about the individual changes: 1. $ref = ref($ref) it seems that isObject is not really in use, but the code in sub isObject choked on objects with overloaded "" (stringify) operator. The additional line fixes this - altough the entire code seems to be removable 2. =~ /^(pseudohash|HASH)$/ I don't know which perl version introduced that - but the ref command returns 'pseudohash' here, and not HASH. This is the key change of the patch 3. The index check must consider the upper limit defined in the $item->[0] hash, not the number of items in @$item - as it seems that the array is extended dynamically 4. some minor code compaction - no change in functionality (I hope) Thanks for the great code and keep up the good work! Cheers, Marek --- ObjScanner.pm.orig Fri Nov 28 18:16:19 2003 +++ ObjScanner.pm Wed Feb 4 11:46:52 2004 @@ -254,6 +254,7 @@ { my $ref = shift ; # not a method ! return 0 unless $ref ; + $ref = ref($ref); return scalar grep ($ref eq $_, qw/REF SCALAR CODE GLOB ARRAY HASH/) ? 0 : 1; } @@ -269,19 +270,17 @@ $cw->{viewpseudohash} && isa($item,'ARRAY') && scalar @$item && - ref $item->[0] eq 'HASH'); + ref($item->[0]) =~ /^(HASH|pseudohash)$/); + my @indexes = values %{ $item->[0] } ; + my $ret = scalar keys %{ $item->[0] } ; - return 0 if scalar grep( /\D/, @indexes ) or - scalar grep( $_ > $#$item,@indexes ) ; + # check that all indexes are numbers and within the range + return 0 if scalar grep( /\D/ || $_ < 1 || $_ > $ret, @indexes ); - my $ret = scalar keys %{ $item->[0] } ; + # check that not more array items than in the range are defined return 0 unless $ret >= scalar @$item - 1; - for (values %{ $item->[0] }) - { - return 0 if ($_ !~ /^\d+$/ || $_ < 1); - } return $ret ; }
Sorry for the delay, your mail arrived at a time where my days were packed (baby born in January) and I just happen to stumble on your request. [MAREKR - Wed Feb 4 05:58:07 2004]: Show quoted text
> Yes, I have read the documentation and the note about pseudohashes > being deprecated. However in perl/5.8.3 with "use fields" still > pseudohashes are used, and this little patch greatly enhances the > support of that;
Since you provides a patch, I can hardly refuse... Show quoted text
> here some comments about the individual changes: > 1. $ref = ref($ref) > it seems that isObject is not really in use, but the code in > sub isObject choked on objects with overloaded "" (stringify) > operator. The additional line fixes this - altough the entire > code seems to be removable
You're right. This code is leftover from previous version. I'll remove it. Show quoted text
> 2. =~ /^(pseudohash|HASH)$/ > I don't know which perl version introduced that - but the ref > command returns 'pseudohash' here, and not HASH. This is the key > change of the patch > 3. The index check must consider the upper limit defined in the > $item->[0] hash, not the number of items in @$item - as it seems > that the array is extended dynamically > 4. some minor code compaction - no change in functionality (I hope) > > Thanks for the great code and keep up the good work!
Thanks for the patch. It will be in next version.