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');
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|