Annotate every indirect sugar-method
[dbsrgits/DBIx-Class.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 use DBICTest;
9
10 use base qw(DBIx::Class::CDBICompat);
11
12 my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
13 # this is only so we grab a lock on mysql
14 {
15   my $x = DBICTest::Schema->connect(@connect);
16 }
17
18 our $dbh = DBI->connect(@connect) or die DBI->errstr;
19 my @table;
20
21 END {
22   $dbh->do("DROP TABLE $_") for @table;
23   undef $dbh;
24 }
25
26 __PACKAGE__->connection(@connect);
27
28 sub set_table {
29   my $class = shift;
30   $class->table($class->create_test_table);
31 }
32
33 sub create_test_table {
34   my $self   = shift;
35   my $table  = $self->next_available_table;
36   my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
37   push @table, $table;
38   $dbh->do($create);
39   return $table;
40 }
41
42 sub next_available_table {
43   my $self   = shift;
44   my @tables = sort @{
45     $dbh->selectcol_arrayref(
46       qq{
47     SHOW TABLES
48   }
49     )
50     };
51   my $table = $tables[-1] || "aaa";
52   return "z$table";
53 }
54
55 1;