[interchange-cvs] interchange - pajamian modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Sat Aug 4 08:40:32 EDT 2007


User:      pajamian
Date:      2007-08-04 12:40:31 GMT
Modified:  .        WHATSNEW-5.5
Modified:  lib/Vend Ship.pm
Log:
The new Ship.pm seems to have a lot of problems.  Here is a patch which
addresses the following issues:

* Fixed problem where only the last shipping policy will get stored if
the multi-line format is used in shipping.asc.

* Fixed problem where options are not converted and stored properly on
all shipping policies.

* Moved more code into the new process_new_beginning sub:
	* By passing a ref to the @shipping array I can now push new records
onto the array from inside the sub.
	* The above means that the old @list array need not be returned since
it's only purpose at that point was to push the record onto @shipping,
then immediately be overwritten by @new.
	* That also means that @new can be assigned to @list inside the sub
instead of outside it.
	* Since we no longer need to return @new, this frees up the return
value which I have used to return the $first value instead.
	* Because $first is returned we no longer need to flag that condition
by assigning "_newmode" as the shipping mode.

* I also removed an entire redundant elsif branch from read_shipping.
The regexp that the branch tested for would never cause the branch to be
executed because the branch above it tests for a regexp that matches the
same lines.

I don't think it's a big deal to change the process_new_beginning sub
the way I did because the sub itself is only about 5 weeks old, so the
likelyhood of someone having implemented code around it is extremely small.

Revision  Changes    Path
1.42      +12 -0     interchange/WHATSNEW-5.5


rev 1.42, prev_rev 1.41
Index: WHATSNEW-5.5
===================================================================
RCS file: /var/cvs/interchange/WHATSNEW-5.5,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- WHATSNEW-5.5	3 Aug 2007 18:33:42 -0000	1.41
+++ WHATSNEW-5.5	4 Aug 2007 12:40:31 -0000	1.42
@@ -75,6 +75,18 @@
 * set_slice now skips updates on existing records when we have only key
   columns (#98).
 
+* Change [shipping-desc] to allow access to arbitrary keys in the shipping
+  configuration.
+
+* Fixed problem where only the last shipping policy will get stored if the
+  multi-line format is used in shipping.asc.
+
+* Fixed problem where options are not converted and stored properly on all
+  shipping policies.
+
+* Moved more code into the new process_new_beginning sub and cleaned up other
+  code in Ship.pm.
+
 UserDB
 ------
 



2.24      +25 -40    interchange/lib/Vend/Ship.pm


rev 2.24, prev_rev 2.23
Index: Ship.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Ship.pm,v
retrieving revision 2.23
retrieving revision 2.24
diff -u -r2.23 -r2.24
--- Ship.pm	4 Jul 2007 16:40:51 -0000	2.23
+++ Ship.pm	4 Aug 2007 12:40:31 -0000	2.24
@@ -1,6 +1,6 @@
 # Vend::Ship - Interchange shipping code
 # 
-# $Id: Ship.pm,v 2.23 2007/07/04 16:40:51 mheins Exp $
+# $Id: Ship.pm,v 2.24 2007/08/04 12:40:31 pajamian Exp $
 #
 # Copyright (C) 2002-2005 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -98,27 +98,41 @@
 );
 
 sub process_new_beginning {
-	my ($record, $line) = @_;
+	my ($shipping, $record, $line) = @_;
 	my @new;
+	my $first;
 
+	$line ||= '';
 	if($line =~ /^[^\s:]+\t/) {
 		@new = split /\t/, $line;
 	}
 	elsif($line =~ /^(\w+)\s*:\s*(.*)/s) {
-		@new = ($1, $2, '_newmode', 0, 99999999, 0);
+		@new = ($1, $2, '', 0, 99999999, 0);
+		$first = 1;
 	}
 
-	$Vend::Cfg->{Shipping_desc}{$new[MODE]} ||= $new[DESC];
+	$Vend::Cfg->{Shipping_desc}{$new[MODE]} ||= $new[DESC] if @new;
 
-	my $old_mode = $record->[MODE];
-	if ($old_mode and ! $Vend::Cfg->{Shipping_hash}{$old_mode}) {
+	if (@$record) {
+		my $old_mode = $record->[MODE];
 		if(! ref($record->[OPT]) ) {
 			$record->[OPT] = string_to_ref($record->[OPT]);
 		}
-		$record->[OPT]{description} ||= $Vend::Cfg->{Shipping_desc}{$old_mode};
-		$Vend::Cfg->{Shipping_hash}{$old_mode} = $record->[OPT];
+
+		if ($old_mode and ! $Vend::Cfg->{Shipping_hash}{$old_mode}) {
+			$record->[OPT]{description} ||= $Vend::Cfg->{Shipping_desc}{$old_mode};
+			$Vend::Cfg->{Shipping_hash}{$old_mode} = $record->[OPT];
+		}
+		else {
+			$record->[OPT]{description} ||= $record->[DESC];
+		}
+
+		push @$shipping, [ @$record ];
 	}
-	return @new;
+
+	@$record = @new;
+
+	return $first;
 }
 
 sub read_shipping {
@@ -241,35 +255,7 @@
 			## two previous branches that had same code doing
 			## same thing.
 
-			my @new = process_new_beginning(\@line, $_);
-			if($new[CRIT] eq '_newmode') {
-				$first = 1;
-			}
-			else {
-				push @shipping, [@new];
-			}
-			@line = @new;
-		}
-		elsif(/^(\w+)\s*:\s*(.*)/s) {
-			my $id = $1;
-			my $desc = $2;
-			my ($opt, $former);
-
-			if(@line) {
-				push (@shipping, [@line]);
-				$opt = $line[OPT];
-				$former = $line[MODE];
-			}
-
-			@line = ($id, $desc, 'quantity', 0, 999999999, 0);
-			$first = 1;
-			if( $seen{$line[MODE]}++ ) {
-				$Vend::Cfg->{Shipping_hash}{$former} ||= $opt;
-			}
-			else {
-				$Vend::Cfg->{Shipping_desc}->{$line[MODE]} = $line[DESC];
-			}
-			next;
+			$first = process_new_beginning(\@shipping, \@line, $_);
 		}
 		elsif(/^\s+min(?:imum)?\s+(\S+)/i) {
 			my $min = $1;
@@ -315,8 +301,7 @@
 		}
 	}
 
-	push @shipping, [ @line ]
-		if @line;
+	process_new_beginning(\@shipping, \@line);
 
 	if($waiting) {
 		logError(








More information about the interchange-cvs mailing list