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
|
|
111
|
use v5.26; |
|
8
|
|
|
|
|
28
|
|
6
|
8
|
|
|
8
|
|
49
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
373
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
47
|
use Config::XrmDatabase::Failure ':all'; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
900
|
|
11
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
|
4192
|
use namespace::clean; |
|
8
|
|
|
|
|
135178
|
|
|
8
|
|
|
|
|
52
|
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
2617
|
use Exporter 'import'; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
262
|
|
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
8
|
|
4308
|
use experimental qw( signatures postderef ); |
|
8
|
|
|
|
|
29470
|
|
|
8
|
|
|
|
|
49
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %CONSTANTS; |
19
|
|
|
|
|
|
|
our ( %META, %RMETA ); # these get exported |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
8
|
|
|
8
|
|
3310
|
%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
|
|
|
|
|
35
|
$CONSTANTS{MATCH_COUNT} => 'match_count' |
33
|
|
|
|
|
|
|
); |
34
|
8
|
|
|
|
|
51
|
%RMETA = reverse %META; |
35
|
|
|
|
|
|
|
|
36
|
8
|
|
|
|
|
17
|
$CONSTANTS{META_QR} = qr/@{[ join '|', map { quotemeta } keys %META ]}/i; |
|
8
|
|
|
|
|
24
|
|
|
16
|
|
|
|
|
957
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# so we can use the scalars here without complaints |
40
|
8
|
|
|
8
|
|
77
|
use vars map { '$' . $_ } keys %CONSTANTS; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
37
|
|
|
48
|
|
|
|
|
886
|
|
41
|
|
|
|
|
|
|
{ |
42
|
8
|
|
|
8
|
|
60
|
no strict 'refs'; ## no critic(ProhibitNoStrict) |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
768
|
|
43
|
|
|
|
|
|
|
*{$_} = \( $CONSTANTS{$_} ) for keys %CONSTANTS; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
8
|
|
59
|
use constant \%CONSTANTS; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
7009
|
|
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
|
10622
|
sub parse_resource_name ( $name ) { |
|
1602
|
|
|
|
|
2182
|
|
|
1602
|
|
|
|
|
1826
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
{ |
76
|
1602
|
|
|
|
|
1949
|
my $last = substr( $name, -1 ); |
|
1602
|
|
|
|
|
2938
|
|
77
|
1602
|
100
|
100
|
|
|
6501
|
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
|
|
|
|
|
9548
|
$name =~ s/[$TIGHT]+/$TIGHT/g; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# any combination of '.' and '*' is replaced with a '*' |
86
|
1599
|
|
|
|
|
5450
|
$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
|
|
|
|
9820
|
grep { $_ ne TIGHT && $_ ne '' } |
|
23043
|
|
|
|
|
58933
|
|
95
|
|
|
|
|
|
|
split( /([${TIGHT}${SINGLE}${LOOSE}])/, $name ) ]; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
45
|
|
|
45
|
1
|
9191
|
sub parse_fq_resource_name ( $name ) { |
|
45
|
|
|
|
|
121
|
|
|
45
|
|
|
|
|
67
|
|
109
|
|
|
|
|
|
|
|
110
|
45
|
100
|
100
|
|
|
247
|
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
|
|
|
|
257
|
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
|
|
|
|
120
|
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
|
|
|
|
124
|
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
|
|
|
|
|
314
|
return [ split( /[$TIGHT]/, $name ) ]; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
1530
|
|
|
1530
|
1
|
1621
|
sub normalize_key( $key ) { |
|
1530
|
|
|
|
|
1791
|
|
|
1530
|
|
|
|
|
1512
|
|
142
|
1530
|
|
|
|
|
5774
|
$key =~ s/[$TIGHT]?[$LOOSE][$TIGHT]?/$LOOSE/g; |
143
|
1530
|
|
|
|
|
3218
|
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__ |