line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::XrmDatabase::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Constants that won't change, and other utilitarian things. |
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
108
|
use v5.26; |
|
8
|
|
|
|
|
27
|
|
6
|
8
|
|
|
8
|
|
45
|
use warnings; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
395
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
60
|
use Config::XrmDatabase::Failure ':all'; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
962
|
|
11
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
|
4299
|
use namespace::clean; |
|
8
|
|
|
|
|
134430
|
|
|
8
|
|
|
|
|
53
|
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
2587
|
use Exporter 'import'; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
264
|
|
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
8
|
|
4410
|
use experimental qw( signatures postderef ); |
|
8
|
|
|
|
|
29907
|
|
|
8
|
|
|
|
|
46
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %CONSTANTS; |
19
|
|
|
|
|
|
|
our ( %META, %RMETA ); # these get exported |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
8
|
|
|
8
|
|
3261
|
%CONSTANTS = ( |
23
|
|
|
|
|
|
|
TIGHT => '.', |
24
|
|
|
|
|
|
|
SINGLE => '?', |
25
|
|
|
|
|
|
|
LOOSE => '*', |
26
|
|
|
|
|
|
|
VALUE => '!!VALUE', |
27
|
|
|
|
|
|
|
MATCH_COUNT => '!!MATCH_COUNT', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
%META = ( |
31
|
|
|
|
|
|
|
$CONSTANTS{VALUE} => 'value', |
32
|
8
|
|
|
|
|
42
|
$CONSTANTS{MATCH_COUNT} => 'match_count' |
33
|
|
|
|
|
|
|
); |
34
|
8
|
|
|
|
|
38
|
%RMETA = reverse %META; |
35
|
|
|
|
|
|
|
|
36
|
8
|
|
|
|
|
15
|
$CONSTANTS{META_QR} = qr/@{[ join '|', map { quotemeta } keys %META ]}/i; |
|
8
|
|
|
|
|
20
|
|
|
16
|
|
|
|
|
918
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# so we can use the scalars here without complaints |
40
|
8
|
|
|
8
|
|
78
|
use vars map { '$' . $_ } keys %CONSTANTS; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
33
|
|
|
48
|
|
|
|
|
865
|
|
41
|
|
|
|
|
|
|
{ |
42
|
8
|
|
|
8
|
|
77
|
no strict 'refs'; ## no critic(ProhibitNoStrict) |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
858
|
|
43
|
|
|
|
|
|
|
*{$_} = \( $CONSTANTS{$_} ) for keys %CONSTANTS; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
8
|
|
59
|
use constant \%CONSTANTS; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
7037
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
49
|
|
|
|
|
|
|
scalar => [ map "\$$_", keys( %CONSTANTS ) ], |
50
|
|
|
|
|
|
|
constants => [ keys( %CONSTANTS ) ], |
51
|
|
|
|
|
|
|
hashes => [ qw( %META %RMETA ) ], |
52
|
|
|
|
|
|
|
funcs => [ |
53
|
|
|
|
|
|
|
qw( parse_resource_name parse_fq_resource_name |
54
|
|
|
|
|
|
|
normalize_key name_arr_to_str is_wildcard ) |
55
|
|
|
|
|
|
|
], |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
our @EXPORT_OK = ( map { @$_ } values %EXPORT_TAGS ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$EXPORT_TAGS{all} = \@EXPORT_OK; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
1602
|
|
|
1602
|
1
|
11331
|
sub parse_resource_name ( $name ) { |
|
1602
|
|
|
|
|
2241
|
|
|
1602
|
|
|
|
|
2047
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
{ |
76
|
1602
|
|
|
|
|
2098
|
my $last = substr( $name, -1 ); |
|
1602
|
|
|
|
|
3099
|
|
77
|
1602
|
100
|
100
|
|
|
6599
|
key_failure->throw( |
|
|
|
100
|
|
|
|
|
78
|
|
|
|
|
|
|
"last component of name may not be a binding operator: $name" ) |
79
|
|
|
|
|
|
|
if $last eq TIGHT || $last eq SINGLE || $last eq LOOSE; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# all consecutive '.' characters are replaced with a single one. |
83
|
1599
|
|
|
|
|
9743
|
$name =~ s/[$TIGHT]+/$TIGHT/g; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# any combination of '.' and '*' is replaced with a '*' |
86
|
1599
|
|
|
|
|
5992
|
$name =~ s/[${TIGHT}${LOOSE}]{2,}/$LOOSE/g; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# toss out fields: |
89
|
|
|
|
|
|
|
# - the tight binding operator; that is the default. |
90
|
|
|
|
|
|
|
# - empty fields correspond to two sequential binding operators |
91
|
|
|
|
|
|
|
# or a leading binding operator |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return [ |
94
|
1599
|
100
|
|
|
|
9945
|
grep { $_ ne TIGHT && $_ ne '' } |
|
23043
|
|
|
|
|
64325
|
|
95
|
|
|
|
|
|
|
split( /([${TIGHT}${SINGLE}${LOOSE}])/, $name ) ]; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
45
|
|
|
45
|
1
|
10064
|
sub parse_fq_resource_name ( $name ) { |
|
45
|
|
|
|
|
131
|
|
|
45
|
|
|
|
|
58
|
|
109
|
|
|
|
|
|
|
|
110
|
45
|
100
|
100
|
|
|
218
|
key_failure->throw( |
111
|
|
|
|
|
|
|
"cannot have '$LOOSE' or '$SINGLE' binding operators in a fully qualified name: $name" |
112
|
|
|
|
|
|
|
) |
113
|
|
|
|
|
|
|
if index( $name, SINGLE ) != -1 |
114
|
|
|
|
|
|
|
or index( $name, LOOSE ) != -1; |
115
|
|
|
|
|
|
|
|
116
|
42
|
100
|
|
|
|
285
|
key_failure->throw( |
117
|
|
|
|
|
|
|
"cannot have multiple sequential '$TIGHT' binding operators in a fully qualified name: $name" |
118
|
|
|
|
|
|
|
) if $name =~ /[$TIGHT]{2,}/; |
119
|
|
|
|
|
|
|
|
120
|
41
|
50
|
|
|
|
119
|
key_failure->throw( |
121
|
|
|
|
|
|
|
"last component of a fully qualified name must not be a binding operator: $name" |
122
|
|
|
|
|
|
|
) if substr( $name, -1 ) eq TIGHT; |
123
|
|
|
|
|
|
|
|
124
|
41
|
100
|
|
|
|
115
|
key_failure->throw( |
125
|
|
|
|
|
|
|
"first component of a fully qualified name must not be a binding operator: $name" |
126
|
|
|
|
|
|
|
) if substr( $name, 0, 1 ) eq TIGHT; |
127
|
|
|
|
|
|
|
|
128
|
40
|
|
|
|
|
370
|
return [ split( /[$TIGHT]/, $name ) ]; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
1530
|
|
|
1530
|
1
|
1980
|
sub normalize_key( $key ) { |
|
1530
|
|
|
|
|
2258
|
|
|
1530
|
|
|
|
|
1877
|
|
142
|
1530
|
|
|
|
|
7559
|
$key =~ s/[$TIGHT]?[$LOOSE][$TIGHT]?/$LOOSE/g; |
143
|
1530
|
|
|
|
|
4040
|
return $key; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
0
|
1
|
|
sub name_arr_to_str ( $name_arr ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
return normalize_key( join( +TIGHT, @$name_arr ) ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
0
|
1
|
|
sub is_wildcard( $string ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
168
|
0
|
|
0
|
|
|
|
return $string eq TIGHT || $string eq LOOSE; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |