[interchange-cvs] interchange - jon modified lib/Vend/Config.pm

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Wed Jan 2 18:26:01 2002


User:      jon
Date:      2002-01-02 23:25:57 GMT
Modified:  lib/Vend Config.pm
Log:
Miscellaneous changes in Config.pm. Using a standard Foundation
catalog, these changes don't change the resulting global or catalog
structures at all.

* In variable parsing:
  - Remove never-used %%VARIABLE%% capability for extra level of parsing.
  - Parse catalog variables before globals, to remedy an unexpected
    situation. Given:

    (Global) Variable SUPERDOM ic.redhat.com
    Variable TESTUSER devnull
    Variable TESTDOM ic.redhat.com

    This:

    MailOrderTo __TESTUSER__@__TESTDOM__

    Comes out as expected:

    MailOrderTo -> devnull@ic.redhat.com

    But this:

    MailOrderTo __TESTUSER__@@@SUPERDOM@@

    Comes out like this:

    MailOrderTo -> __TESTUSER__@ic.redhat.com

    Adding any global variable causes all catalog variables in the same
    directive not to parse.

* ConfigParseComments doesn't need an explicit default set in code,
  because the directive specifies its own default.
  (No functional change.)

* A couple of simplifications, and a typo fix.

Revision  Changes    Path
2.18      +11 -26    interchange/lib/Vend/Config.pm


rev 2.18, prev_rev 2.17
Index: Config.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Config.pm,v
retrieving revision 2.17
retrieving revision 2.18
diff -u -u -r2.17 -r2.18
--- Config.pm	2001/12/28 17:16:26	2.17
+++ Config.pm	2002/01/02 23:25:57	2.18
@@ -1,6 +1,6 @@
 # Vend::Config - Configure Interchange
 #
-# $Id: Config.pm,v 2.17 2001/12/28 17:16:26 mheins Exp $
+# $Id: Config.pm,v 2.18 2002/01/02 23:25:57 jon Exp $
 #
 # Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -95,7 +95,7 @@
 use Vend::Parse;
 use Vend::Util;
 
-$VERSION = substr(q$Revision: 2.17 $, 10);
+$VERSION = substr(q$Revision: 2.18 $, 10);
 
 my %CDname;
 
@@ -607,15 +607,10 @@
 # This is what happens when ParseVariables is true
 sub substitute_variable {
 	my($val) = @_;
-	# Return after globals so can others can be contained
-	$val =~ s/\@\@([A-Z][A-Z_0-9]+[A-Z0-9])\@\@/$Global::Variable->{$1}/g
-		and return $val;
-	return $val unless $val =~ /([_%])\1/;
 	1 while $val =~ s/__([A-Z][A-Z_0-9]*?[A-Z0-9])__/$C->{Variable}->{$1}/g;
-	# YALOS (yet another level)
-	return $val unless $val =~ /%%[A-Z]/;
-	$val =~ s/%%([A-Z][A-Z_0-9]+[A-Z0-9])%%/$Global::Variable->{$1}/g;
-	$val =~ s/__([A-Z][A-Z_0-9]*?[A-Z0-9])__/$C->{Variable}->{$1}/g;
+	# Only parse once for globals so they can contain other
+	# global and catalog variables
+	$val =~ s/\@\@([A-Z][A-Z_0-9]+[A-Z0-9])\@\@/$Global::Variable->{$1}/g;
 	return $val;
 }
 
@@ -631,7 +626,7 @@
 	my($catalog, $dir, $confdir, $subconfig, $existing, $passed_file) = @_;
 	my($d, $parse, $var, $value, $lvar);
 
-	if(ref $existing) {
+	if(ref $existing eq 'HASH') {
 #::logDebug("existing=$existing");
 		$C = $existing;
 	}
@@ -640,8 +635,6 @@
 		$C = {};
 		$C->{CatalogName} = $catalog;
 		$C->{VendRoot} = $dir;
-		# Default to old #ifdef, #endif, #include syntax for backward compatibility
-		$C->{ConfigParseComments} = 1;
 
 		unless (defined $subconfig) {
 			$C->{ErrorFile} = 'error.log';
@@ -744,8 +737,8 @@
 	my $read = sub {
 		my ($lvar, $value, $tie) = @_;
 		$parse = $parse{$lvar};
-					# call the parsing function for this directive
-		if($C->{ParseVariables} and $value =~ /([_%@])\1/) {
+		# call the parsing function for this directive
+		if($C->{ParseVariables} and $value =~ /(?:__|\@\@)/) {
 			save_variable($CDname{$lvar}, $value);
 			$value = substitute_variable($value);
 		}
@@ -1056,9 +1049,6 @@
 
 	$Global::Structure = {} unless $Global::Structure;
 
-	# Default to old #ifdef, #endif, #include syntax for backward compatibility
-	$Global::ConfigParseComments = 1;
-
 	# Prevent parsers from thinking it is a catalog
 	undef $C;
 
@@ -1856,7 +1846,7 @@
 
 # Set the default search files based on ProductFiles setting
 # Honor a NO_SEARCH parameter in the Database structure
-# Set MV_DEFAULT_SEARCH_FILES to the {file} entry,
+# Set MV_DEFAULT_SEARCH_FILE to the {file} entry,
 # and set MV_DEFAULT_SEARCH_TABLE to the table name.
 #
 # Error out if not SubCatalog and can't find a setting.
@@ -3112,13 +3102,8 @@
 		$c = ${"Global::$var"};
 	}
 
-	if($value =~ /\n/) {
-		($name, $param) = split /\s+/, $value, 2;
-		chomp $param;
-	}
-	else {
-		($name, $param) = split /\s+/, $value, 2;
-	}
+	($name, $param) = split /\s+/, $value, 2;
+	chomp $param;
 	$c->{$name} = $param;
 	return $c;
 }