line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
815
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
1
|
|
|
1
|
|
6
|
use Clone (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
8
|
1
|
|
|
1
|
|
328
|
use Catmandu::Util; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
5
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
10
|
1
|
|
|
1
|
|
4
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
11
|
1
|
|
|
1
|
|
631
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has path => (fix_opt => 1); |
15
|
|
|
|
|
|
|
has var => (fix_opt => 1); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has root => (is => 'rw'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
[]; |
21
|
0
|
|
|
0
|
0
|
0
|
} |
22
|
0
|
|
|
|
|
0
|
|
23
|
|
|
|
|
|
|
my ($self, $data) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$self->root($data); |
26
|
13
|
|
|
13
|
0
|
24
|
|
27
|
|
|
|
|
|
|
defined $self->path ? Catmandu::Util::data_at($self->path, $data) : $data; |
28
|
13
|
|
|
|
|
35
|
} |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
168
|
my ($self, $mvar, $code) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $root = $self->root; |
33
|
|
|
|
|
|
|
my $var = $self->var; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
if (Catmandu::Util::is_hash_ref($mvar)) { |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Ignore all specialized processing when not an array |
38
|
|
|
|
|
|
|
$mvar = $code->($mvar); |
39
|
|
|
|
|
|
|
return $mvar; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif (Catmandu::Util::is_array_ref($mvar)) { |
42
|
|
|
|
|
|
|
for my $item (@$mvar) { |
43
|
|
|
|
|
|
|
if (defined $var) { |
44
|
|
|
|
|
|
|
$root->{$var} = $item; |
45
|
|
|
|
|
|
|
$root = $code->($root); |
46
|
|
|
|
|
|
|
delete $root->{$var}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
|
|
|
|
|
|
$item = $code->($item); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
return $mvar; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
return $self->zero; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Catmandu::Fix::Bind::list - a binder that computes Fix-es for every element in a list |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Create an array: |
71
|
|
|
|
|
|
|
# demo: |
72
|
|
|
|
|
|
|
# - red |
73
|
|
|
|
|
|
|
# - green |
74
|
|
|
|
|
|
|
# - yellow |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Add a foo field to every item in the demo list, by default all |
77
|
|
|
|
|
|
|
# fixes will be in context of the iterated path. If the context |
78
|
|
|
|
|
|
|
# is a list, then '.' will be the path of the temporary context |
79
|
|
|
|
|
|
|
# variable |
80
|
|
|
|
|
|
|
do list(path:demo) |
81
|
|
|
|
|
|
|
if all_equal(.,green) |
82
|
|
|
|
|
|
|
upcase(.) |
83
|
|
|
|
|
|
|
end |
84
|
|
|
|
|
|
|
end |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# This will result: |
87
|
|
|
|
|
|
|
# demo: |
88
|
|
|
|
|
|
|
# - red |
89
|
|
|
|
|
|
|
# - GREEN |
90
|
|
|
|
|
|
|
# - yellow |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Loop over the list but store the values in a temporary 'c' variable |
93
|
|
|
|
|
|
|
# Use this c variable to copy the list to the root 'xyz' path |
94
|
|
|
|
|
|
|
do list(path:demo,var:c) |
95
|
|
|
|
|
|
|
copy_field(c,xyz.$append) |
96
|
|
|
|
|
|
|
end |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# This will result: |
99
|
|
|
|
|
|
|
# demo: |
100
|
|
|
|
|
|
|
# - red |
101
|
|
|
|
|
|
|
# - GREEN |
102
|
|
|
|
|
|
|
# - yellow |
103
|
|
|
|
|
|
|
# xyz: |
104
|
|
|
|
|
|
|
# - red |
105
|
|
|
|
|
|
|
# - GREEN |
106
|
|
|
|
|
|
|
# - yellow |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DESCRIPTION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The list binder will iterate over all the elements in a list and fixes the |
111
|
|
|
|
|
|
|
values in context of that list. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 CONFIGURATION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 path |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The path to a list in the data. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 var |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The loop variable to be iterated over. When used, a magic temporary field will |
122
|
|
|
|
|
|
|
be available in the root of the record containing the iterated data. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |