| 1 | package Catmandu::Fix::collapse; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Catmandu::Sane; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 2 | our $VERSION = '1.0201_02'; | |||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Catmandu::Expander (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Catmandu::Fix::Has; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | with 'Catmandu::Fix::Inlineable'; | |||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | has sep => (fix_opt => 1, default => sub {undef}); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | sub fix { | ||||||||||
| 17 | 3 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
fix: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 18 | 3 | my $ref = Catmandu::Expander->collapse_hash($data); | |||||||||
| 19 | |||||||||||
| 20 | 3 | ▶ | if (defined(my $char = $self->sep)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 1 | my $new_ref = {}; | |||||||||
| 22 | 1 | for my $key (keys %$ref) { | |||||||||
| 23 | 2 | my $val = $ref->{$key}; | |||||||||
| 24 | 2 | $key =~ s{\.}{$char}g; | |||||||||
| 25 | 2 | $new_ref->{$key} = $val; | |||||||||
| 26 | } | ||||||||||
| 27 | 1 | $ref = $new_ref; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 3 | $ref; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 2 | 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 | ||||||||||