Rev 263 | Blame | Compare with Previous | Last modification | View Log | RSS feed
######################################################################### Copyright ( C ) 2006 ERG Limited, All rights reserved## Module name : JatsEnv.pm# Module type : Perl Module# Compiler(s) : Perl# Environment(s): JATS## Description : Provide some misc environment functions## Usage : EnvImport (VarName);# EnvImportOptional (VarName [, DefaultValue]);###......................................................................#require 5.006_001;use strict;use warnings;package JatsEnv;use JatsError;our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);use Exporter;$VERSION = 1.00;@ISA = qw(Exporter);# Symbols to autoexport (:DEFAULT tag)@EXPORT = qw(EnvImportEnvImportOptional);#-------------------------------------------------------------------------------# Function : EnvImport## Description : Import an environment variable into the global name space# The user should have pre-declared the usage of the variable# with an "our".## Inputs : Name of the environment variable to import## Returns : 1# If the variable is not present then an error message is# generated and the program will be terminated. The assumption# is that the variable MUST be present.#sub EnvImport{my( $EnvVar ) = @_;EnvImportOptional ( $EnvVar, undef );Error( "Environment Variable '$EnvVar' not defined." )unless( defined ${$main::{$EnvVar}} );return 1;}#-------------------------------------------------------------------------------# Function : EnvImportOptional## Description : Import an environment variable into the global name space# The user should have pre-declared the usage of the variable# with an "our".## If no default value is provided and the variable does not# exist in the environment, then result will be undefined## Inputs : Name of the environment variable to import# Default value## Returns : 1#sub EnvImportOptional{my( $EnvVar, $DefaultValue ) = @_;unless ( defined( ${$main::{$EnvVar}} ) ) {my $value = $ENV{ $EnvVar };$value = $DefaultValue unless ( defined $value );${$main::{$EnvVar}} = $value;}return 1;}1;