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