[interchange-cvs] interchange - heins modified 4 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Fri Nov 15 08:44:00 2002


User:      heins
Date:      2002-11-15 13:43:11 GMT
Modified:  lib/Vend Config.pm Dispatch.pm Session.pm
Modified:  lib/Vend/Table Editor.pm
Log:
Change locale handling.

* Add new directive "ExecutionLocale", which defaults to "C". This is
  set before every page so that the daemon cannot be left in a bad locale.

* Changed current default resolution code to always honor a "DefaultLocale"
  directive, which existed before but was indirectly set.

* Honor any current "Locale en_US default 1" setting, or its equivalent
  in the LocaleDatabase.

* Change old method of setting locales outside of config() routine
  to setting them within the config. Default is resolved in the normal
  %Default custom routine fashion.

* Change so it only sets defaults from POSIX::localeconv() if specified
  specifically with "Locale en_US". Will not do it indirectly, so
  MV_LOCALE_NO_DEFAULTS will no longer be necessary.

* Keep track of last locale set, and if the default has not otherwise
  been specified explicitly set the default to that.

* Of course still allow default user locale setting with ScratchDefault.

I believe this will be completely compatible with the current setup and
remove ambiguity and possiblity for error.

Some examples:

        ## Always forces default locale to be de_DE, despite any future
        ## settings
        DefaultLocale  de_DE

        ## A way of setting DefaultLocale indirectly, would be rendered
        ## meaninngless by the above. Same if done in LocaleDatabase
        Locale  de_DE  default 1

        ## Set the execution locale to de_DE, so you can put , separated
        ## numbers in the db -- don't know if this would work
        ExecutionLocale  de_DE

If two locales have "default" set and no DefaultLocale is specified,
the behavior is undefined, as the first default found will be set
as the default.

Revision  Changes    Path
2.81      +59 -74    interchange/lib/Vend/Config.pm


rev 2.81, prev_rev 2.80
Index: Config.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Config.pm,v
retrieving revision 2.80
retrieving revision 2.81
diff -u -r2.80 -r2.81
--- Config.pm	6 Nov 2002 04:36:18 -0000	2.80
+++ Config.pm	15 Nov 2002 13:43:10 -0000	2.81
@@ -1,6 +1,6 @@
 # Vend::Config - Configure Interchange
 #
-# $Id: Config.pm,v 2.80 2002/11/06 04:36:18 kwalsh Exp $
+# $Id: Config.pm,v 2.81 2002/11/15 13:43:10 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -45,7 +45,7 @@
 use Vend::Util;
 use Vend::Data;
 
-$VERSION = substr(q$Revision: 2.80 $, 10);
+$VERSION = substr(q$Revision: 2.81 $, 10);
 
 my %CDname;
 
@@ -396,9 +396,11 @@
 # END GLIMPSE
 	['Locale',           'locale',           ''],
 	['Route',            'locale',           ''],
-	['LocaleDatabase',    undef,             ''],
+	['LocaleDatabase',   'configdb',         ''],
+	['ExecutionLocale',   undef,             'C'],
+	['DefaultLocale',     undef,             ''],
 	['DbDatabase',        'dbdatabase',        ''],
-	['RouteDatabase',     'routeconfig',        ''],
+	['RouteDatabase',     'configdb',        ''],
 	['DirectiveDatabase', 'dbconfig',        ''],
 	['VariableDatabase',  'dbconfig',        ''],
 	['DirConfig',         'dirconfig',        ''],
@@ -1056,44 +1058,6 @@
 		Vend::Data::read_shipping();
 		open_database(1);
 		my $db;
-
-		LREAD: {
-			last LREAD unless $db = $Vend::Cfg->{LocaleDatabase};
-			$db = database_exists_ref($db)
-				or last LREAD;
-			$db = $db->ref();
-			my ($k, @f);	# key and fields
-			my @l;			# refs to locale repository
-			my @n;			# names of locales
-
-			@n = $db->columns();
-			my $extra;
-			for(@n) {
-				$Vend::Cfg->{Locale_repository}{$_} = {}
-					unless $Vend::Cfg->{Locale_repository}{$_};
-				push @l, $Vend::Cfg->{Locale_repository}{$_};
-			}
-			my $i;
-			while( ($k , @f ) = $db->each_record) {
-				for ($i = 0; $i < @f; $i++) {
-					next unless length($f[$i]);
-					$l[$i]->{$k} = $f[$i];
-				}
-			}
-			unless ($Vend::Cfg->{Locale}) {
-				for(@n) {
-					next unless $Vend::Cfg->{Locale_repository}{$_}{'default'};
-					$Vend::Cfg->{DefaultLocale} = $_;
-					$Vend::Cfg->{Locale} = $Vend::Cfg->{Locale_repository}{$_};
-					last;
-				}
-				unless ($Vend::Cfg->{Locale}) {
-					$Vend::Cfg->{Locale} = $Vend::Cfg->{Locale_repository}{$n[0]};
-					$Vend::Cfg->{DefaultLocale} = $n[0];
-				}
-			}
-		}
-
 		close_database();
 	};
 
@@ -2069,14 +2033,7 @@
 
 	my ($eval, $safe);
 	if ($name and $item eq 'Locale') {
-		$c = POSIX::localeconv();
-		$c->{mon_thousands_sep} = ','
-			unless $c->{mon_thousands_sep};
-		$c->{decimal_point} = '.'
-			unless $c->{decimal_point};
-		$c->{frac_digits} = 2
-			unless defined $c->{frac_digits};
-		$store->{$name} = $c;
+		$store->{$name} = POSIX::localeconv();
 	}
 	elsif ($settings =~ s/^\s*([-\w.@]+)\s+//) {
 		$name = $1;
@@ -2091,11 +2048,7 @@
 				$store->{$name} = POSIX::localeconv();
 			}
 		}
-#		if(defined $store->{$name}) {
-#			for (sort keys %{$store->{$name}}) {
-#				printf "%-5s %-16s %s\n", $name, $_, $store->{$name}{$_};
-#			}
-#		}
+
 		my($sethash);
 		if ($eval) {
 			$sethash = $safe->reval($settings)
@@ -2113,22 +2066,13 @@
 		for (keys %{$sethash}) {
 			$c->{$_} = $sethash->{$_};
 		}
-		if($item eq 'Locale') {
-			$Vend::Cfg->{DefaultLocale} = $name;
-			unless ($nodefaults) {
-				$c->{mon_thousands_sep} = ','
-					unless defined $c->{mon_thousands_sep};
-				$c->{decimal_point} = '.'
-					unless $c->{decimal_point};
-				$c->{frac_digits} = 2
-					unless defined $c->{frac_digits};
-			}
-		}
 	}
 	else {
 		config_error("Bad locale setting $settings.\n");
 	}
 
+	$C->{LastLocale} = $name if $C and $item eq 'Locale';
+
 	$store->{$name} = $c unless $store->{$name};
 
 	return $c;
@@ -2333,6 +2277,27 @@
 			}
 			return 1;
 		},
+		Locale => sub {
+						my $repos = $C->{Locale_repository}
+							or return 1;
+						if ($C->{DefaultLocale}) {
+							my $def = $C->{DefaultLocale};
+							$C->{Locale} = $repos->{$def};
+						}
+						else {
+							for(keys %$repos) {
+								if($repos->{$_}{default}) {
+									$C->{Locale} = $repos->{$_};
+									$C->{DefaultLocale} = $_;
+								}
+							}
+							if(! $C->{DefaultLocale} and $C->{LastLocale}) {
+								$C->{DefaultLocale} = $C->{LastLocale};
+								$C->{Locale} = $repos->{$C->{LastLocale}};
+							}
+						}
+						return 1;
+					},
 		ProductFiles => \&set_default_search,
 );
 
@@ -2388,7 +2353,6 @@
 	return $val;
 }
 
-
 sub check_legal {
 	my ($directive, $value) = @_;
 	return 1 unless defined $IllegalValue{$directive}->{$value};
@@ -3169,13 +3133,14 @@
 	return ($db, $table);
 }
 
-sub parse_routeconfig {
+my %Columnar = (Locale => 1);
+
+sub parse_configdb {
 	my ($var, $value) = @_;
 
 	my ($file, $type);
 	return '' if ! $value;
 	local($Vend::Cfg) = $C;
-
 	my ($db, $table) = get_configdb($var, $value);
 
 	return '' if ! $db;
@@ -3185,14 +3150,34 @@
 	my @n;			# names of locales
 	my @h;			# names of locales
 
+	my $base_direc = $var;
+	$base_direc =~ s/Database$//;
+	my $repos_name = $base_direc . '_repository';
+	my $repos = $C->{$repos_name} ||= {};
+
 	@n = $db->columns();
 	shift @n;
 	my $i;
-	while( ($k, undef, @f ) = $db->each_record) {
-#::logDebug("Got route key=$k f=@f");
-		for ($i = 0; $i < @f; $i++) {
-			next unless length($f[$i]);
-			$C->{Route_repository}{$k}{$n[$i]} = $f[$i];
+	if($Columnar{$base_direc}) {
+		my @l;
+		for(@n) {
+			$repos->{$_} ||= {};
+			push @l, $repos->{$_};
+		}
+		my $i;
+		while( ($k , undef, @f ) = $db->each_record) {
+			for ($i = 0; $i < @f; $i++) {
+				next unless length($f[$i]);
+				$l[$i]->{$k} = $f[$i];
+			}
+		}
+	}
+	else {
+		while( ($k, undef, @f ) = $db->each_record) {
+			for ($i = 0; $i < @f; $i++) {
+				next unless length($f[$i]);
+				$repos->{$k}{$n[$i]} = $f[$i];
+			}
 		}
 	}
 	$db->close_table();



1.6       +3 -2      interchange/lib/Vend/Dispatch.pm


rev 1.6, prev_rev 1.5
Index: Dispatch.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Dispatch.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Dispatch.pm	8 Nov 2002 17:22:04 -0000	1.5
+++ Dispatch.pm	15 Nov 2002 13:43:10 -0000	1.6
@@ -1,6 +1,6 @@
 # Vend::Dispatch - Handle Interchange page requests
 #
-# $Id: Dispatch.pm,v 1.5 2002/11/08 17:22:04 mheins Exp $
+# $Id: Dispatch.pm,v 1.6 2002/11/15 13:43:10 mheins Exp $
 #
 # Copyright (C) 2002 ICDEVGROUP <interchange@icdevgroup.org>
 # Copyright (C) 2002 Mike Heins <mike@perusion.net>
@@ -26,7 +26,7 @@
 package Vend::Dispatch;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.5 $, 10);
+$VERSION = substr(q$Revision: 1.6 $, 10);
 
 use POSIX qw(strftime);
 use Vend::Util;
@@ -964,6 +964,7 @@
 
 	chdir $Vend::Cfg->{VendRoot} 
 		or die "Couldn't change to $Vend::Cfg->{VendRoot}: $!\n";
+	POSIX::setlocale('LC_ALL', $Vend::Cfg->{ExecutionLocale});
 	set_file_permissions();
 # STATICPAGE
 	tie_static_dbm() if $Vend::Cfg->{StaticDBM};



2.9       +3 -4      interchange/lib/Vend/Session.pm


rev 2.9, prev_rev 2.8
Index: Session.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Session.pm,v
retrieving revision 2.8
retrieving revision 2.9
diff -u -r2.8 -r2.9
--- Session.pm	30 Oct 2002 23:40:29 -0000	2.8
+++ Session.pm	15 Nov 2002 13:43:10 -0000	2.9
@@ -1,6 +1,6 @@
 # Vend::Session - Interchange session routines
 #
-# $Id: Session.pm,v 2.8 2002/10/30 23:40:29 kwalsh Exp $
+# $Id: Session.pm,v 2.9 2002/11/15 13:43:10 mheins Exp $
 # 
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -26,7 +26,7 @@
 require Exporter;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.8 $, 10);
+$VERSION = substr(q$Revision: 2.9 $, 10);
 
 @ISA = qw(Exporter);
 
@@ -460,8 +460,7 @@
 		if $CGI::secure;
 	$::Values     = $Vend::Session->{'values'};
 	$::Scratch	  = $Vend::Session->{scratch};
-	$::Scratch->{mv_locale} = $Vend::Cfg->{DefaultLocale}
-		if ! $::Scratch->{mv_locale} and $Vend::Cfg->{DefaultLocale};
+	$::Scratch->{mv_locale} ||= $Vend::Cfg->{DefaultLocale};
 	$::Carts	  = $Vend::Session->{carts};
 	tie $Vend::Items, 'Vend::Cart';
 	$::Values->{mv_shipmode} = $Vend::Cfg->{DefaultShipping}



1.18      +4 -3      interchange/lib/Vend/Table/Editor.pm


rev 1.18, prev_rev 1.17
Index: Editor.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/Editor.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Editor.pm	30 Oct 2002 17:39:06 -0000	1.17
+++ Editor.pm	15 Nov 2002 13:43:11 -0000	1.18
@@ -1,6 +1,6 @@
 # Vend::Table::Editor - Swiss-army-knife table editor for Interchange
 #
-# $Id: Editor.pm,v 1.17 2002/10/30 17:39:06 mheins Exp $
+# $Id: Editor.pm,v 1.18 2002/11/15 13:43:11 mheins Exp $
 #
 # Copyright (C) 2002 ICDEVGROUP <interchange@icdevgroup.org>
 # Copyright (C) 2002 Mike Heins <mike@perusion.net>
@@ -26,7 +26,7 @@
 package Vend::Table::Editor;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.17 $, 10);
+$VERSION = substr(q$Revision: 1.18 $, 10);
 
 use Vend::Util;
 use Vend::Interpolate;
@@ -2762,7 +2762,8 @@
 		}
 		elsif (defined $default->{$c} and ! length($data->{$c}) ) {
 			$currval = $default->{$c};
-#::logDebug("hit preload for $col,currval=$currval");
+			$overridden = 1;
+#::logDebug("hit default setting for $col,currval=$currval");
 		}
 		else {
 #::logDebug("hit data->col for $col, t=$t, c=$c, k=$k, currval=$currval");