Merge branch 'master' into topic/constructor_rewrite
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO.pm
index 8c64735..8cca22d 100644 (file)
@@ -4,6 +4,7 @@ use base 'DBIx::Class::Storage::DBI';
 use mro 'c3';
 
 use Sub::Name;
+use Try::Tiny;
 use namespace::clean;
 
 =head1 NAME
@@ -21,7 +22,7 @@ should be transparent to the user.
 sub _rebless {
   my $self = shift;
 
-  my $dbtype = $self->_dbh_get_info(17);
+  my $dbtype = $self->_dbh_get_info('SQL_DBMS_NAME');
 
   if (not $dbtype) {
     warn "Unable to determine ADO driver, failling back to generic support.\n";
@@ -60,23 +61,28 @@ sub _dbh_get_info {
 }
 
 # Monkeypatch out the horrible warnings during global destruction.
-# A patch to DBD::ADO has been submitted as well.
+# A patch to DBD::ADO has been submitted as well, and it was fixed
+# as of 2.99
 # https://rt.cpan.org/Ticket/Display.html?id=65563
 sub _init {
-  no warnings 'redefine';
-  require DBD::ADO;
-
-  if ($DBD::ADO::VERSION <= 2.98) {
-    my $disconnect = *DBD::ADO::db::disconnect{CODE};
-
-    *DBD::ADO::db::disconnect = subname 'DBD::ADO::db::disconnect' => sub {
-      my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
-      local $SIG{__WARN__} = sub {
-        $warn_handler->(@_)
-          unless $_[0] =~ /Not a Win32::OLE object|uninitialized value/;
+  unless ($DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__) {
+    require DBD::ADO;
+
+    unless (try { DBD::ADO->VERSION('2.99'); 1 }) {
+      no warnings 'redefine';
+      my $disconnect = *DBD::ADO::db::disconnect{CODE};
+
+      *DBD::ADO::db::disconnect = subname 'DBD::ADO::db::disconnect' => sub {
+        my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
+        local $SIG{__WARN__} = sub {
+          $warn_handler->(@_)
+            unless $_[0] =~ /Not a Win32::OLE object|uninitialized value/;
+        };
+        $disconnect->(@_);
       };
-      $disconnect->(@_);
-    };
+    }
+
+    $DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__ = 1;
   }
 }