line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::retain; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
104970
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
876
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
9
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
746
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has paths => (fix_arg => 'collect', default => sub {[]},); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_fixer { |
17
|
3
|
|
|
3
|
|
36
|
my ($self) = @_; |
18
|
3
|
|
|
|
|
6
|
my $paths = [map {as_path($_)} @{$self->paths}]; |
|
4
|
|
|
|
|
33
|
|
|
3
|
|
|
|
|
10
|
|
19
|
3
|
|
|
|
|
1159
|
my $getters = [map {$_->getter} @$paths]; |
|
4
|
|
|
|
|
13
|
|
20
|
3
|
|
|
|
|
15
|
my $creators = [map {$_->creator} @$paths]; |
|
4
|
|
|
|
|
83
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub { |
23
|
3
|
|
|
3
|
|
6
|
my $data = $_[0]; |
24
|
3
|
|
|
|
|
5
|
my $temp = {}; |
25
|
3
|
|
|
|
|
13
|
for (my $i = 0; $i < @$getters; $i++) { |
26
|
4
|
|
|
|
|
10
|
my $getter = $getters->[$i]; |
27
|
4
|
|
|
|
|
6
|
my $creator = $creators->[$i]; |
28
|
4
|
|
|
|
|
74
|
my $values = $getter->($data); |
29
|
4
|
|
|
|
|
12
|
while (@$values) { |
30
|
3
|
|
|
|
|
53
|
$creator->($temp, shift @$values); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
3
|
|
|
|
|
13
|
undef %$data; |
34
|
3
|
|
|
|
|
12
|
for my $key (keys %$temp) { |
35
|
3
|
|
|
|
|
8
|
$data->{$key} = $temp->{$key}; |
36
|
|
|
|
|
|
|
} |
37
|
3
|
|
|
|
|
56
|
$data; |
38
|
3
|
|
|
|
|
41
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=pod |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Catmandu::Fix::retain - delete everything except the paths given |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Keep the field _id , name , title |
54
|
|
|
|
|
|
|
retain(_id , name, title) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Delete everything except foo.bar |
57
|
|
|
|
|
|
|
# {bar => { x => 1} , foo => {bar => 1, y => 2}} |
58
|
|
|
|
|
|
|
# to |
59
|
|
|
|
|
|
|
# {foo => {bar => 1}} |
60
|
|
|
|
|
|
|
retain(foo.bar) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SEE ALSO |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
L<Catmandu::Fix> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |