I guess that wasn't so bad.
use English '-no_match_vars';
sub dbh {
state $dbh;
state $dbh_pid;
if ( defined $dbh_pid && $PROCESS_ID != $dbh_pid ) {
my $child_dbh = $dbh->clone;
$dbh->{InactiveDestroy} = 1;
$dbh = $child_dbh;
$dbh_pid = $PROCESS_ID;
$L->debug( "cloned database connection in PID $dbh_pid" );
}
if ( ! defined $dbh ) {
my ($u,$p) = ('user',':)');
$dbh = DBI->connect(
"dbi:Sybase:server=sql.example.com",
$u, $p, { RaiseError => 1 },
);
$dbh->do( $initialization_stuff );
$dbh_pid = $PROCESS_ID;
$L->debug( "made new database connection in PID $dbh_pid" );
}
return $dbh;
}