On Thu, 2004-05-27 at 14:13, Nathanial P. Hendler wrote:
> I'd like to have a config module, that holds things like:
> 
>   $document_root    = '/var/www/html';
>   $images_base_path = $document_root . '/images';
>   $images_base_url  = '/images';
> 
>   %phrases = ( red=>'This is red', blue=>'this is blue' );
> 
> But I can also think of reasons to have subroutines as well.  The module
> would need to be available to all of the used modules, and I'd rather not
> have to pass around a handle.  It also seems like it'd be nice if the
> values were re-written, that it would only last for that session, but that
> the change would be visible to all modules.
> 
> How do you guys deal with that?

Well, first I would drop the crazy stuff about subroutines and changing
values in mid-flight.  That's not config and it belongs somewhere else.

There's a section on this in the guide:
http://perl.apache.org/docs/1.0/guide/porting.html#Configuration_Files__Writing__Dynamically_Updating_and_Reloading

I typically use one of the config file modules on CPAN and a simple
singleton pattern.  You could use Class::Singleton, or roll your own.

> What about a (or several) $dbh handle?  I'm going to have SQL queries in
> all of my modules.  Do they all have to create their own $dbh?  Is there a
> well understood approach to this that I'm not finding on the interweb?

It's been discussed here many times.  You either just connect in each
one, letting Apache::DBI handle the persistence, or you use a singleton
approach of some kind.  Check the mailing list archives for more.

- 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

Reply via email to