blib/lib/Catmandu/Fix/collapse.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 97.5% 39 / 40 CC 3 SCAR 5.1
CC
3
Cov
100%
fix
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« blib/lib/Catmandu/Fix/expand.pm ↑ Summary blib/lib/Catmandu/Exporter/Multi.pm »
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
BranchTrueFalseTotal
if (defined(my $char = $self->sep)) 1 2 3
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
« blib/lib/Catmandu/Fix/expand.pm ↑ Summary blib/lib/Catmandu/Exporter/Multi.pm »