Switch the ::Sybase family to _determine_connector_driver (same as 75d3bdb2)
Peter Rabbitson [Fri, 14 Aug 2015 04:51:13 +0000 (05:51 +0100)]
Simplify test a bit

lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/Replicated.pm
lib/DBIx/Class/Storage/DBI/Sybase.pm
t/746sybase.t

index b5fa871..eb9bd88 100644 (file)
@@ -1335,7 +1335,7 @@ sub _extract_driver_from_connect_info {
 sub _determine_connector_driver {
   my ($self, $conn) = @_;
 
-  my $dbtype = $self->_dbh_get_info('SQL_DBMS_NAME');
+  my $dbtype = $self->_get_rdbms_name;
 
   if (not $dbtype) {
     $self->_warn_undetermined_driver(
@@ -1362,6 +1362,8 @@ sub _determine_connector_driver {
   }
 }
 
+sub _get_rdbms_name { shift->_dbh_get_info('SQL_DBMS_NAME') }
+
 sub _warn_undetermined_driver {
   my ($self, $msg) = @_;
 
index 273b218..92a0e17 100644 (file)
@@ -340,6 +340,7 @@ my $method_dispatch = {
     set_dbms_capability
     _dbh_details
     _dbh_get_info
+    _get_rdbms_name
 
     _determine_connector_driver
     _extract_driver_from_connect_info
index 4631117..6288325 100644 (file)
@@ -21,28 +21,25 @@ L<DBD::Sybase>
 
 =cut
 
-sub _rebless {
+sub _rebless { shift->_determine_connector_driver('Sybase') }
+
+sub _get_rdbms_name {
   my $self = shift;
 
-  my $dbtype;
   try {
-    $dbtype = @{$self->_get_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2]
-  } catch {
-    $self->throw_exception("Unable to establish connection to determine database type: $_")
-  };
-
-  if ($dbtype) {
-    $dbtype =~ s/\W/_/gi;
+    my $name = $self->_get_dbh->selectrow_arrayref('sp_server_info @attribute_id=1')->[2];
 
-    # saner class name
-    $dbtype = 'ASE' if $dbtype eq 'SQL_Server';
+    if ($name) {
+      $name =~ s/\W/_/gi;
 
-    my $subclass = __PACKAGE__ . "::$dbtype";
-    if ($self->load_optional_class($subclass)) {
-      bless $self, $subclass;
-      $self->_rebless;
+      # saner class name
+      $name = 'ASE' if $name eq 'SQL_Server';
     }
-  }
+
+    $name;  # RV
+  } catch {
+    $self->throw_exception("Unable to establish connection to determine database type: $_")
+  };
 }
 
 sub _init {
index 540ca78..ea08cbb 100644 (file)
@@ -13,11 +13,8 @@ my @storage_types = (
   'DBI::Sybase::ASE',
   'DBI::Sybase::ASE::NoBindVars',
 );
-eval "require DBIx::Class::Storage::$_;" or die $@
-  for @storage_types;
 
 my $schema;
-my $storage_idx = -1;
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
 
@@ -31,6 +28,7 @@ sub get_schema {
 
 my $ping_count = 0;
 {
+  require DBIx::Class::Storage::DBI::Sybase::ASE;
   my $ping = DBIx::Class::Storage::DBI::Sybase::ASE->can('_ping');
   *DBIx::Class::Storage::DBI::Sybase::ASE::_ping = sub {
     $ping_count++;
@@ -39,7 +37,6 @@ my $ping_count = 0;
 }
 
 for my $storage_type (@storage_types) {
-  $storage_idx++;
 
   unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
     DBICTest::Schema->storage_type("::$storage_type");
@@ -49,12 +46,12 @@ for my $storage_type (@storage_types) {
 
   $schema->storage->ensure_connected;
 
-  if ($storage_idx == 0 &&
-      $schema->storage->isa('DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars')) {
-      # no placeholders in this version of Sybase or DBD::Sybase (or using FreeTDS)
-      skip "Skipping entire test for $storage_type - no placeholder support", 1;
-      next;
-  }
+  # we are going to explicitly test this anyway, just loop through
+  next if
+    $storage_type ne 'DBI::Sybase::ASE::NoBindVars'
+      and
+    $schema->storage->isa('DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars')
+  ;
 
   isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );