Hi all,
My application uses different databases depending on the client, which is
always the first parameter in each route. Example:
/:client/home
/:client/list
...
I’m using the following ‘before’ hook to set the database handle dbh:
# Figure out client, if any
my $client = param('client') || '';
unless ($client =~ /^[a-z0-9]{2,20}$/) {
$client = ''; }
# If $client, get client dbh
if ($client) {
if (!vars->{'dbh'}) {
eval {
var dbh => database({
driver => "mysql",
host => "localhost",
dbi_params => ...
database => "s_".$client,
...
});
}
}
if (!vars->{'dbh'}) {
warning “Could not open client database”; # Warning is present
pass; # Internal Server Error thrown
}
}
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.
Any ideas on how to implement this without having to repeat this code over and
over and over within each route?
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).
Thanks in advance for any thoughts!
Hermann
_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users