IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 7, 2006, 12:56:41 PM (20 years ago)
Author:
Paul Price
Message:

Adding interpolation of environment variables within paths.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r9870 r9898  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.3 2006-11-07 03:18:39 price Exp $
     3# $Id: Config.pm,v 1.4 2006-11-07 22:56:41 price Exp $
    44
    55package PS::IPP::Config;
     
    4242    my $mdc = $parser->parse( join '', @contents); # The parsed metadata config
    4343
    44     my $path = _mdLookupStr($mdc, 'PATH'); # The path
    45     my $workdir = _mdLookupStr($mdc, 'WORKDIR'); # The working directory
     44    my $path = _interpolate_env(_mdLookupStr($mdc, 'PATH')); # The path
     45    my $workdir = _interpolate_env(_mdLookupStr($mdc, 'WORKDIR')); # The working directory
    4646    croak "PATH is not set in $name\n" unless defined $path;
    4747    croak "WORKDIR is not set in $name\n" unless defined $workdir;
     48
     49    # Interpolate environment variables in the work directory
    4850
    4951    my $self = {
     
    182184
    183185
     186# Interpolate environment variables in a directory (or colon-delimited list of directories)
     187sub _interpolate_env
     188{
     189    my $dir = shift;            # Directory of interest
     190
     191    return undef unless defined $dir;
     192
     193    print "Checking $dir\n";
     194
     195    while ($dir =~ /\$\{?(\w*)[\}\/:]?/) {
     196        my $name = $1;          # Environment variable name
     197        my $value = $ENV{$name}; # Environment variable value
     198        print "Replacing $name with $value.\n";
     199        $dir =~ s/\$\{?$name\}?/$value\//;
     200    }
     201    return $dir;
     202}
     203
    184204# Lookup the metadata, checking the type is STR
    185205sub _mdLookupStr
Note: See TracChangeset for help on using the changeset viewer.