Subversion Repositories DevTools

Rev

Rev 263 | Rev 6177 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
5710 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 3
#
261 dpurdie 4
# Module name   : JatsEnv.pm
5
# Module type   : Perl Module
6
# Compiler(s)   : Perl
7
# Environment(s): JATS
227 dpurdie 8
#
9
# Description   : Provide some misc environment functions
10
#
261 dpurdie 11
# Usage         : EnvImport (VarName);
12
#                 EnvImportOptional (VarName [, DefaultValue]);
227 dpurdie 13
#
14
#
15
#......................................................................#
16
 
255 dpurdie 17
require 5.006_001;
227 dpurdie 18
 
19
use strict;
20
use warnings;
263 dpurdie 21
 
22
package JatsEnv;
227 dpurdie 23
use JatsError;
24
 
263 dpurdie 25
 
26
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
27
use Exporter;
28
 
29
$VERSION = 1.00;
30
@ISA = qw(Exporter);
31
 
32
# Symbols to autoexport (:DEFAULT tag)
33
@EXPORT = qw(
34
                EnvImport
35
                EnvImportOptional
36
            );
37
 
227 dpurdie 38
#-------------------------------------------------------------------------------
39
# Function        : EnvImport
40
#
261 dpurdie 41
# Description     : Import an environment variable into the global name space
227 dpurdie 42
#                   The user should have pre-declared the usage of the variable
261 dpurdie 43
#                   with an "our".
227 dpurdie 44
#
261 dpurdie 45
# Inputs          : Name of the environment variable to import
227 dpurdie 46
#
47
# Returns         : 1
48
#                   If the variable is not present then an error message is
261 dpurdie 49
#                   generated and the program will be terminated. The assumption
50
#                   is that the variable MUST be present.
227 dpurdie 51
#
52
sub EnvImport
53
{
54
    my( $EnvVar ) = @_;
55
 
261 dpurdie 56
    EnvImportOptional ( $EnvVar, undef );
227 dpurdie 57
 
58
    Error( "Environment Variable '$EnvVar' not defined." )
261 dpurdie 59
        unless( defined ${$main::{$EnvVar}} );
227 dpurdie 60
 
61
    return 1;
62
}
63
 
64
#-------------------------------------------------------------------------------
65
# Function        : EnvImportOptional
66
#
261 dpurdie 67
# Description     : Import an environment variable into the global name space
227 dpurdie 68
#                   The user should have pre-declared the usage of the variable
261 dpurdie 69
#                   with an "our".
227 dpurdie 70
#
71
#                   If no default value is provided and the variable does not
72
#                   exist in the environment, then result will be undefined
73
#
261 dpurdie 74
# Inputs          : Name of the environment variable to import
227 dpurdie 75
#                   Default value
76
#
77
# Returns         : 1
78
#
79
sub EnvImportOptional
80
{
81
    my( $EnvVar, $DefaultValue ) = @_;
82
 
261 dpurdie 83
    unless ( defined( ${$main::{$EnvVar}} ) ) {
227 dpurdie 84
 
261 dpurdie 85
        my $value = $ENV{ $EnvVar };
86
        $value = $DefaultValue unless ( defined $value );
87
        ${$main::{$EnvVar}} = $value;
227 dpurdie 88
    }
89
    return 1;
90
}
91
 
92
1;
93