Subversion Repositories DevTools

Rev

Rev 6177 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
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
 
6198 dpurdie 58
    no strict 'refs';
59
    $EnvVar = 'main::' . $EnvVar;
227 dpurdie 60
    Error( "Environment Variable '$EnvVar' not defined." )
6198 dpurdie 61
        unless( defined ($$EnvVar) );
227 dpurdie 62
    return 1;
63
}
64
 
65
#-------------------------------------------------------------------------------
66
# Function        : EnvImportOptional
67
#
261 dpurdie 68
# Description     : Import an environment variable into the global name space
227 dpurdie 69
#                   The user should have pre-declared the usage of the variable
261 dpurdie 70
#                   with an "our".
227 dpurdie 71
#
72
#                   If no default value is provided and the variable does not
73
#                   exist in the environment, then result will be undefined
74
#
261 dpurdie 75
# Inputs          : Name of the environment variable to import
227 dpurdie 76
#                   Default value
77
#
78
# Returns         : 1
79
#
80
sub EnvImportOptional
81
{
82
    my( $EnvVar, $DefaultValue ) = @_;
6198 dpurdie 83
    no strict 'refs';
227 dpurdie 84
 
6198 dpurdie 85
    my $GlobalEnvVar = 'main::' . $EnvVar;
227 dpurdie 86
 
6198 dpurdie 87
    unless ( defined( $$GlobalEnvVar ) ) {
88
        my $value = $::ENV{ $EnvVar };
261 dpurdie 89
        $value = $DefaultValue unless ( defined $value );
6198 dpurdie 90
        $$GlobalEnvVar = $value;
227 dpurdie 91
    }
92
    return 1;
93
}
94
 
95
1;
96
 
6198 dpurdie 97