Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Configuration Best Practices for Web Apps

by cbrandtbuffalo (Deacon)
on Jan 30, 2006 at 19:09 UTC ( [id://526528]=note: print w/replies, xml ) Need Help??


in reply to Re: Configuration Best Practices for Web Apps
in thread Configuration Best Practices for Web Apps

I'm pretty sold on the OO approach, but there are a few additional wrinkles I neglected to mention. I agree that having a perl-based config file is very handy and easy to use. When we do so, we typically want to use info from the machine config inside the app-specific config file. So...

# In my cgi script... use My::Config; my $config = My::Config->new(project => 'GuestBook'); require $config->get('config_path') . "app_config.pl"; # Now, inside app_config.pl, what's the best way to get at the config # object if I want to use some of the methods? # Just create another new object? It seems wrong to do it again, # but I suppose the overhead # is probably trivial. # Inside app_config.pl package My::App; use My::Config; our $config = My::Config->new(project => 'GuestBook'); if ( $config->get('env_dev') ){ # We're in dev, so set the dev passwords. } # etc.

Now, how do you feel about then using the $config object as a package variable to access it in other code that is part of the framework but outside the scope of the original script? Using the code above, I could then do this, right?

package My::App::Page; my $db_password = $My::App::config->get('db_password');

Replies are listed 'Best First'.
Re^3: Configuration Best Practices for Web Apps
by perrin (Chancellor) on Jan 30, 2006 at 21:13 UTC
    I would use a class method rather than a package variable. No need to expose that.

    For handling the application scoped and machine scoped configs, I would make it possible to access both through a single object. You might make an application config class that subclasses the machine config class, or you might just have a class that always reads the machine config file in addition to the app config file and merges them internally (i.e. there is no API for accessing the machine config outside of an application context).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://526528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found