Revert "Embed Safe 2.07 into Vend::Safe to avoid various problems with recent version...
[interchange.git] / code / SystemTag / assign.coretag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: assign.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $
9
10 UserTag assign              addAttr
11 UserTag assign              PosNumber    0
12 UserTag assign              Version      $Revision: 1.5 $
13 UserTag assign              Routine      <<EOR
14 my %_assignable = (qw/
15                                 salestax        1
16                                 shipping        1
17                                 handling        1
18                                 subtotal        1
19                                 credit          1       
20                                 /);
21 sub {
22         my ($opt) = @_;
23         if($opt->{clear}) {
24                 delete $Vend::Session->{assigned};
25                 return;
26         }
27         $Vend::Session->{assigned} ||= {};
28         for(keys %$opt) {
29                 next unless $_assignable{$_};
30                 my $value = $opt->{$_};
31                 $value =~ s/^\s+//;
32                 $value =~ s/\s+$//;
33                 if($value =~ /^-?\d+\.?\d*$/) {
34                         $Vend::Session->{assigned}{$_} = $value;
35                 }
36                 else {
37             if ($value) {
38                         logError(
39                                 "Attempted assign of non-numeric '%s' to %s. Deleted.",
40                                 $value,
41                                 $_,
42                             );
43             }
44                         delete $Vend::Session->{assigned}{$_};
45                 }
46         }
47         return;
48 }
49 EOR