line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
101093
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Util qw(is_value is_hash_ref is_array_ref); |
7
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(refaddr); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
8
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
4
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
263
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my ($self, $v) = @_; |
14
|
|
|
|
|
|
|
(is_hash_ref($v) && %$v) || (is_array_ref($v) && @$v); |
15
|
10
|
|
|
10
|
|
19
|
} |
16
|
10
|
100
|
66
|
|
|
46
|
|
|
|
|
66
|
|
|
|
|
17
|
|
|
|
|
|
|
my ($self, $v) = @_; |
18
|
|
|
|
|
|
|
!defined($v) |
19
|
|
|
|
|
|
|
|| (is_value($v) && $v !~ /\S/) |
20
|
27
|
|
|
27
|
|
33
|
|| (is_hash_ref($v) && !%$v) |
21
|
27
|
100
|
100
|
|
|
192
|
|| (is_array_ref($v) && !@$v); |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my ($self, $data) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return $data unless $self->_visit($data); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
0
|
154
|
my @stack = ($data); |
29
|
|
|
|
|
|
|
my %seen; |
30
|
1
|
50
|
|
|
|
3
|
|
31
|
|
|
|
|
|
|
while (@stack) { |
32
|
1
|
|
|
|
|
3
|
my $d = pop @stack; |
33
|
1
|
|
|
|
|
1
|
my $id = refaddr($d); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
if ($seen{$id}) { |
36
|
16
|
|
|
|
|
19
|
if (is_hash_ref($d)) { |
37
|
16
|
|
|
|
|
25
|
for my $k (keys %$d) { |
38
|
|
|
|
|
|
|
delete $d->{$k} if $self->_empty($d->{$k}); |
39
|
16
|
100
|
|
|
|
26
|
} |
40
|
8
|
100
|
|
|
|
17
|
} |
|
|
50
|
|
|
|
|
|
41
|
6
|
|
|
|
|
12
|
elsif (is_array_ref($d)) { |
42
|
7
|
100
|
|
|
|
12
|
my @vals = grep {!$self->_empty($_)} @$d; |
43
|
|
|
|
|
|
|
splice(@$d, 0, @$d, @vals); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
2
|
|
|
|
|
3
|
else { |
|
2
|
|
|
|
|
3
|
|
47
|
2
|
|
|
|
|
7
|
$seen{$id} = 1; |
48
|
|
|
|
|
|
|
push @stack, $d; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if (is_hash_ref($d)) { |
51
|
8
|
|
|
|
|
11
|
for my $k (keys %$d) { |
52
|
8
|
|
|
|
|
11
|
my $v = $d->{$k}; |
53
|
|
|
|
|
|
|
if ($self->_empty($v)) { |
54
|
8
|
100
|
|
|
|
15
|
delete $d->{$k}; |
|
|
50
|
|
|
|
|
|
55
|
6
|
|
|
|
|
12
|
} |
56
|
15
|
|
|
|
|
17
|
elsif ($self->_visit($v)) { |
57
|
15
|
100
|
|
|
|
23
|
push @stack, $v; |
|
|
100
|
|
|
|
|
|
58
|
8
|
|
|
|
|
19
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
6
|
|
|
|
|
12
|
elsif (is_array_ref($d)) { |
62
|
|
|
|
|
|
|
my @vals; |
63
|
|
|
|
|
|
|
for my $v (@$d) { |
64
|
|
|
|
|
|
|
next if $self->_empty($v); |
65
|
|
|
|
|
|
|
push @vals, $v; |
66
|
2
|
|
|
|
|
2
|
push @stack, $v if $self->_visit($v); |
67
|
2
|
|
|
|
|
4
|
} |
68
|
3
|
100
|
|
|
|
5
|
splice @$d, 0, @$d, @vals; |
69
|
2
|
|
|
|
|
5
|
} |
70
|
2
|
100
|
|
|
|
3
|
} |
71
|
|
|
|
|
|
|
} |
72
|
2
|
|
|
|
|
5
|
|
73
|
|
|
|
|
|
|
$data; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
1
|
|
|
|
|
4
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Catmandu::Fix::vacuum - delete all empty fields from your data |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Delete all the empty fields |
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
# input: |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# foo: '' |
92
|
|
|
|
|
|
|
# bar: [] |
93
|
|
|
|
|
|
|
# relations: {} |
94
|
|
|
|
|
|
|
# test: 123 |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
vacuum() |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# output: |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
# test: 123 |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Catmandu::Fix> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |