line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::disassoc; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
105814
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
473
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
5
|
1
|
|
|
1
|
|
7
|
use Catmandu::Util qw(is_array_ref); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
6
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
333
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
751
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has old_path => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has new_path => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has key_name => (fix_arg => 1); |
15
|
|
|
|
|
|
|
has value_name => (fix_arg => 1); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_fixer { |
18
|
3
|
|
|
3
|
|
36
|
my ($self) = @_; |
19
|
3
|
|
|
|
|
49
|
my $key_name = $self->key_name; |
20
|
3
|
|
|
|
|
9
|
my $val_name = $self->value_name; |
21
|
3
|
|
|
|
|
15
|
my $getter = as_path($self->old_path)->getter; |
22
|
3
|
|
|
|
|
27
|
my $creator = as_path($self->new_path)->creator; |
23
|
|
|
|
|
|
|
as_path($self->new_path)->creator( |
24
|
|
|
|
|
|
|
sub { |
25
|
3
|
|
|
3
|
|
13
|
my ($arr, $data) = @_; |
26
|
3
|
100
|
100
|
|
|
18
|
if (is_array_ref($arr //= [])) { |
27
|
2
|
|
|
|
|
5
|
for my $hash (@{$getter->($data)}) { |
|
2
|
|
|
|
|
36
|
|
28
|
2
|
|
|
|
|
11
|
for my $key (sort keys %$hash) { |
29
|
|
|
|
|
|
|
push @$arr, |
30
|
4
|
|
|
|
|
19
|
{$key_name => $key, $val_name => $hash->{$key},}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
3
|
|
|
|
|
61
|
$arr; |
35
|
|
|
|
|
|
|
} |
36
|
3
|
|
|
|
|
21
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Catmandu::Fix::disassoc - inverse of assoc, transform a hash into an array of key value pairs |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# {fields => {subject => 'Perl', year => 2009}} |
52
|
|
|
|
|
|
|
disassoc(fields, pairs, key, val) |
53
|
|
|
|
|
|
|
# {pairs => [{key => 'year', val => 2009}, {key => 'subject', val => 'Perl'}], fields => ...} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SEE ALSO |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
L<Catmandu::Fix::assoc>, L<Catmandu::Fix> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |