Add strict/warnings test, adjust all offenders (wow, that was a lot)
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / MyBase.pm
CommitLineData
c6d74d3e 1package # hide from PAUSE
2 MyBase;
ea2e61bf 3
4a233f30 4use warnings;
ea2e61bf 5use strict;
4a233f30 6
d2cee1fa 7use DBI;
ea2e61bf 8
8d6b1478 9use lib 't/lib';
10use DBICTest;
11
12use base qw(DBIx::Class::CDBICompat);
13
f9cc85ce 14our $dbh;
ea2e61bf 15
49b3a264 16my $err;
17if (! $ENV{DBICTEST_MYSQL_DSN} ) {
18 $err = 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test';
19}
20elsif ( ! DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mysql') ) {
21 $err = 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mysql')
22}
23
24if ($err) {
25 my $t = eval { Test::Builder->new };
26 if ($t and ! $t->current_test) {
27 $t->skip_all ($err);
28 }
29 else {
30 die "$err\n";
31 }
32}
33
9381840d 34my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
8d6b1478 35# this is only so we grab a lock on mysql
36{
37 my $x = DBICTest::Schema->connect(@connect);
38}
39
ea2e61bf 40$dbh = DBI->connect(@connect) or die DBI->errstr;
41my @table;
42
43END { $dbh->do("DROP TABLE $_") foreach @table }
44
45__PACKAGE__->connection(@connect);
46
47sub set_table {
6a3bf251 48 my $class = shift;
49 $class->table($class->create_test_table);
ea2e61bf 50}
51
52sub create_test_table {
6a3bf251 53 my $self = shift;
54 my $table = $self->next_available_table;
55 my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
56 push @table, $table;
57 $dbh->do($create);
58 return $table;
ea2e61bf 59}
60
61sub next_available_table {
6a3bf251 62 my $self = shift;
63 my @tables = sort @{
64 $dbh->selectcol_arrayref(
65 qq{
ea2e61bf 66 SHOW TABLES
67 }
6a3bf251 68 )
69 };
70 my $table = $tables[-1] || "aaa";
71 return "z$table";
ea2e61bf 72}
73
741;