Author: timbo
Date: Wed May 28 13:20:02 2008
New Revision: 11341

Modified:
   dbi/trunk/lib/DBI/PurePerl.pm
   dbi/trunk/t/18concathash.t

Log:
Bring PurePerl _concat_hash_sorted into line.
Silence debug warning.


Modified: dbi/trunk/lib/DBI/PurePerl.pm
==============================================================================
--- dbi/trunk/lib/DBI/PurePerl.pm       (original)
+++ dbi/trunk/lib/DBI/PurePerl.pm       Wed May 28 13:20:02 2008
@@ -673,13 +673,12 @@
 
 sub DBI::st::TIEHASH { bless $_[1] => $_[0] };
 
-
 sub _concat_hash_sorted {
     my ( $hash_ref, $kv_separator, $pair_separator, $value_format, $sort_type 
) = @_;
     # $value_format: false=use neat(), true=dumb quotes
     # $sort_type: 0=lexical, 1=numeric, undef=try to guess
-    Carp::croak("hash is not a hash reference")
-        unless ref $hash_ref eq 'HASH';
+
+    die "hash is not a hash reference" unless ref $hash_ref eq 'HASH';
     my $keys = _get_sorted_hash_keys($hash_ref, $sort_type);
     my $string = '';
     for my $key (@$keys) {
@@ -687,10 +686,10 @@
         my $value = $hash_ref->{$key};
         if ($value_format) {
             $value = (defined $value) ? "'$value'" : 'undef';
-        }   
+        }
         else {
             $value = DBI::neat($value,0);
-        }   
+        }
         $string .= $key . $kv_separator . $value;
     }
     return $string;
@@ -698,24 +697,22 @@
 
 sub _get_sorted_hash_keys {
     my ($hash_ref, $sort_type) = @_;
-    my $sort_guess = 1;
     if (not defined $sort_type) {
-        #my $first_key = (each %$hash_ref)[0];
-        #$sort_type = looks_like_number($first_key);
-    
-        $sort_guess = (1!=DBI::looks_like_number($_))
-                ? 0 : $sort_guess
+        my $sort_guess = 1;
+        $sort_guess = (not looks_like_number($_)) ? 0 : $sort_guess
             for keys %$hash_ref;
-        $sort_type = $sort_guess unless (defined $sort_type);
+        $sort_type = $sort_guess;
     }
     
     my @keys = keys %$hash_ref;
     no warnings 'numeric';
-    return [ ($sort_type && $sort_guess)
-        ? sort {$a <=> $b} @keys
-        : sort    @keys
-    ];  
-}           
+    my @sorted = ($sort_type)
+        ? sort { $a <=> $b or $a cmp $b } @keys
+        : sort    @keys;
+    #warn "$sort_type = @sorted\n";
+    return [EMAIL PROTECTED];
+}
+
 
 
 package

Modified: dbi/trunk/t/18concathash.t
==============================================================================
--- dbi/trunk/t/18concathash.t  (original)
+++ dbi/trunk/t/18concathash.t  Wed May 28 13:20:02 2008
@@ -7,6 +7,7 @@
 
 use strict;
 use Benchmark qw(:all);
+use Scalar::Util qw(looks_like_number);
 no warnings 'uninitialized';
 
 use Test::More tests => 36;
@@ -137,6 +138,7 @@
     # $value_format: false=use neat(), true=dumb quotes
     # $sort_type: 0=lexical, 1=numeric, undef=try to guess
 
+    die "hash is not a hash reference" unless ref $hash_ref eq 'HASH';
     my $keys = _get_sorted_hash_keys($hash_ref, $sort_type);
     my $string = '';
     for my $key (@$keys) {
@@ -153,7 +155,6 @@
     return $string;
 }
 
-use Scalar::Util qw(looks_like_number);
 sub _get_sorted_hash_keys {
     my ($hash_ref, $sort_type) = @_;
     if (not defined $sort_type) {
@@ -168,7 +169,7 @@
     my @sorted = ($sort_type)
         ? sort { $a <=> $b or $a cmp $b } @keys
         : sort    @keys;
-    warn "$sort_type = @sorted\n";
+    #warn "$sort_type = @sorted\n";
     return [EMAIL PROTECTED];
 }
 

Reply via email to