From: Peter Rabbitson Date: Wed, 24 Apr 2013 03:31:55 +0000 (+0200) Subject: Unbreak devrel version checks X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b1dbf7164ee06fa23aef5a799dd57df0357514ba;p=dbsrgits%2FDBIx-Class-Historic.git Unbreak devrel version checks One needs to supply the literal (string) value of a devrel to VERSION() otherwise the checks fail. However in this case 5.8 emits annoying warnings. Abstract the whole insanity in a neatish util function and use that. --- diff --git a/lib/DBIx/Class/Storage/DBI/ODBC.pm b/lib/DBIx/Class/Storage/DBI/ODBC.pm index 3462de1..1e8851b 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC.pm @@ -4,6 +4,9 @@ use warnings; use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; +use DBIx::Class::_Util 'modver_gt_or_eq'; +use namespace::clean; + sub _rebless { shift->_determine_connector_driver('ODBC') } # Whether or not we are connecting via the freetds ODBC driver @@ -33,11 +36,17 @@ sub _disable_odbc_array_ops { my $self = shift; my $dbh = $self->_get_dbh; - if (eval { DBD::ODBC->VERSION(1.35_01) }) { - $dbh->{odbc_array_operations} = 0; - } - elsif (eval { DBD::ODBC->VERSION(1.33_01) }) { - $dbh->{odbc_disable_array_operations} = 1; + $DBD::ODBC::__DBIC_DISABLE_ARRAY_OPS_VIA__ ||= [ do { + if( modver_gt_or_eq('DBD::ODBC', '1.35_01') ) { + odbc_array_operations => 0; + } + elsif( modver_gt_or_eq('DBD::ODBC', '1.33_01') ) { + odbc_disable_array_operations => 1; + } + }]; + + if (my ($k, $v) = @$DBD::ODBC::__DBIC_DISABLE_ARRAY_OPS_VIA__) { + $dbh->{$k} = $v; } } diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index 72146db..82c0f17 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -6,6 +6,7 @@ use warnings; use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; +use DBIx::Class::_Util 'modver_gt_or_eq'; use DBIx::Class::Carp; use Try::Tiny; use namespace::clean; @@ -152,11 +153,7 @@ sub _ping { # older DBD::SQLite does not properly synchronize commit state between # the libsqlite and the $dbh unless (defined $DBD::SQLite::__DBIC_TXN_SYNC_SANE__) { - local $@; - $DBD::SQLite::__DBIC_TXN_SYNC_SANE__ = eval { DBD::SQLite->VERSION(1.38_02); 1 } - ? 1 - : 0 - ; + $DBD::SQLite::__DBIC_TXN_SYNC_SANE__ = modver_gt_or_eq('DBD::SQLite', '1.38_02'); } # fallback to travesty diff --git a/lib/DBIx/Class/_Util.pm b/lib/DBIx/Class/_Util.pm new file mode 100644 index 0000000..d4760bc --- /dev/null +++ b/lib/DBIx/Class/_Util.pm @@ -0,0 +1,34 @@ +package # hide from PAUSE + DBIx::Class::_Util; + +use warnings; +use strict; + +use constant SPURIOUS_VERSION_CHECK_WARNINGS => ($] < 5.010 ? 1 : 0); + +use Carp; + +use base 'Exporter'; +our @EXPORT_OK = qw(modver_gt_or_eq); + +sub modver_gt_or_eq { + my ($mod, $ver) = @_; + + croak "Nonsensical module name supplied" + if ! defined $mod or ! length $mod; + + croak "Nonsensical minimum version supplied" + if ! defined $ver or $ver =~ /[^0-9\.\_]/; + + local $SIG{__WARN__} = do { + my $orig_sig_warn = $SIG{__WARN__} || sub { warn @_ }; + sub { + $orig_sig_warn->(@_) unless $_[0] =~ /\Qisn't numeric in subroutine entry/ + } + } if SPURIOUS_VERSION_CHECK_WARNINGS; + + local $@; + eval { $mod->VERSION($ver) } ? 1 : 0; +} + +1; diff --git a/maint/Makefile.PL.inc/21_meta_noindex.pl b/maint/Makefile.PL.inc/21_meta_noindex.pl index 73527c6..062e74c 100644 --- a/maint/Makefile.PL.inc/21_meta_noindex.pl +++ b/maint/Makefile.PL.inc/21_meta_noindex.pl @@ -11,6 +11,7 @@ no_index package => $_ for (qw/ DBIx::Class::Storage::DBIHacks DBIx::Class::Storage::BlockRunner DBIx::Class::Carp + DBIx::Class::_Util DBIx::Class::ResultSet::Pager /); diff --git a/t/55namespaces_cleaned.t b/t/55namespaces_cleaned.t index 30795a7..5b147d4 100644 --- a/t/55namespaces_cleaned.t +++ b/t/55namespaces_cleaned.t @@ -80,8 +80,9 @@ my $skip_idx = { map { $_ => 1 } ( # from the parent 'DBIx::Class::ResultSet::Pager', - # a utility class, not part of the inheritance chain + # utility classes, not part of the inheritance chain 'DBIx::Class::ResultSource::RowParser::Util', + 'DBIx::Class::_Util', ) }; my $has_cmop = eval { require Class::MOP }; diff --git a/t/752sqlite.t b/t/752sqlite.t index fc28037..d9a8e5d 100644 --- a/t/752sqlite.t +++ b/t/752sqlite.t @@ -9,6 +9,7 @@ use Config; use lib qw(t/lib); use DBICTest; +use DBIx::Class::_Util 'modver_gt_or_eq'; # savepoints test { @@ -52,7 +53,7 @@ use DBICTest; # However DBD::SQLite 1.38_02 seems to fix this, with an accompanying test: # https://metacpan.org/source/ADAMK/DBD-SQLite-1.38_02/t/54_literal_txn.t -my $lit_txn_todo = eval { DBD::SQLite->VERSION(1.38_02) } +my $lit_txn_todo = modver_gt_or_eq('DBD::SQLite', '1.38_02') ? undef : "DBD::SQLite before 1.38_02 is retarded wrt detecting literal BEGIN/COMMIT statements" ; @@ -151,7 +152,7 @@ $schema->storage->dbh_do(sub { # range is -(2**63) .. 2**63 - 1 SKIP: { skip 'This perl does not seem to have 64bit int support - DBI roundtrip of large int will fail with DBD::SQLite < 1.37', 1 - if ($Config{ivsize} < 8 and ! eval { DBD::SQLite->VERSION(1.37); 1 }); + if ($Config{ivsize} < 8 and ! modver_gt_or_eq('DBD::SQLite', '1.37') ); for my $bi (qw/ -9223372036854775808 diff --git a/xt/podcoverage.t b/xt/podcoverage.t index 7a7804e..da48580 100644 --- a/xt/podcoverage.t +++ b/xt/podcoverage.t @@ -131,6 +131,7 @@ my $exceptions = { 'DBIx::Class::SQLMaker::LimitDialects' => {}, # internals + 'DBIx::Class::_Util' => { skip => 1 }, 'DBIx::Class::SQLMaker*' => { skip => 1 }, 'DBIx::Class::SQLAHacks*' => { skip => 1 }, 'DBIx::Class::Storage::DBI*' => { skip => 1 },