Subversion Repositories DevTools

Rev

Rev 229 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
3
# Copyright ( C ) 2006 ERG Limited, All rights reserved
4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Provide some misc environment functions
11
#                 Note this is not a "package" as we will be importing
12
#                 variables directly into the users space.
13
#
14
# Usage:
15
#
16
# Version   Who      Date        Description
17
#
18
#......................................................................#
19
 
20
require 5.6.1;
21
 
22
use strict;
23
use warnings;
24
use JatsError;
25
 
26
#-------------------------------------------------------------------------------
27
# Function        : EnvImport
28
#
29
# Description     : Import an environment variable into the current user space
30
#                   The user should have pre-declared the usage of the variable
31
#                   with an "our". For this reason this package is not a
32
#                   'package'. Rather it is simply imported.
33
#
34
# Inputs          : Name of the environment varibale to import
35
#
36
# Returns         : 1
37
#                   If the variable is not present then an error message is
38
#                   generated and the program will be termianted. The assumption
39
#                   is tha the variable MUST be present.
40
#
41
sub EnvImport
42
{
43
    my( $EnvVar ) = @_;
44
 
45
    no strict 'refs';
46
    unless ( defined( $$EnvVar ) ) {
47
        $$EnvVar = $ENV{ $EnvVar };
48
    }
49
    use strict;
50
 
51
    Error( "Environment Variable '$EnvVar' not defined." )
52
        unless( defined $$EnvVar );
53
 
54
    return 1;
55
}
56
 
57
#-------------------------------------------------------------------------------
58
# Function        : EnvImportOptional
59
#
60
# Description     : Import an environment variable into the current user space
61
#                   The user should have pre-declared the usage of the variable
62
#                   with an "our". For this reason this package is not a
63
#                   'package'. Rather it is simply imported.
64
#
65
#                   If no default value is provided and the variable does not
66
#                   exist in the environment, then result will be undefined
67
#
68
# Inputs          : Name of the environment varibale to import
69
#                   Default value
70
#
71
# Returns         : 1
72
#
73
sub EnvImportOptional
74
{
75
    my( $EnvVar, $DefaultValue ) = @_;
76
 
77
    my $value = $ENV{ $EnvVar } || $DefaultValue;
78
 
79
    no strict 'refs';
80
    unless ( defined( $$EnvVar ) ) {
81
        $$EnvVar = $value;
82
    }
83
    use strict;
84
 
85
    return 1;
86
}
87
 
88
1;
89