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