Hello,

I'm interested in discussing suggested ways to best use "PARAMS" in
CGI::App, especially regarding the distinction between those that come
from a config file, an those that are declared in the instance script. 

Let me elaborate a bit further what I'm getting at. I have a couple
different primary ways I use "params". The first to access project
specific variables. These are stored in an external configuration file,
and are accessed by several instance scripts. They include things like
database credentials, and the root URL and directory of the website I'm
working with. These variables should always be "read only".

The second way I use params() is more like they may have been
intended... to declare values that may change from instance script to
instance script on a project or across projects. These are declared
directly in the instance script.  In fact, these should nearly always be
"read only" by the application as well.

However, I find it useful to separate them from params that come from a
config file. For one, it prevents possible naming clashes. I think it's
also useful just to be clear that these kinds of things are different
from each other. 

Right now I handle this by loading my config file parameters into a hash
and then storing them as reference in a param named 'cfg'. Then when I
want to access them in a run mode, I use:

my %CFG = %{ %self->param('cfg') };

The 'params' declared in the instance script are accessed directly.


One idea I have, which I haven't tried yet, is to declare my config file 
params as 'constants'. (See 'perldoc constant'). If understand that
documentation correctly, then I could access my config variables like
this:

HTML_ROOT_URL

or even:

$self->HTML_ROOT_URL

This might solve my problem of creating the distinction I want, while
also saving me the bit of syntax of frequently recreating the %CFG hash.
Do other people have config/param handling systems they are particularly
satisfied with?

        Mark

--
http://mark.stosberg.com/ 


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

Reply via email to