[Dancer-users] Opening multiple database connections after startup

Alex C calyx238 at gmail.com
Mon Jul 16 22:29:13 CEST 2012

My app needs to connect to multiple databases (currently: 1 PostgreSQL
+ 2 Redis), and I would like it to do this as soon as possible after

However, due to Dancer's cached-coderef design, it is not trivial to
do this immediately after forking (as far as I know).

My current solution is this:

sub init_connections {
    $dbh      = connect_to_dbh();
    $redis_0  = connect_to_redis_0();
    $redis_1  = connect_to_redis_1();
    return 1;

sub before {
    $connected ||= init_connections;

This works fine, but if there are any connection problems, I don't
find out immediately.

So I tried coding the app to connect to itself, like this:

sub init_connections {
    return 1;

But of course, my first experiment resulted in a loop!

I wonder if I am approaching this the right way. Before I spend much
more time on this, does anyone have any thoughts / experience on this


More information about the Dancer-users mailing list