line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::expand; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
103982
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
14
|
use Moo; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
10
|
|
8
|
2
|
|
|
2
|
|
708
|
use namespace::clean; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
10
|
|
9
|
2
|
|
|
2
|
|
1080
|
use Catmandu::Expander (); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
43
|
|
10
|
2
|
|
|
2
|
|
396
|
use Catmandu::Fix::Has; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has sep => (fix_opt => 1, default => sub {undef}); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub fix { |
17
|
4
|
|
|
4
|
0
|
27
|
my ($self, $data) = @_; |
18
|
|
|
|
|
|
|
|
19
|
4
|
100
|
|
|
|
22
|
if (defined(my $char = $self->sep)) { |
20
|
1
|
|
|
|
|
4
|
my $new_ref = {}; |
21
|
1
|
|
|
|
|
5
|
for my $key (keys %$data) { |
22
|
2
|
|
|
|
|
5
|
my $val = $data->{$key}; |
23
|
2
|
|
|
|
|
20
|
$key =~ s{$char}{\.}g; |
24
|
2
|
|
|
|
|
18
|
$new_ref->{$key} = $val; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
2
|
$data = $new_ref; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
31
|
Catmandu::Expander->expand_hash($data); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Catmandu::Fix::expand - convert a flat hash into nested data using the TT2 dot convention |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# collapse the data into a flat hash |
46
|
|
|
|
|
|
|
collapse() |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# expand again to the nested original |
49
|
|
|
|
|
|
|
expand() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# optionally provide a path separator |
52
|
|
|
|
|
|
|
collapse(sep: '/') |
53
|
|
|
|
|
|
|
expand(sep: '/') |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SEE ALSO |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
L<Catmandu::Fix> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |