| 1 | package Hash::Layout::Level; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Level definition object for Hash::Layout | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Types::Standard qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | has 'index', is => 'ro', isa => Int, required => 1; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | has 'delimiter', is => 'ro', isa => Maybe[Str], default => sub {undef}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | has 'name', is => 'ro', isa => Str, lazy => 1, default => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | return 'level-' . $self->index; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 78 | ▶ | ], coerce => \&_coerce_list_hash, default => sub {undef}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ($self,$key) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_peel_str_key: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | return $key if ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | $self->registered_keys && | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 3767 | ▶ | $self->registered_keys->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->registered_keys and $self->registered_keys->{$key}
MC/DC100%2/2
$self->registered_keys and $self->registered_keys->{$key}
$self->registered_keys
$self->registered_keys->{$key}
Truth table100%3/3
A and B
A= $self->registered_keysB= $self->registered_keys->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3764 | ▶ | my $del = $self->delimiter or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3282 | ▶ | return undef unless ($key =~ /\Q${del}\E/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 246 | my ($peeled,$leftover) = split(/\Q${del}\E/,$key,2); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 246 | ▶ | return undef unless ($peeled && $peeled ne ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$peeled and $peeled ne ""
MC/DC50%1/2
$peeled and $peeled ne ""
$peeled
$peeled ne ""
Truth table66%2/3
A and B
A= $peeledB= $peeled ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 240 | ▶ | return ($leftover && $leftover ne '' && wantarray) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$leftover and $leftover ne "" and wantarray
$leftover and $leftover ne ""
MC/DC66%2/3
$leftover and $leftover ne "" and wantarray
$leftover
$leftover ne ""
wantarray
Truth table75%3/4
A and B and C
A= $leftoverB= $leftover ne ""C= wantarray
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | ($peeled,$leftover) : $peeled; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | sub _coerce_list_hash { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | $_[0] && ! ref($_[0]) ? { $_[0] => 1 } : | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 79 | ▶ | ref($_[0]) eq 'ARRAY' ? { map {$_=>1} @{$_[0]} } : $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_list_hash: called CC=4 SCAR=14.2
Branch: 2 branches
Condition66%2/3
$_[0] and not ref $_[0]
MC/DC0%0/2
$_[0] and not ref $_[0]
$_[0]
not ref $_[0]
Truth table66%2/3
A and not(B)
A= $_[0]B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||||||||||||||||