Inevitably, every system has parameters which differ between development, certification and production. Any parameter which will vary in such a way should be set up as an environment variable. For testing, e.g., a new version of perl, it may be necessary to set one or more aliases. The environment script in every arena is a shell script which sets environment variables and aliases necessary for successful execution in that arena. This script is generated by the create_environment script, which requires an environment.template file and can use an environment.defaults file.
The environment.template file consists of lines like the following:
FOO_DB_SERVER= FOO_DB_USER= FOO_DB_PASS= ...
The create_environment function will prompt the user for the values of each of these variables, defaulting to the values it finds in the environment.defaults file, if available, and generate the environment shell script. In addition, it will modify the environment.defaults file to contain the same values as are contained in the environment script. The environment script will generally look like:
ENV_TEMPLATE=/home/epbzs01/foo/environment.template export ENV_TEMPLATE FOO_DB_SERVER=albsun8_sql11_prd export FOO_DB_SERVER FOO_DB_USER=foo export FOO_DB_USER FOO_DB_PASS=bar export FOO_DB_PASS
And the environment.defaults file will generally look like:
FOO_DB_SERVER=albsun8_sql11_prd FOO_DB_DB=foo_dbdata_prd FOO_DB_USER=foo FOO_DB_PASS=bar
In particular, note that the environment.defaults script may contain entries which no longer appear in the environment.template or environment files. Since the environment.template file is under source control, variables may be removed from it over time. At some point, an older version might get checked out, and we might as well have around the last default for those variables which newer versions dont contain.
There is a module, Environment.pm, to help applications and modules verify and use these environment variables. When a perl script or module incants
the environment.template file is parsed and every variable mentioned in it must have a non-null value or croak() will be called with a suitable error message. The error message will list all the non-existent variables. Furthermore, each environment variable thus mentioned will be exported to a scalar of the same name in the callers namespace. The list of variables to be exported may be limited by providing a list of names to use POP::Environment. Environment.pm knows where to find the environment.template file by looking at the ENV_TEMPLATE environment variable, which is added to environment by create_environment.