line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::assoc; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
101989
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
774
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
9
|
1
|
|
|
1
|
|
7
|
use Catmandu::Util qw(is_hash_ref); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
10
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
11
|
1
|
|
|
1
|
|
737
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
16
|
|
|
|
|
|
|
has keys_path => (fix_arg => 1); |
17
|
|
|
|
|
|
|
has vals_path => (fix_arg => 1); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _build_fixer { |
20
|
2
|
|
|
2
|
|
19
|
my ($self) = @_; |
21
|
2
|
|
|
|
|
36
|
my $keys_getter = as_path($self->keys_path)->getter; |
22
|
2
|
|
|
|
|
20
|
my $vals_getter = as_path($self->vals_path)->getter; |
23
|
|
|
|
|
|
|
as_path($self->path)->creator( |
24
|
|
|
|
|
|
|
sub { |
25
|
2
|
|
|
2
|
|
6
|
my ($val, $data) = @_; |
26
|
2
|
50
|
100
|
|
|
13
|
if (is_hash_ref($val //= {})) { |
27
|
2
|
|
|
|
|
36
|
my $keys = $keys_getter->($data); |
28
|
2
|
|
|
|
|
37
|
my $vals = $vals_getter->($data); |
29
|
2
|
|
66
|
|
|
21
|
$val->{shift @$keys} = shift @$vals while @$keys && @$vals; |
30
|
|
|
|
|
|
|
} |
31
|
2
|
|
|
|
|
45
|
$val; |
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
|
|
17
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=pod |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Catmandu::Fix::assoc - associate two values as a hash key and value |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# {pairs => [{key => 'year', val => 2009}, {key => 'subject', val => 'Perl'}]} |
49
|
|
|
|
|
|
|
assoc(fields, pairs.*.key, pairs.*.val) |
50
|
|
|
|
|
|
|
# {fields => {subject => 'Perl', year => 2009}, pairs => [...]} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SEE ALSO |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
L<Catmandu::Fix> |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |