How are other people handling user settings? For instance, LibDB::Settings determines a bunch of stuff for each and every request, depending on the user environment (script being run, the browser's AcceptLanguage, the user's chosen template, etc.). Since I want those values to be the same through all objects ($s1, $s2, $s3 should return the same setting value regardless whether it was changed by $s4), they're all stored in a global (to LibDB::Settings) %SETTINGS. How should I handle this from mod_perl's standpoint?
To generalize this, the question is how should you make some data that is specific to this request available from any code that wants to use it. There are a couple of common approaches.
One of them is to put the data in $r->pnotes(). You can always get at it from any other code then, like this:
my $value = Apache->request->pnotes('key');
Because you want to make things work in CGI too, you could make an accessor method that reads and stores this data in pnotes when running under mod_perl but just shoves it in a global under CGI. The advantage that pnotes has under mod_perl is that it gets automatically cleared at the end of every request, avoiding the possibility of caching.
Another way to do it is to structure your code so that there is a place near the start of each request where you calculate this and put it in a lexical variable (maybe a hash or an object if it's multiple values), and then you pass that "context" object (or specific values from it) around to methods that need it.
Make sure you aren't opening a database connection during server startup. Throw in a log statement where you connect to the database and make sure it doesn't happen before you send in a request.
I'm not, but realize that it's never getting to the actual database connection: instead, it's telling me that the ->connect routine doesn't even exist in the (correct) module.
Usually, a connection before the fork would give you lots of mysterious errors about losing connections and such, so probably not that. It looks to me like this just comes back to your "settings" problem again. From your lLibDB::DB::new:
return undef unless LibDB::DB->supported($user_dbtype);
That would explain why it can't call connect() on the object being returned.
You should really follow the advice about debugging with -X. It's the only way to make the problem repeatable, and you will have a hard time solving it if you can't come up with a way to repeat it.
- Perrin
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html