Make $SIG{__WARN__} overrides more Carp::Always friendly
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO.pm
CommitLineData
56dca25f 1package DBIx::Class::Storage::DBI::ADO;
4ffa5700 2
4a233f30 3use warnings;
4use strict;
5
4ffa5700 6use base 'DBIx::Class::Storage::DBI';
56dca25f 7use mro 'c3';
4ffa5700 8
772a1a25 9use Sub::Name;
8892d8e5 10use Try::Tiny;
052a832c 11use DBIx::Class::_Util 'sigwarn_silencer';
772a1a25 12use namespace::clean;
13
56dca25f 14=head1 NAME
15
16DBIx::Class::Storage::DBI::ADO - Support for L<DBD::ADO>
17
18=head1 DESCRIPTION
19
20This class provides a mechanism for discovering and loading a sub-class
21for a specific ADO backend, as well as some workarounds for L<DBD::ADO>. It
22should be transparent to the user.
23
24=cut
25
75d3bdb2 26sub _rebless { shift->_determine_connector_driver('ADO') }
56dca25f 27
28# cleanup some warnings from DBD::ADO
29# RT#65563, not fixed as of DBD::ADO v2.98
30sub _dbh_get_info {
31 my $self = shift;
32
052a832c 33 local $SIG{__WARN__} = sigwarn_silencer(
34 qr{^Missing argument in sprintf at \S+/ADO/GetInfo\.pm}
35 );
56dca25f 36
37 $self->next::method(@_);
4ffa5700 38}
39
772a1a25 40# Monkeypatch out the horrible warnings during global destruction.
8892d8e5 41# A patch to DBD::ADO has been submitted as well, and it was fixed
42# as of 2.99
772a1a25 43# https://rt.cpan.org/Ticket/Display.html?id=65563
44sub _init {
8892d8e5 45 unless ($DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__) {
46 require DBD::ADO;
47
48 unless (try { DBD::ADO->VERSION('2.99'); 1 }) {
49 no warnings 'redefine';
50 my $disconnect = *DBD::ADO::db::disconnect{CODE};
51
52 *DBD::ADO::db::disconnect = subname 'DBD::ADO::db::disconnect' => sub {
052a832c 53 local $SIG{__WARN__} = sigwarn_silencer(
54 qr/Not a Win32::OLE object|uninitialized value/
55 );
8892d8e5 56 $disconnect->(@_);
772a1a25 57 };
8892d8e5 58 }
59
60 $DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__ = 1;
772a1a25 61 }
62}
63
748eb620 64# Here I was just experimenting with ADO cursor types, left in as a comment in
65# case you want to as well. See the DBD::ADO docs.
9930caaf 66#sub _prepare_sth {
4ffa5700 67# my ($self, $dbh, $sql) = @_;
68#
69# my $sth = $self->disable_sth_caching
70# ? $dbh->prepare($sql, { CursorType => 'adOpenStatic' })
71# : $dbh->prepare_cached($sql, { CursorType => 'adOpenStatic' }, 3);
72#
73# $self->throw_exception($dbh->errstr) if !$sth;
74#
75# $sth;
76#}
77
781;
56dca25f 79
80=head1 AUTHOR
81
82See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
83
84=head1 LICENSE
85
86You may distribute this code under the same terms as Perl itself.
87
88=cut
89# vim:sts=2 sw=2: