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

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Tue Jan 15 21:11:00 2002


User:      jon
Date:      2002-01-16 02:10:19 GMT
Modified:  lib/Vend Interpolate.pm
Log:
Don't complain about missing field names unless they are actually
referenced in prefix-param and if-prefix-param. Check this once for
the loop body, rather than in the tag substitution loop, for speed.
Use new logOnce routine to keep logs from getting too bloated.

Thanks to Kevin Walsh for pointing out the unnecessary error messages.

Also comment out a block used only for debugging.

Revision  Changes    Path
2.38      +14 -6     interchange/lib/Vend/Interpolate.pm


rev 2.38, prev_rev 2.37
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.37
retrieving revision 2.38
diff -u -u -r2.37 -r2.38
--- Interpolate.pm	2002/01/11 08:48:06	2.37
+++ Interpolate.pm	2002/01/16 02:10:19	2.38
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.37 2002/01/11 08:48:06 jon Exp $
+# $Id: Interpolate.pm,v 2.38 2002/01/16 02:10:19 jon Exp $
 #
 # Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.37 $, 10);
+$VERSION = substr(q$Revision: 2.38 $, 10);
 
 @EXPORT = qw (
 
@@ -4547,9 +4547,9 @@
 	local($Safe_data);
 	$Safe_data = 1 if $opt->{safe_data};
 
-	if($opt->{prefix} eq 'item') {
+#	if($opt->{prefix} eq 'item') {
 #::logDebug("labeled list: opt:\n" . ::uneval($opt) . "\nobj:" . ::uneval($obj) . "text:" . substr($text,0,100));
-	}
+#	}
 	$Orig_prefix = $Prefix = $opt->{prefix} || 'item';
 
 	$B  = qr(\[$Prefix)i;
@@ -4659,8 +4659,7 @@
 				$fh->{$_} = $idx++;
 			}
 		}
-		logError("Missing mv_field_hash and/or mv_field_names in Vend::Interpolate::labeled_list")
-			unless ref $fh eq 'HASH';
+#::logDebug("Missing mv_field_hash and/or mv_field_names in Vend::Interpolate::labeled_list") unless ref $fh eq 'HASH';
 		$r = iterate_array_list($i, $end, $count, $text, $ary, $opt_select, $fh);
 	}
 	$MVSAFE::Unsafe = $save_unsafe;
@@ -4951,6 +4950,15 @@
 					  {
 					  	resolve_nested_if($1, $2)
 					  }se;
+
+	# log helpful errors if any unknown field names are
+	# used in if-prefix-param or prefix-param tags
+	my @field_msg = ('error', "Unknown field name '%s' used in tag %s");
+	$run = $text;
+	$run =~ s#$B$QR{_param}# defined $fh->{$1} ||
+		::logOnce(@field_msg, $1, "$Orig_prefix-param") #ige;
+	$run =~ s#$IB$QR{_param_if}# defined $fh->{$3} ||
+		::logOnce(@field_msg, $3, "if-$Orig_prefix-param") #ige;
 
 	for( ; $i <= $end ; $i++, $count++ ) {
 		$row = $ary->[$i];