support $ENV{DBI_DSN} and $ENV{DBI_DRIVER} (patch from Possum)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI.pm
index 655f506..e048b62 100644 (file)
@@ -950,11 +950,18 @@ sub _server_info {
       if (
         @verparts
           &&
-        @verparts <= 3
-          &&
-        ! grep { $_ > 999 } (@verparts)
+        $verparts[0] <= 999
       ) {
-        $info{normalized_dbms_version} = sprintf "%d.%03d%03d", @verparts;
+        # consider only up to 3 version parts, iff not more than 3 digits
+        my @use_parts;
+        while (@verparts && @use_parts < 3) {
+          my $p = shift @verparts;
+          last if $p > 999;
+          push @use_parts, $p;
+        }
+        push @use_parts, 0 while @use_parts < 3;
+
+        $info{normalized_dbms_version} = sprintf "%d.%03d%03d", @use_parts;
       }
     }
 
@@ -991,8 +998,9 @@ sub _determine_driver {
           # try to use dsn to not require being connected, the driver may still
           # force a connection in _rebless to determine version
           # (dsn may not be supplied at all if all we do is make a mock-schema)
-          my $dsn = $self->_dbi_connect_info->[0] || '';
+          my $dsn = $self->_dbi_connect_info->[0] || $ENV{DBI_DSN} || '';
           ($driver) = $dsn =~ /dbi:([^:]+):/i;
+          $driver ||= $ENV{DBI_DRIVER};
         }
       }