line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::DefHash::Normalize; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-04-24'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
388
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
7
|
1
|
|
|
1
|
|
2
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
8
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
237
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
normalize_defhash |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub normalize_defhash($;$) { |
17
|
6
|
|
|
6
|
1
|
49
|
my ($dh, $opts) = @_; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
100
|
|
|
16
|
$opts //= {}; |
20
|
6
|
|
100
|
|
|
17
|
$opts->{remove_internal_properties} //= 0; |
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
|
|
4
|
my $opt_rip = $opts->{remove_internal_properties}; |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
|
|
7
|
my $ndh = {}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
KEY: |
27
|
6
|
|
|
|
|
12
|
for my $k (keys %$dh) { |
28
|
13
|
100
|
|
|
|
55
|
die "Invalid prop/attr syntax '$k', must be word/dotted-word only" |
29
|
|
|
|
|
|
|
unless $k =~ /\A(\w+)(?:\.(\w+(?:\.\w+)*))?(?:\((\w+)\))?\z/; |
30
|
|
|
|
|
|
|
|
31
|
11
|
|
|
|
|
8
|
my ($prop, $attr); |
32
|
11
|
100
|
|
|
|
14
|
if (defined $3) { |
33
|
1
|
|
|
|
|
3
|
$prop = $1; |
34
|
1
|
50
|
|
|
|
4
|
$attr = defined($2) ? "$2.alt.lang.$3" : "alt.lang.$3"; |
35
|
|
|
|
|
|
|
} else { |
36
|
10
|
|
|
|
|
9
|
$prop = $1; |
37
|
10
|
|
|
|
|
10
|
$attr = $2; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
11
|
100
|
|
|
|
15
|
my $nk = "$prop" . (defined($attr) ? ".$attr" : ""); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# strip property/attr started with _ |
43
|
11
|
100
|
100
|
|
|
40
|
if ($prop =~ /\A_/ || defined($attr) && $attr =~ /\A_|\._/) { |
|
|
|
66
|
|
|
|
|
44
|
4
|
100
|
|
|
|
6
|
unless ($opt_rip) { |
45
|
2
|
|
|
|
|
4
|
$ndh->{$nk} = $dh->{$k}; |
46
|
|
|
|
|
|
|
} |
47
|
4
|
|
|
|
|
5
|
next KEY; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
10
|
$ndh->{$nk} = $dh->{$k}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
21
|
$ndh; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
# ABSTRACT: Normalize DefHash |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |