Subversion Repositories DevTools

Rev

Rev 255 | Rev 263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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