| … | |
… | |
| 10 | our @EXPORT_OK = qw( |
10 | our @EXPORT_OK = qw( |
| 11 | runtime_use |
11 | runtime_use |
| 12 | readFile |
12 | readFile |
| 13 | formatDateTime |
13 | formatDateTime |
| 14 | parseDateTime |
14 | parseDateTime |
|
|
15 | dbDecode |
|
|
16 | dbEncode |
| 15 | ref2string |
17 | ref2string |
| 16 | hash2string |
18 | hash2string |
| 17 | array2string |
19 | array2string |
| 18 | ); |
20 | ); |
| 19 | |
21 | |
| … | |
… | |
| 46 | } |
48 | } |
| 47 | |
49 | |
| 48 | sub parseDateTime($) { |
50 | sub parseDateTime($) { |
| 49 | my $string = shift; |
51 | my $string = shift; |
| 50 | return str2time $string; |
52 | return str2time $string; |
|
|
53 | } |
|
|
54 | |
|
|
55 | sub dbDecode($) { |
|
|
56 | my $string = shift; |
|
|
57 | return unless defined $string and $string; |
|
|
58 | my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g; |
|
|
59 | $hash{$_} =~ s/\\(&|=)/$1/g foreach (keys %hash); # unescape & and = |
|
|
60 | return %hash; |
|
|
61 | } |
|
|
62 | |
|
|
63 | sub dbEncode(@) { |
|
|
64 | my %hash = @_; |
|
|
65 | my $string; |
|
|
66 | foreach (keys %hash) { |
|
|
67 | $hash{$_} = "" unless defined $hash{$_}; # promote undef to "" |
|
|
68 | $hash{$_} =~ s/(=|&)/\\$1/g; # escape & and = |
|
|
69 | $string .= "$_=$hash{$_}&"; |
|
|
70 | } |
|
|
71 | chop $string; # remove final '&' from string for old code :p |
|
|
72 | return $string; |
| 51 | } |
73 | } |
| 52 | |
74 | |
| 53 | # ----- |
75 | # ----- |
| 54 | |
76 | |
| 55 | sub ref2string($;$); |
77 | sub ref2string($;$); |