line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package SQL::Admin::Utils; |
3
|
5
|
|
|
5
|
|
505717
|
use base qw( Exporter ); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
523
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
28
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
290
|
|
6
|
5
|
|
|
5
|
|
40
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
300
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = v0.5.0; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
###################################################################### |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
28
|
use List::Util; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
8447
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
###################################################################### |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
17
|
|
|
|
|
|
|
qw( refhash refarray ), |
18
|
|
|
|
|
|
|
qw( empty ignore not_implemented ), |
19
|
|
|
|
|
|
|
qw( token literal aval aexp vlist hvlist), |
20
|
|
|
|
|
|
|
qw( type kwset val hoption happend ), |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
qw( href ), |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
qw( true false alias ), |
25
|
|
|
|
|
|
|
qw( expr_stm ), |
26
|
|
|
|
|
|
|
qw( expr expr_map expr_list expr_vlist expr_key expr_set expr_type ), |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
qw( reflist ), |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK, ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
###################################################################### |
34
|
|
|
|
|
|
|
###################################################################### |
35
|
|
|
|
|
|
|
sub refhash ( ;$ ) { # ; |
36
|
3731
|
100
|
|
3731
|
0
|
32049
|
'HASH' eq ref (@_ ? $_[0] : $_); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
###################################################################### |
41
|
|
|
|
|
|
|
###################################################################### |
42
|
|
|
|
|
|
|
sub refarray ( ;$ ) { # ; |
43
|
2696
|
50
|
|
2696
|
0
|
15933
|
'ARRAY' eq ref (@_ ? $_[0] : $_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
###################################################################### |
48
|
|
|
|
|
|
|
###################################################################### |
49
|
|
|
|
|
|
|
sub href ( ;@ ) { # ; |
50
|
976
|
|
|
976
|
0
|
50575
|
+{@_} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
###################################################################### |
55
|
|
|
|
|
|
|
###################################################################### |
56
|
|
|
|
|
|
|
sub aexp ( @ ) { # ; |
57
|
830
|
100
|
|
830
|
0
|
6685
|
map refarray ($_) ? @$_ : $_, @_ |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
###################################################################### |
62
|
|
|
|
|
|
|
###################################################################### |
63
|
|
|
|
|
|
|
sub tree ( @ ) { # ; |
64
|
0
|
|
|
0
|
0
|
0
|
+{ $_[0] => [@_[1..$#_]] }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
###################################################################### |
69
|
|
|
|
|
|
|
###################################################################### |
70
|
|
|
|
|
|
|
sub hmap ( @ ) { # ; |
71
|
325
|
|
|
325
|
0
|
1130
|
href ($_[0], href (map %$_, grep refhash, @_)) |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
###################################################################### |
76
|
|
|
|
|
|
|
###################################################################### |
77
|
|
|
|
|
|
|
sub happend ( @ ) { # ; |
78
|
9
|
|
|
9
|
0
|
627
|
my $to = shift; |
79
|
9
|
|
|
|
|
34
|
hmap %$to, aexp @_; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
###################################################################### |
84
|
|
|
|
|
|
|
###################################################################### |
85
|
|
|
|
|
|
|
sub hval ( @ ) { # ; |
86
|
0
|
0
|
|
0
|
0
|
0
|
return {} if @_ == 1; |
87
|
0
|
|
|
|
|
0
|
my $h = { @_ }; |
88
|
0
|
|
|
|
|
0
|
$_ = (values %$_)[0] for grep refhash, values %$h; |
89
|
0
|
|
|
|
|
0
|
$h |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
###################################################################### |
94
|
|
|
|
|
|
|
###################################################################### |
95
|
0
|
|
|
0
|
0
|
0
|
sub hmerge { href (map %$_, grep refhash, @_) } |
96
|
0
|
|
|
0
|
0
|
0
|
sub empty {({})} |
97
|
0
|
|
|
0
|
0
|
0
|
sub ignore {({})} |
98
|
|
|
|
|
|
|
sub not_implemented { # ; |
99
|
|
|
|
|
|
|
+{} |
100
|
49
|
|
|
49
|
0
|
93746
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
###################################################################### |
104
|
|
|
|
|
|
|
###################################################################### |
105
|
289
|
|
|
289
|
0
|
511120
|
sub token ( @ ) { href (@_) } |
106
|
12
|
|
|
12
|
0
|
79532
|
sub literal ( @ ) { shift } |
107
|
|
|
|
|
|
|
sub vlist ( @ ) { # ; |
108
|
110
|
|
|
110
|
0
|
405
|
[ map values %$_, grep refhash, aexp (@_) ] |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
###################################################################### |
112
|
|
|
|
|
|
|
###################################################################### |
113
|
|
|
|
|
|
|
sub hvlist ( @ ) { # ; |
114
|
0
|
|
|
0
|
0
|
0
|
href $_[0], vlist @_; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
###################################################################### |
118
|
|
|
|
|
|
|
###################################################################### |
119
|
|
|
|
|
|
|
sub alias ( @ ) { # ; |
120
|
737
|
|
|
737
|
0
|
47935
|
my ($rule, $value) = @_; |
121
|
737
|
50
|
|
|
|
2482
|
return {} if @_ == 1; |
122
|
|
|
|
|
|
|
|
123
|
737
|
|
|
|
|
21619
|
+{ $rule => (values %$value)[0] }; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
###################################################################### |
128
|
|
|
|
|
|
|
###################################################################### |
129
|
|
|
|
|
|
|
sub expr_type ( @ ) { # ; |
130
|
113
|
|
|
113
|
0
|
213177
|
my ($type, @params) = @_; |
131
|
113
|
|
|
|
|
304
|
$type =~ s/^ (?: data_ )? type_ //x; |
132
|
|
|
|
|
|
|
|
133
|
113
|
|
|
|
|
622
|
expr_set ({ data_type => $type }, aexp reverse @params); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
###################################################################### |
138
|
|
|
|
|
|
|
###################################################################### |
139
|
|
|
|
|
|
|
sub type ( @ ) { # ; |
140
|
0
|
|
|
0
|
0
|
0
|
my ($type, @params) = @_; |
141
|
0
|
|
|
|
|
0
|
$type =~ s/^ (?: data_ )? type_ //x; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
hmerge ({ data_type => $type }, aexp reverse @params); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
###################################################################### |
148
|
|
|
|
|
|
|
###################################################################### |
149
|
|
|
|
|
|
|
sub kwset ( @ ) { # ; |
150
|
0
|
|
|
0
|
0
|
0
|
shift; |
151
|
0
|
|
|
|
|
0
|
[ lc join '_', @_ ]; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
###################################################################### |
156
|
|
|
|
|
|
|
###################################################################### |
157
|
|
|
|
|
|
|
sub val ( $ ) { # ; |
158
|
0
|
0
|
|
0
|
0
|
0
|
return undef unless refhash $_[0]; |
159
|
0
|
|
|
|
|
0
|
(values %{ $_[0] })[0]; |
|
0
|
|
|
|
|
0
|
|
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
###################################################################### |
163
|
|
|
|
|
|
|
###################################################################### |
164
|
|
|
|
|
|
|
sub hoption ( @ ) { # ; |
165
|
13
|
|
|
13
|
0
|
18745
|
my ($key, $val) = @_; |
166
|
13
|
50
|
|
|
|
42
|
$val = [ $val ] unless refarray $val; |
167
|
|
|
|
|
|
|
|
168
|
13
|
50
|
|
|
|
357
|
@$val ? {$key => 1} : {}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
###################################################################### |
173
|
|
|
|
|
|
|
###################################################################### |
174
|
|
|
|
|
|
|
sub expr ( @ ) { # ; |
175
|
986
|
|
|
986
|
0
|
994678
|
my $key = shift; |
176
|
986
|
|
|
1355
|
|
6473
|
my $val = List::Util::first { ref } @_; |
|
1355
|
|
|
|
|
2585
|
|
177
|
986
|
100
|
|
|
|
6463
|
$val = pop unless ref $val; |
178
|
|
|
|
|
|
|
|
179
|
986
|
100
|
66
|
|
|
2680
|
($val) = (values %$val) |
180
|
|
|
|
|
|
|
if refhash ($val) and 2 > scalar keys %$val; |
181
|
|
|
|
|
|
|
|
182
|
986
|
|
|
|
|
33269
|
+{ $key, $val }; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
###################################################################### |
187
|
|
|
|
|
|
|
###################################################################### |
188
|
|
|
|
|
|
|
sub expr_map ( @ ) { # ; |
189
|
316
|
|
|
316
|
0
|
271892
|
hmap aexp @_; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
###################################################################### |
194
|
|
|
|
|
|
|
###################################################################### |
195
|
|
|
|
|
|
|
sub expr_stm ( @ ) { # ; |
196
|
100
|
|
|
100
|
0
|
125308
|
expr_map @_; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
###################################################################### |
201
|
|
|
|
|
|
|
###################################################################### |
202
|
|
|
|
|
|
|
sub expr_set ( @ ) { # ; |
203
|
235
|
|
|
235
|
0
|
135403
|
+{ map %$_, grep refhash, aexp @_ } |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
###################################################################### |
208
|
|
|
|
|
|
|
###################################################################### |
209
|
|
|
|
|
|
|
sub expr_vlist ( @ ) { # ; |
210
|
110
|
|
|
110
|
0
|
23183
|
+{ $_[0] => vlist @_ }; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
###################################################################### |
215
|
|
|
|
|
|
|
###################################################################### |
216
|
|
|
|
|
|
|
sub expr_list ( @ ) { # ; |
217
|
9
|
|
|
9
|
0
|
2106
|
+{ shift() => [ grep ref, aexp @_ ] }; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
###################################################################### |
222
|
|
|
|
|
|
|
###################################################################### |
223
|
|
|
|
|
|
|
sub expr_key ( @ ) { # ; |
224
|
14
|
|
|
14
|
0
|
26397
|
+{ $_[0] => 1 }; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
###################################################################### |
229
|
|
|
|
|
|
|
###################################################################### |
230
|
|
|
|
|
|
|
sub true { |
231
|
0
|
|
|
0
|
0
|
|
[ 1 ] |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
###################################################################### |
236
|
|
|
|
|
|
|
###################################################################### |
237
|
|
|
|
|
|
|
sub false { |
238
|
0
|
|
|
0
|
0
|
|
[ 0 ] |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
###################################################################### |
243
|
|
|
|
|
|
|
###################################################################### |
244
|
|
|
|
|
|
|
sub reflist ( @ ) { # ; |
245
|
0
|
|
|
0
|
0
|
|
[ grep ref, @_ ] |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
package SQL::Admin::Utils; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
1; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=pod |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 NAME |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
SQL::Admin::Utils |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 DESCRIPTION |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
common utils |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|