line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bb::Collaborate::Ultra::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Bb::Collaborate::Ultra::Util - Utility functions for Collaborate Ultra |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
For internal use only. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
32
|
use warnings; use strict; |
|
6
|
|
|
6
|
|
20
|
|
|
6
|
|
|
|
|
165
|
|
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
85
|
|
14
|
6
|
|
|
6
|
|
18
|
use Scalar::Util; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
260
|
|
15
|
6
|
|
|
6
|
|
383
|
use Date::Parse qw; |
|
6
|
|
|
|
|
4611
|
|
|
6
|
|
|
|
|
2943
|
|
16
|
|
|
|
|
|
|
sub _freeze { |
17
|
18
|
|
|
18
|
|
17
|
my ($val, $type) = @_; |
18
|
|
|
|
|
|
|
|
19
|
18
|
|
|
|
|
15
|
for ($val) { |
20
|
|
|
|
|
|
|
|
21
|
18
|
50
|
|
|
|
20
|
if (!defined) { |
22
|
0
|
|
|
|
|
0
|
warn "undefined value of type $type\n" |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
18
|
|
|
|
|
14
|
my $raw_val = $_; |
26
|
|
|
|
|
|
|
|
27
|
18
|
100
|
|
|
|
24
|
if ($type =~ m{^Bool}ix) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# DBize boolean flags.. |
31
|
|
|
|
|
|
|
# |
32
|
3
|
100
|
|
|
|
15
|
$_ = $_ ? 'true' : 'false'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif ($type =~ m{^(Str|enum)}ix) { |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# low level check for taintness. Only applicable when |
38
|
|
|
|
|
|
|
# perl program is running in taint mode |
39
|
|
|
|
|
|
|
# |
40
|
9
|
50
|
|
|
|
63
|
die "attempt to freeze tainted data (type $type): $_" |
41
|
|
|
|
|
|
|
if Scalar::Util::tainted($_); |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# l-r trim |
44
|
|
|
|
|
|
|
# |
45
|
9
|
50
|
|
|
|
37
|
$_ = $1 |
46
|
|
|
|
|
|
|
if m{^ \s* (.*?) \s* $}x; |
47
|
9
|
100
|
|
|
|
12
|
$_ = lc if $type =~ m{^enum}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($type =~ m{^Int}ix) { |
50
|
0
|
|
|
|
|
0
|
$_ = $_ + 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ($type =~ m{^Date}) { |
53
|
4
|
|
|
|
|
56
|
my ($sec,$min,$hr,$day,$mon,$year) = gmtime $_; |
54
|
4
|
|
|
|
|
22
|
$_ = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ", |
55
|
|
|
|
|
|
|
$year+1900, $mon+1, $day, $hr, $min, $sec; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($type =~ m{^Ref|Any|Hash}ix) { |
58
|
|
|
|
|
|
|
# pass through |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
2
|
50
|
|
|
|
36
|
die "unable to convert $raw_val to $type\n" |
62
|
|
|
|
|
|
|
unless defined; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
18
|
|
|
|
|
68
|
return $val; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# |
71
|
|
|
|
|
|
|
# thawing of elementary data-types |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _thaw { |
75
|
24
|
|
|
24
|
|
17
|
my ($val, $type) = @_; |
76
|
|
|
|
|
|
|
|
77
|
24
|
100
|
66
|
|
|
77
|
return $val |
78
|
|
|
|
|
|
|
if !defined $val || $type =~ m{Ref|Array}i; |
79
|
|
|
|
|
|
|
|
80
|
22
|
|
|
|
|
123
|
for ($val) { |
81
|
|
|
|
|
|
|
|
82
|
22
|
100
|
|
|
|
28
|
if ($type =~ m{^Bool}i) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# |
84
|
|
|
|
|
|
|
# Perlise boolean flags.. |
85
|
|
|
|
|
|
|
# |
86
|
6
|
100
|
|
|
|
50
|
$_ = m{^(true|1)$}i ? 1 : 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif ($type =~ m{^(Str|enum)}i) { |
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
# l-r trim |
91
|
|
|
|
|
|
|
# |
92
|
8
|
50
|
|
|
|
71
|
$_ = $1 |
93
|
|
|
|
|
|
|
if m{^ \s* (.*?) \s* $}x; |
94
|
8
|
100
|
|
|
|
10
|
$_ = lc if $type =~ m{^enum}i; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif ($type =~ m{^Int}i) { |
97
|
0
|
|
|
|
|
0
|
$_ = $_ + 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif ($type =~ m{^Date}) { |
100
|
8
|
|
|
|
|
103
|
$_ = str2time $_; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ($type =~ m{^Ref|Any|Hash}ix) { |
103
|
|
|
|
|
|
|
# pass through |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
0
|
|
|
|
|
0
|
die "unknown type: $type"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
|
110
|
22
|
|
|
|
|
1072
|
return $val; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |