Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Configuration Best Practices for Web Apps

by cbrandtbuffalo (Deacon)
on Jan 30, 2006 at 19:09 UTC ( #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') . ""; # Now, inside, 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 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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2020-08-13 02:59 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (69 votes). Check out past polls.