line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Bind::iterate; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1219
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
8
|
1
|
|
|
1
|
|
459
|
use Catmandu::Util; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
455
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
447
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has start => (fix_opt => 1); |
15
|
|
|
|
|
|
|
has end => (fix_opt => 1); |
16
|
|
|
|
|
|
|
has step => (fix_opt => 1); |
17
|
|
|
|
|
|
|
has var => (fix_opt => 1); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub unit { |
20
|
29
|
|
|
29
|
0
|
52
|
my ($self, $data) = @_; |
21
|
29
|
|
|
|
|
468
|
$data; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub bind { |
25
|
|
|
|
|
|
|
my ($self, $mvar, $func, $name, $fixer) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $start = $self->start; |
28
|
|
|
|
|
|
|
my $end = $self->end; |
29
|
|
|
|
|
|
|
my $step = $self->step // 1; |
30
|
|
|
|
|
|
|
my $var = $self->var; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ( Catmandu::Util::is_number($start) |
33
|
|
|
|
|
|
|
&& Catmandu::Util::is_number($end) |
34
|
|
|
|
|
|
|
&& Catmandu::Util::is_number($step)) |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
for (my $i = $start; $i <= $end; $i = $i + $step) { |
37
|
|
|
|
|
|
|
$mvar->{$var} = $i if defined($var); |
38
|
|
|
|
|
|
|
$mvar = $func->($mvar); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
delete $mvar->{$var} if defined($var); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $mvar; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Catmandu::Fix::Bind::iterate - a binder iterates fixes in a loop |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Create: |
61
|
|
|
|
|
|
|
# numbers = [1,2,3,4,5,6,7,8,9,10] |
62
|
|
|
|
|
|
|
do iterate(start:1, end: 10, step: 1, var: i) |
63
|
|
|
|
|
|
|
copy_field(i,numbers.$append) |
64
|
|
|
|
|
|
|
end |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The list binder will iterate over all the elements in a list and fixes the |
69
|
|
|
|
|
|
|
values in context of that list. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 CONFIGURATION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 start |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Start value of the iterator. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 end |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
End value of the iterator. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 step |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Increase the interator with this value for every step. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head3 var |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Optional variable holding the value of the current step |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SEE ALSO |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind> , |
92
|
|
|
|
|
|
|
L<Catmandu::Fix::list> , |
93
|
|
|
|
|
|
|
L<Catmandu::Fix::with> , |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |