line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Layout::Level; |
2
|
5
|
|
|
5
|
|
40
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
162
|
|
3
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
143
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Level definition object for Hash::Layout |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
27
|
use Moo; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
106
|
|
8
|
5
|
|
|
5
|
|
2039
|
use Types::Standard qw(:all); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
51
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'index', is => 'ro', isa => Int, required => 1; |
11
|
|
|
|
|
|
|
has 'delimiter', is => 'ro', isa => Maybe[Str], default => sub {undef}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'name', is => 'ro', isa => Str, lazy => 1, default => sub { |
14
|
|
|
|
|
|
|
my $self = shift; |
15
|
|
|
|
|
|
|
return 'level-' . $self->index; |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Key names which we specifically expect to be at this level. This |
19
|
|
|
|
|
|
|
# is a mechanism to resolve default/pad ambiguity when resolving |
20
|
|
|
|
|
|
|
# composite key strings |
21
|
|
|
|
|
|
|
has 'registered_keys', is => 'ro', isa => Maybe[ |
22
|
|
|
|
|
|
|
Map[Str,Bool] |
23
|
|
|
|
|
|
|
], coerce => \&_coerce_list_hash, default => sub {undef}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
## TDB: |
27
|
|
|
|
|
|
|
#has 'edge_keys', is => 'ro', isa => Maybe[ |
28
|
|
|
|
|
|
|
# Map[Str,Bool] |
29
|
|
|
|
|
|
|
#], coerce => \&_coerce_list_hash, default => sub {undef}; |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
#has 'deep_keys', is => 'ro', isa => Maybe[ |
32
|
|
|
|
|
|
|
# Map[Str,Bool] |
33
|
|
|
|
|
|
|
#], coerce => \&_coerce_list_hash, default => sub {undef}; |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
#has 'limit_keys', is => 'ro', isa => Bool, default => sub { 0 }; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Peel off the prefix key from a concatenated key string, according |
40
|
|
|
|
|
|
|
# to this Level's delimiter: |
41
|
|
|
|
|
|
|
sub _peel_str_key { |
42
|
3767
|
|
|
3767
|
|
5590
|
my ($self,$key) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $key if ( |
45
|
|
|
|
|
|
|
$self->registered_keys && |
46
|
3767
|
100
|
100
|
|
|
6685
|
$self->registered_keys->{$key} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
3764
|
100
|
|
|
|
7802
|
my $del = $self->delimiter or return undef; |
50
|
3282
|
100
|
|
|
|
15487
|
return undef unless ($key =~ /\Q${del}\E/); |
51
|
246
|
|
|
|
|
1319
|
my ($peeled,$leftover) = split(/\Q${del}\E/,$key,2); |
52
|
246
|
100
|
66
|
|
|
963
|
return undef unless ($peeled && $peeled ne ''); |
53
|
240
|
100
|
100
|
|
|
1482
|
return ($leftover && $leftover ne '' && wantarray) ? |
54
|
|
|
|
|
|
|
($peeled,$leftover) : $peeled; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _coerce_list_hash { |
58
|
|
|
|
|
|
|
$_[0] && ! ref($_[0]) ? { $_[0] => 1 } : |
59
|
79
|
100
|
66
|
79
|
|
1579
|
ref($_[0]) eq 'ARRAY' ? { map {$_=>1} @{$_[0]} } : $_[0]; |
|
5
|
50
|
|
|
|
32
|
|
|
1
|
|
|
|
|
4
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |