line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Layout::Level; |
2
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
157
|
|
3
|
5
|
|
|
5
|
|
37
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
134
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Level definition object for Hash::Layout |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
28
|
use Moo; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
39
|
|
8
|
5
|
|
|
5
|
|
1730
|
use Types::Standard qw(:all); |
|
5
|
|
|
|
|
41
|
|
|
5
|
|
|
|
|
59
|
|
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
|
|
5593
|
my ($self,$key) = @_; |
43
|
|
|
|
|
|
|
|
44
|
3767
|
100
|
100
|
|
|
9857
|
return $key if ( |
45
|
|
|
|
|
|
|
$self->registered_keys && |
46
|
|
|
|
|
|
|
$self->registered_keys->{$key} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
3764
|
100
|
|
|
|
11124
|
my $del = $self->delimiter or return undef; |
50
|
3282
|
100
|
|
|
|
20594
|
return undef unless ($key =~ /\Q${del}\E/); |
51
|
246
|
|
|
|
|
1365
|
my ($peeled,$leftover) = split(/\Q${del}\E/,$key,2); |
52
|
246
|
100
|
66
|
|
|
1469
|
return undef unless ($peeled && $peeled ne ''); |
53
|
240
|
100
|
100
|
|
|
5523
|
return ($leftover && $leftover ne '' && wantarray) ? |
54
|
|
|
|
|
|
|
($peeled,$leftover) : $peeled; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _coerce_list_hash { |
58
|
5
|
|
|
|
|
29
|
$_[0] && ! ref($_[0]) ? { $_[0] => 1 } : |
59
|
79
|
100
|
66
|
79
|
|
2142
|
ref($_[0]) eq 'ARRAY' ? { map {$_=>1} @{$_[0]} } : $_[0]; |
|
1
|
50
|
|
|
|
4
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |