line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Bind::mab_each; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
753
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
270
|
use Catmandu::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
233
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has done => (is => 'ro'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub unit { |
13
|
1
|
|
|
1
|
0
|
2791
|
my ($self,$data) = @_; |
14
|
1
|
|
|
|
|
3
|
$self->{done} = 0; |
15
|
1
|
|
|
|
|
14
|
$data; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub bind { |
19
|
|
|
|
|
|
|
my ($self,$mvar,$code) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return $mvar if $self->done; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $rows = $mvar->{record} // []; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my @new = (); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
for my $row (@{$rows}) { |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$mvar->{record} = [$row]; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $fixed = $code->($mvar); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
push @new , @{$fixed->{record}} if defined($fixed) && exists $fixed->{record}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$mvar->{record} = \@new if exists $mvar->{record}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->{done} = 1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$mvar; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=encoding UTF-8 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Catmandu::Fix::Bind::mab_each - a binder that loops over MAB2 fields |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Only add field 331 to the title when field 412 matches 'Heise' |
59
|
|
|
|
|
|
|
do mab_each() |
60
|
|
|
|
|
|
|
if mab_match("412","Heise") |
61
|
|
|
|
|
|
|
mab_map("331",title) |
62
|
|
|
|
|
|
|
end |
63
|
|
|
|
|
|
|
end |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Delete all the 700 subject fields |
66
|
|
|
|
|
|
|
do mab_each() |
67
|
|
|
|
|
|
|
if mab_match("700",".*") |
68
|
|
|
|
|
|
|
reject() |
69
|
|
|
|
|
|
|
end |
70
|
|
|
|
|
|
|
end |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The mab_each binder will iterate over each individual MAB2 field and |
75
|
|
|
|
|
|
|
execute the fixes only in context over each individual field. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
If a MAB2 record contains: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
705 $a775.05$c775 |
80
|
|
|
|
|
|
|
705 $a702.08$c702 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
then the fix |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
do mab_each() |
85
|
|
|
|
|
|
|
mab_map("705a",subject.$append) |
86
|
|
|
|
|
|
|
end |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
will have the same effect as |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
mab_map("705a",subject.$append) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
because C<mab_map> by default loops over all repeated MAB2 fields. But the |
93
|
|
|
|
|
|
|
C<mab_each> bind has the advantage to process fields in context. E.g. to |
94
|
|
|
|
|
|
|
only map fields where the subfield $c doesn't contain '702' you |
95
|
|
|
|
|
|
|
can write: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
do mab_each() |
98
|
|
|
|
|
|
|
unless mab_match("705","702") |
99
|
|
|
|
|
|
|
mab_map("705",subject.$append) |
100
|
|
|
|
|
|
|
end |
101
|
|
|
|
|
|
|
end |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Johann Rolschewski <jorol@cpan.org> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Johann Rolschewski. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
116
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |