Switch CDBICompat and its tests to OptDeps
[dbsrgits/DBIx-Class-Historic.git] / t / cdbi / testlib / MyBase.pm
1 package # hide from PAUSE
2     MyBase;
3
4 use warnings;
5 use strict;
6
7 use DBI;
8
9 use lib 't/lib';
10 use DBICTest;
11
12 use base qw(DBIx::Class::CDBICompat);
13
14 my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
15 # this is only so we grab a lock on mysql
16 {
17   my $x = DBICTest::Schema->connect(@connect);
18 }
19
20 our $dbh = DBI->connect(@connect) or die DBI->errstr;
21 my @table;
22
23 END {
24   $dbh->do("DROP TABLE $_") for @table;
25   undef $dbh;
26 }
27
28 __PACKAGE__->connection(@connect);
29
30 sub set_table {
31   my $class = shift;
32   $class->table($class->create_test_table);
33 }
34
35 sub create_test_table {
36   my $self   = shift;
37   my $table  = $self->next_available_table;
38   my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
39   push @table, $table;
40   $dbh->do($create);
41   return $table;
42 }
43
44 sub next_available_table {
45   my $self   = shift;
46   my @tables = sort @{
47     $dbh->selectcol_arrayref(
48       qq{
49     SHOW TABLES
50   }
51     )
52     };
53   my $table = $tables[-1] || "aaa";
54   return "z$table";
55 }
56
57 1;