line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
100538
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
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
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
4
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
255
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my ($self, $v) = @_; |
14
|
|
|
|
|
|
|
(is_hash_ref($v) && %$v) || (is_array_ref($v) && @$v); |
15
|
10
|
|
|
10
|
|
17
|
} |
16
|
10
|
100
|
66
|
|
|
48
|
|
|
|
|
66
|
|
|
|
|
17
|
|
|
|
|
|
|
my ($self, $v) = @_; |
18
|
|
|
|
|
|
|
!defined($v) |
19
|
|
|
|
|
|
|
|| (is_value($v) && $v !~ /\S/) |
20
|
27
|
|
|
27
|
|
36
|
|| (is_hash_ref($v) && !%$v) |
21
|
27
|
100
|
100
|
|
|
203
|
|| (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
|
177
|
my @stack = ($data); |
29
|
|
|
|
|
|
|
my %seen; |
30
|
1
|
50
|
|
|
|
7
|
|
31
|
|
|
|
|
|
|
while (@stack) { |
32
|
1
|
|
|
|
|
4
|
my $d = pop @stack; |
33
|
1
|
|
|
|
|
1
|
my $id = refaddr($d); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
if ($seen{$id}) { |
36
|
16
|
|
|
|
|
23
|
if (is_hash_ref($d)) { |
37
|
16
|
|
|
|
|
19
|
for my $k (keys %$d) { |
38
|
|
|
|
|
|
|
delete $d->{$k} if $self->_empty($d->{$k}); |
39
|
16
|
100
|
|
|
|
28
|
} |
40
|
8
|
100
|
|
|
|
18
|
} |
|
|
50
|
|
|
|
|
|
41
|
6
|
|
|
|
|
11
|
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
|
|
|
|
|
4
|
else { |
|
2
|
|
|
|
|
4
|
|
47
|
2
|
|
|
|
|
6
|
$seen{$id} = 1; |
48
|
|
|
|
|
|
|
push @stack, $d; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if (is_hash_ref($d)) { |
51
|
8
|
|
|
|
|
14
|
for my $k (keys %$d) { |
52
|
8
|
|
|
|
|
9
|
my $v = $d->{$k}; |
53
|
|
|
|
|
|
|
if ($self->_empty($v)) { |
54
|
8
|
100
|
|
|
|
15
|
delete $d->{$k}; |
|
|
50
|
|
|
|
|
|
55
|
6
|
|
|
|
|
14
|
} |
56
|
15
|
|
|
|
|
20
|
elsif ($self->_visit($v)) { |
57
|
15
|
100
|
|
|
|
22
|
push @stack, $v; |
|
|
100
|
|
|
|
|
|
58
|
8
|
|
|
|
|
18
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
6
|
|
|
|
|
13
|
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
|
|
|
|
|
3
|
push @stack, $v if $self->_visit($v); |
67
|
2
|
|
|
|
|
4
|
} |
68
|
3
|
100
|
|
|
|
6
|
splice @$d, 0, @$d, @vals; |
69
|
2
|
|
|
|
|
4
|
} |
70
|
2
|
100
|
|
|
|
5
|
} |
71
|
|
|
|
|
|
|
} |
72
|
2
|
|
|
|
|
7
|
|
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 |