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

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Tue Jan 21 11:10:01 2003


User:      heins
Date:      2003-01-21 16:09:09 GMT
Modified:  lib/Vend Util.pm
Log:
* The [setlocale currency=xx_XX] tag was destructive. This fixes it.

Revision  Changes    Path
2.46      +34 -10    interchange/lib/Vend/Util.pm


rev 2.46, prev_rev 2.45
Index: Util.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Util.pm,v
retrieving revision 2.45
retrieving revision 2.46
diff -u -r2.45 -r2.46
--- Util.pm	2 Jan 2003 23:27:07 -0000	2.45
+++ Util.pm	21 Jan 2003 16:09:09 -0000	2.46
@@ -1,6 +1,6 @@
 # Vend::Util - Interchange utility functions
 #
-# $Id: Util.pm,v 2.45 2003/01/02 23:27:07 mheins Exp $
+# $Id: Util.pm,v 2.46 2003/01/21 16:09:09 mheins Exp $
 # 
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -85,7 +85,7 @@
 use Safe;
 use subs qw(logError logGlobal);
 use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.45 $, 10);
+$VERSION = substr(q$Revision: 2.46 $, 10);
 
 BEGIN {
 	eval {
@@ -426,8 +426,6 @@
             $Vend::Cfg->{$_} = $curr->{$_}
                 if defined $curr->{$_};
         }
-        @{$Vend::Cfg->{Locale}}{@Vend::Config::Locale_keys_currency} =
-                @{$curr}{@Vend::Config::Locale_keys_currency};
     }
 
 	if(my $ref = $Vend::Cfg->{CodeDef}{LocaleChange}) {
@@ -440,8 +438,22 @@
 		}
 	}
 
-    $::Scratch->{mv_locale}   = $locale    if $opt->{persist} and $locale;
-    $::Scratch->{mv_currency} = $currency  if $opt->{persist} and $currency;
+    if($opt->{persist}) {
+		$::Scratch->{mv_locale}   = $locale		if $locale;
+		delete $::Scratch->{mv_currency_tmp};
+		delete $::Scratch->{mv_currency};
+		$::Scratch->{mv_currency} = $currency if $currency;
+	}
+	elsif($currency) {
+		Vend::Interpolate::set_tmp('mv_currency_tmp')
+			unless defined $::Scratch->{mv_currency_tmp};
+		$::Scratch->{mv_currency_tmp} = $currency;
+	}
+	else {
+		delete $::Scratch->{mv_currency_tmp};
+		delete $::Scratch->{mv_currency};
+	}
+
     return '';
 }
 
@@ -459,7 +471,22 @@
 	my $fmt;
 	my $precede = '';
 	my $succede = '';
-	if ($loc = $opt->{locale} || $Vend::Cfg->{Locale}) {
+	my $loc = $opt->{locale}
+			|| $::Scratch->{mv_currency_tmp}
+			|| $::Scratch->{mv_currency}
+			|| $Vend::Cfg->{Locale};
+
+	if(ref($loc)) {
+		## Do nothing, is a hash reference
+	}
+	elsif($loc) {
+		$loc = $Vend::Cfg->{Locale_repository}{$loc};
+	}
+	
+	if (! $loc) {
+		$fmt = "%.2f";
+	}
+	else {
 		$sep = $loc->{mon_thousands_sep} || $loc->{thousands_sep} || ',';
 		$dec = $loc->{mon_decimal_point} || $loc->{decimal_point} || '.';
 		return picture_format($amount, $loc->{price_picture}, $sep, $dec)
@@ -476,9 +503,6 @@
 				$succede = " $succede" if $loc->{p_sep_by_space};
 			}
 		}
-	}
-	else {
-		$fmt = "%.2f";
 	}
 
 	$amount = safe_sprintf($fmt, $amount);