=item on_disconnect_do
-Takes arguments in the same for as L<on_connect_do> and executes them
+Takes arguments in the same form as L<on_connect_do> and executes them
immediately before disconnecting from the database.
Note, this only runs if you explicitly call L<disconnect> on the
my ($self, $action) = @_;
if (ref $action eq 'CODE') {
- $action->($self);
+ $action = $action->($self);
+ $self->_do_query($_) foreach @$action;
}
else {
my @to_run = (ref $action eq 'ARRAY') ? (@$action) : ($action);
on_connect_do => [
'CREATE TABLE TEST_empty (id INTEGER)',
[ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
+ \&insert_from_subref,
],
on_disconnect_do =>
[\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
is_deeply
$schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
- [ [ 2 ] ],
+ [ [ 2 ], [ 3 ], [ 7 ] ],
'on_connect_do() worked';
eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
ok $@, 'Searching for nonexistent table dies';
sub check_exists {
my $storage = shift;
ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
+ return;
}
sub check_dropped {
my $storage = shift;
eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
ok $@, 'Reading from dropped table fails';
+ return;
+}
+
+sub insert_from_subref {
+ my $storage = shift;
+ return [
+ [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
+ 'INSERT INTO TEST_empty VALUES (7)',
+ ];
}