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

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Tue Oct 9 18:30:01 2001


User:      heins
Date:      2001-10-09 22:29:58 GMT
Modified:  lib/Vend Interpolate.pm
Log:
	* Try again to commit serialization changes....this is frustrating
	  to have CVS be so darn slow.

	* Add new access method to [data ...] tag. If the serial=1 option
	  is added, and the column name contains a ".", the value is automatically
	  serialized into a hash structure.

	  So, if you use this tag:

	  	[data  table=mv_metadata
			   column=extended.ui_data_fields
			   key=country
			   value="code name shipmodes tax"
			   serial=1]

	  It would store in extended:

	  	{ ui_data_fields => 'code name shipmodes tax' }

	  And when you reference it, it would be:

	  	[data  table=mv_metadata
			   column=extended.ui_data_fields
			   key=country
			   serial=1]

	  returning:

	  	code name shipmodes tax

	  If there is existing serialized hash data it is read then
	  the proper thing is done. If the serialized data has a syntax
	  error not making it evaluate to a hash, then it will be silently
	  emptied and overwritten. Add an error?

   * Change move_combo JS addItem call so that variable names with periods
     in them are handled.

Revision  Changes    Path
2.17      +34 -8     interchange/lib/Vend/Interpolate.pm


rev 2.17, prev_rev 2.16
Index: Interpolate.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.16
retrieving revision 2.17
diff -u -r2.16 -r2.17
--- Interpolate.pm	2001/10/07 11:53:21	2.16
+++ Interpolate.pm	2001/10/09 22:29:57	2.17
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.16 2001/10/07 11:53:21 racke Exp $
+# $Id: Interpolate.pm,v 2.17 2001/10/09 22:29:57 mheins 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.16 $, 10);
+$VERSION = substr(q$Revision: 2.17 $, 10);
 
 @EXPORT = qw (
 
@@ -820,10 +820,6 @@
 			return '';
 		}
 	}
-	elsif($opt->{increment}) {
-#::logDebug("increment_field: key=$key field=$field value=$opt->{value}");
-		return increment_field($Vend::Database{$selector},$key,$field,$opt->{value} || 1);
-	}
 	elsif (defined $opt->{value}) {
 #::logDebug("alter table: table=$selector alter=$opt->{alter} field=$field value=$opt->{value}");
 		my $db = $Vend::Database{$selector};
@@ -849,9 +845,39 @@
 			$opt->{value} = filter_value($opt->{filter}, $opt->{value}, $field)
 				if $opt->{filter};
 #::logDebug("set_field: table=$selector key=$key field=$field foreign=$opt->{foreign} value=$opt->{value}");
-			return set_field($selector,$key,$field,$opt->{value},$opt->{append}, $opt->{foreign});
+			my $orig = $opt->{value};
+			if($opt->{serial}) {
+				$field =~ s/\.(.*)//;
+				my $hk = $1;
+				my $current = database_field($selector,$key,$field,$opt->{foreign});
+				$opt->{value} = dotted_hash($current, $hk, $orig);
+			}
+			my $result = set_field(
+							$selector,
+							$key,
+							$field,
+							$opt->{value},
+							$opt->{append},
+							$opt->{foreign},
+						);
+			return $orig if $opt->{serial};
+			return $result
 		}
 	}
+	elsif($opt->{increment}) {
+#::logDebug("increment_field: key=$key field=$field value=$opt->{value}");
+		return increment_field($Vend::Database{$selector},$key,$field,$opt->{value} || 1);
+	}
+	elsif ($opt->{serial}) {
+		$field =~ s/\.(.*)//;
+		my $hk = $1;
+		return ed(
+					dotted_hash(
+						database_field($selector,$key,$field,$opt->{foreign}),
+						$hk,
+					)
+				);
+	}
 	elsif ($opt->{hash}) {
 		my $db = ::database_exists_ref($selector);
 		return undef unless $db->record_exists($key);
@@ -2362,7 +2388,7 @@
 		$opt->{rows} = $opt->{rows} || $1 || 1;
 		$opt->{cols} = $opt->{cols} || $2 || 16;
 		my $ejs = ",1" if $opt->{rows} > 1;
-		$opt->{js} = qq{onChange="addItem(this.form.X$name,this.form.$name$ejs)"}
+		$opt->{js} = qq{onChange="addItem(this.form['X$name'],this.form['$name']$ejs)"}
 			unless $opt->{js};
 		my $out = build_accessory_select("X$name", $type, '', $opt, @opts);
 		if($opt->{rows} > 1) {