blib/lib/Catmandu/Fix/expand.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 97.4% 38 / 39 CC 3 SCAR 5.1
CC
3
Cov
100%
fix
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« blib/lib/Catmandu/MultiIterator.pm ↑ Summary blib/lib/Catmandu/Fix/collapse.pm »
1 package Catmandu::Fix::expand;
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Catmandu::Expander ();
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 3 ▶has sep => (fix_opt => 1, default => sub {undef});
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 sub fix {
17 4 ▶ my ($self, $data) = @_;
Subroutine fix: called CC=3 SCAR=11.0
Pod undocumented
18  
19 4 ▶ if (defined(my $char = $self->sep)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $char = $self->sep)) 1 3 4
20 1 my $new_ref = {};
21 1 for my $key (keys %$data) {
22 2 my $val = $data->{$key};
23 2 $key =~ s{$char}{\.}g;
24 2 $new_ref->{$key} = $val;
25 }
26  
27 1 $data = $new_ref;
28 }
29  
30 4 Catmandu::Expander->expand_hash($data);
31 }
32  
33 2 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
« blib/lib/Catmandu/MultiIterator.pm ↑ Summary blib/lib/Catmandu/Fix/collapse.pm »