<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: 'Calibri'; COLOR: #000000">
<DIV>Hi all,</DIV>
<DIV> </DIV>
<DIV>My application uses different databases depending on the client, which is
always the first parameter in each route. Example:</DIV>
<DIV> </DIV>
<DIV>/:client/home</DIV>
<DIV>/:client/list</DIV>
<DIV>...</DIV>
<DIV> </DIV>
<DIV>I’m using the following ‘before’ hook to set the database handle dbh:</DIV>
<DIV> </DIV>
<DIV># Figure out client, if any</DIV>
<DIV>my $client = param('client') || '';</DIV>
<DIV>unless ($client =~ /^[a-z0-9]{2,20}$/) {</DIV>
<DIV> $client = ''; }</DIV>
<DIV> </DIV>
<DIV># If $client, get client dbh</DIV>
<DIV>if ($client) {</DIV>
<DIV> if (!vars->{'dbh'}) {</DIV>
<DIV> eval {</DIV>
<DIV> var dbh => database({</DIV>
<DIV> driver => "mysql",</DIV>
<DIV> host => "localhost",</DIV>
<DIV> dbi_params => ...</DIV>
<DIV> database =>
"s_".$client,</DIV>
<DIV> ...</DIV>
<DIV> }); </DIV>
<DIV> }</DIV>
<DIV> }</DIV>
<DIV> if (!vars->{'dbh'}) {</DIV>
<DIV> warning “Could not open client database”; #
Warning is present</DIV>
<DIV> pass; # Internal Server Error thrown</DIV>
<DIV> } </DIV>
<DIV> }</DIV>
<DIV> </DIV>
<DIV>I’d like Dancer to gracefully fall through to a 404 error in case
s1_$client is not found or cannot be opened. I’ve tried “pass” and
“forward”, but I receive a cryptic “Internal Server Error” which I assume is
because these keywords are not valid within hooks, but I’m not sure.</DIV>
<DIV> </DIV>
<DIV>Any ideas on how to implement this without having to repeat this code over
and over and over within each route?</DIV>
<DIV> </DIV>
<DIV>I’m also open to other ideas/approaches to implement this general scheme as
long as I get a separate database for each :client (i.e., “create one huge
database” is not a valid solution given the application requirements).</DIV>
<DIV> </DIV>
<DIV>Thanks in advance for any thoughts!</DIV>
<DIV> </DIV>
<DIV>Hermann</DIV>
<DIV> </DIV></DIV></DIV></BODY></HTML>