[Bast-commits] r9133 - DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Mon Apr 12 18:23:11 GMT 2010


Author: caelum
Date: 2010-04-12 19:23:11 +0100 (Mon, 12 Apr 2010)
New Revision: 9133

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm
Log:
better way to find minimal dbms version in ::Replicated

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm	2010-04-12 07:10:38 UTC (rev 9132)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm	2010-04-12 18:23:11 UTC (rev 9133)
@@ -15,7 +15,7 @@
 use MooseX::Types::Moose qw/ClassName HashRef Object/;
 use Scalar::Util 'reftype';
 use Hash::Merge;
-use List::Util qw/min max/;
+use List::Util qw/min max reduce/;
 
 use namespace::clean -except => 'meta';
 
@@ -1010,21 +1010,24 @@
   return min map $_->_ping, $self->all_storages;
 }
 
+my $numify_ver = sub {
+  my $ver = shift;
+  my @numparts = split /\D+/, $ver;
+  my $format = '%d.' . (join '', ('%05d') x (@numparts - 1));
+
+  return sprintf $format, @numparts;
+};
+
 sub _server_info {
   my $self = shift;
 
   if (not $self->_server_info_hash) {
-    no warnings 'numeric'; # in case dbms_version doesn't normalize
+    my $min_version_info = (
+      reduce { $a->[0] < $b->[0] ? $a : $b } 
+      map [ $numify_ver->($_->{dbms_version}), $_ ],
+      map $_->_server_info, $self->all_storages
+    )->[1];
 
-    my @infos = 
-      map $_->[1],
-      sort { $a->[0] <=> $b->[0] } 
-      map [ (defined $_->{normalized_dbms_version} ? $_->{normalized_dbms_version}
-              : $_->{dbms_version}), $_ ],
-      map $_->_server_info, $self->all_storages;
-
-    my $min_version_info = $infos[0];
-
     $self->_server_info_hash($min_version_info); # on master
   }
 

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm	2010-04-12 07:10:38 UTC (rev 9132)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm	2010-04-12 18:23:11 UTC (rev 9133)
@@ -89,7 +89,7 @@
 
     my $data_type = $col_info->{$selected}{data_type};
 
-    if ($data_type && $data_type =~ /^uniqueidentifier\z/i) {
+    if ($data_type && lc($data_type) eq 'uniqueidentifier') {
       $select->[$select_idx] = { UUIDTOSTR => $selected };
     }
   }




More information about the Bast-commits mailing list