1package # hide from PAUSE 2 MyBase; 3 4use strict; 5use base qw(DBIx::Class::CDBICompat); 6 7use DBI; 8 9use vars qw/$dbh/; 10 11my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0}); 12$dbh = DBI->connect(@connect) or die DBI->errstr; 13my @table; 14 15END { $dbh->do("DROP TABLE $_") foreach @table } 16 17__PACKAGE__->connection(@connect); 18 19sub set_table { 20 my $class = shift; 21 $class->table($class->create_test_table); 22} 23 24sub create_test_table { 25 my $self = shift; 26 my $table = $self->next_available_table; 27 my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; 28 push @table, $table; 29 $dbh->do($create); 30 return $table; 31} 32 33sub next_available_table { 34 my $self = shift; 35 my @tables = sort @{ 36 $dbh->selectcol_arrayref( 37 qq{ 38 SHOW TABLES 39 } 40 ) 41 }; 42 my $table = $tables[-1] || "aaa"; 43 return "z$table"; 44} 45 461; 47