The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::TempDB::Util - Utility functions for DBIx::TempDB

SYNOPSIS

  use DBIx::TempDB::Util qw(dsn_for parse_sql);

  my $url = URI::db->new("postgresql://postgres@localhost");
  print join ", ", dsn_for($url);

  my $guard = on_process_end sub { ... };
  undef $guard; # call the code block earlier

  print $_ for parse_sql("mysql", "delimiter //\ncreate table y (bar varchar(255))//\n");

DESCRIPTION

DBIx::TempDB::Util contains some utility functions for DBIx::TempDB.

FUNCTIONS

dsn_for

  @dsn = dsn_for +URI::db->new("postgresql://postgres@localhost");
  @dsn = dsn_for "postgresql://postgres@localhost";

"dsn_for" takes either a string or URI::db object and returns a list of arguments suitable for "connect" in DBI.

on_process_end

  $guard = on_process_end sub { ... };
  $guard = on_process_end $mode       => sub { ... };
  $guard = on_process_end destroy     => sub { ... };
  $guard = on_process_end double_fork => sub { ... };
  $guard = on_process_end fork        => sub { ... };

Used to set up a code block to be called when the process ends. The default $mode is "fork". The $guard value can be used to call the code block before the process ends:

  undef $guard; # call sub { ... }
  • destroy

    This mode will call the callback when the current process ends normally. This means that if the process is killed with SIGKILL (9) or another untrapped signal, then the callback will not be called.

  • double_fork

    This mode will create a process that is detached from the parent process. The double forked process will check if the parent is running by sending kill 0 every two seconds. This mode might not be supported by all operating systems.

  • fork

    This mode will create a process with a pipe connected to the parent process. Once the pipe is closed (when the parents ends) the callback will be called. This should work in most processes, but will not work if a the process group receives an unhandled signal.

parse_sql

  @statements = parse_sql $type, $sql;
  @statements = parse_sql $uri_db, $sql;
  @statements = parse_sql "mysql", "insert into ...";

Takes either a string or an URI::db object and a string containing SQL and splits the SQL into a list of individual statements.

Currently only "mysql" is a supported type, meaning any other type will simply return the input $sql.

This is not required for SQLite though, you can do this instead:

  local $dbh->{sqlite_allow_multiple_statements} = 1;
  $dbh->do($sql);

SEE ALSO

DBIx::TempDB.