Centralize remaining uses of Sub::Name within _Util
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO.pm
index 8a0fa68..c7c0621 100644 (file)
@@ -1,33 +1,67 @@
-package # hide from PAUSE
-    DBIx::Class::Storage::DBI::ADO;
+package DBIx::Class::Storage::DBI::ADO;
+
+use warnings;
+use strict;
 
 use base 'DBIx::Class::Storage::DBI';
+use mro 'c3';
+
+use DBIx::Class::_Util qw( sigwarn_silencer modver_gt_or_eq set_subname );
+use namespace::clean;
+
+=head1 NAME
+
+DBIx::Class::Storage::DBI::ADO - Support for L<DBD::ADO>
+
+=head1 DESCRIPTION
 
-sub _rebless {
+This class provides a mechanism for discovering and loading a sub-class
+for a specific ADO backend, as well as some workarounds for L<DBD::ADO>. It
+should be transparent to the user.
+
+=cut
+
+sub _rebless { shift->_determine_connector_driver('ADO') }
+
+# cleanup some warnings from DBD::ADO
+# RT#65563, not fixed as of DBD::ADO v2.98
+sub _dbh_get_info {
   my $self = shift;
 
-# check for MSSQL
-# XXX This should be using an OpenSchema method of some sort, but I don't know
-# how.
-# Current version is stolen from Sybase.pm
-  my $dbtype = eval {
-    @{$self->_get_dbh
-      ->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})
-    }[2]
-  };
-
-  unless ($@) {
-    $dbtype =~ s/\W/_/gi;
-    my $subclass = "DBIx::Class::Storage::DBI::ADO::${dbtype}";
-    if ($self->load_optional_class($subclass) && !$self->isa($subclass)) {
-      bless $self, $subclass;
-      $self->_rebless;
+  local $SIG{__WARN__} = sigwarn_silencer(
+    qr{^Missing argument in sprintf at \S+/ADO/GetInfo\.pm}
+  );
+
+  $self->next::method(@_);
+}
+
+# Monkeypatch out the horrible warnings during global destruction.
+# 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 {
+  unless ($DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__) {
+    require DBD::ADO;
+
+    unless ( modver_gt_or_eq( 'DBD::ADO', '2.99' ) ) {
+      no warnings 'redefine';
+      my $disconnect = *DBD::ADO::db::disconnect{CODE};
+
+      *DBD::ADO::db::disconnect = set_subname 'DBD::ADO::db::disconnect' => sub {
+        local $SIG{__WARN__} = sigwarn_silencer(
+          qr/Not a Win32::OLE object|uninitialized value/
+        );
+        $disconnect->(@_);
+      };
     }
+
+    $DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__ = 1;
   }
 }
 
-# set cursor type here, if necessary
-#sub _dbh_sth {
+# Here I was just experimenting with ADO cursor types, left in as a comment in
+# case you want to as well. See the DBD::ADO docs.
+#sub _prepare_sth {
 #  my ($self, $dbh, $sql) = @_;
 #
 #  my $sth = $self->disable_sth_caching
@@ -39,4 +73,19 @@ sub _rebless {
 #  $sth;
 #}
 
+=head1 FURTHER QUESTIONS?
+
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
+
+=head1 COPYRIGHT AND LICENSE
+
+This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
+by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
+redistribute it and/or modify it under the same terms as the
+L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
+
+=cut
+
 1;
+
+# vim:sts=2 sw=2: