[cgiapp] Re: Thinking about constants and different uses of params

2003-06-03 Thread Mark Stosberg
Thanks for the response Jesse. I have a couple of follow-up questions:

In article [EMAIL PROTECTED], Jesse Erlbaum wrote:

 
 For configuration file params (to use your idiom), I tend to use Perl
 modules:
 
   package Site::Configuration;
   use constant SMTP_SERVER = localhost;
 
 ...and in my CGI-App:
 
   package Site::MyApp;
   use base qw/CGI::Application/;
   use Site::Configuration;
   my $smtp_server = Site::Configuration::SMTP_SERVER;
 
 This allows me to put more functionality into my configuration:
 
   package Site::Configuration;
   sub SMTP_SERVER {
 if ($ENV{DEVMODE}) {
   return localhost;
 } else {
   return smtp.site.com;}
   }

To save typing use constant over and over, have you considered using
the hash ref method of declaring all your constants, you can just
type:
use constant $href;

Also, do you actually need to declare your sub as 

sub SMTP_SERVER ($)... for it to be used as a bare word? I'm not a
user of the 'constant' module yet, but that was my impression from the
docs.

Another question: Do you store Site::Configuration in the perllib
directory with the other perl modules? I found this made site launches a
little more difficult, because I would want to copy everything but the
Config module to the live site, which have an existing Config module
configured for the live site. Instead, I store a config file in a
config directory.

Perhaps you solve this with the if $ENV{DEVMODE} construct you
illustrated above.

Mark

-- 
 . . . . . . . . . . . . . . . . . . . . . . . . . . . 
   Mark StosbergPrincipal Developer  
   [EMAIL PROTECTED] Summersault, LLC 
   765-939-9301 ext 202 database driven websites
 . . . . . http://www.summersault.com/ . . . . . . . .


-
Web Archive:  http://www.mail-archive.com/[EMAIL PROTECTED]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [cgiapp] Re: Thinking about constants and different uses of params

2003-06-03 Thread Jesse Erlbaum
Hi Mark --

 Another question: Do you store Site::Configuration in the perllib
 directory with the other perl modules? I found this made site 
 launches a
 little more difficult, because I would want to copy 
 everything but the
 Config module to the live site, which have an existing Config module
 configured for the live site. Instead, I store a config file in a
 config directory.
 
 Perhaps you solve this with the if $ENV{DEVMODE} construct you
 illustrated above.


I definitely store Site::Configuration along with all the other
modules.

As you've identified, I use a mechanism similar to my if $ENV{DEVMODE}
example to automatically change the run-time configuration.  The system
I use is based on a few ideas:

  1. There are things called environments, of which production,
staging, and Mark's development would be a few.
  2. Each environment should have its own Apache server.
  3. Environments need to be centrally managed.
  4. The process for moving work between environments must be totally
consistent for Quality Assurance's sake.
  5. Each environment is defined by a number of distinct run-time
settings.


Regarding number five, here is a list of run-time properties for
environments in my typical system:

  ENVIRONMENT_NAME
  DEV_ROOT
  LOG_DIR
  SITE_HOST_NAME
  APACHE_IP
  APACHE_ROOT
  APACHE_PIDFILE

For each environment I have a hash containing values for these
parameters.  A control script (run via sudo) is used to start and stop
Apache.  This control script reads the environment name (e.g.,
production, mark, jesse, etc.) from a UNIX environment variable,
and selects the proper hash of environment configuration settings.  This
control script then *dynamically* creates an Apache httpd.conf from a
template (using HTML::Template, of course) populating things like the IP
address and host name.  (N.b., the DEV_ROOT property is used to
automatically set PERL5LIB and HTML_TEMPLATE_ROOT.)

As you can imagine, this system eliminates the problems usually related
to moving changes between environments.  I've been using this system for
years.


TTYL,

-Jesse-


--

  Jesse Erlbaum
  The Erlbaum Group
  [EMAIL PROTECTED]
  Phone: 212-684-6161
  Fax: 212-684-6226








-
Web Archive:  http://www.mail-archive.com/[EMAIL PROTECTED]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]