line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Bind::marc_each; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
551
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
255
|
use Catmandu::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
210
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has done => (is => 'ro'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub unit { |
13
|
10
|
|
|
10
|
0
|
273
|
my ($self,$data) = @_; |
14
|
|
|
|
|
|
|
|
15
|
10
|
|
|
|
|
19
|
$self->{done} = 0; |
16
|
|
|
|
|
|
|
|
17
|
10
|
|
|
|
|
125
|
$data; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub bind { |
21
|
|
|
|
|
|
|
my ($self,$mvar,$code) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $mvar if $self->done; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $rows = $mvar->{record} // []; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @new = (); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
for my $row (@{$rows}) { |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$mvar->{record} = [$row]; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $fixed = $code->($mvar); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
push @new , @{$fixed->{record}} if defined $fixed && exists $fixed->{record} && defined $fixed->{record}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$mvar->{record} = \@new if exists $mvar->{record}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->{done} = 1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$mvar; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Catmandu::Fix::Bind::marc_each - a binder that loops over MARC fields |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Only add the 720 field to the authors when the $e subfield contains a 'promotor' |
54
|
|
|
|
|
|
|
do marc_each() |
55
|
|
|
|
|
|
|
if marc_match("720e","promotor") |
56
|
|
|
|
|
|
|
marc_map("720ab",authors.$append) |
57
|
|
|
|
|
|
|
end |
58
|
|
|
|
|
|
|
end |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Delete all the 500 fields |
61
|
|
|
|
|
|
|
do marc_each() |
62
|
|
|
|
|
|
|
if marc_match("500",".*") |
63
|
|
|
|
|
|
|
reject() |
64
|
|
|
|
|
|
|
end |
65
|
|
|
|
|
|
|
end |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The marc_each binder will iterate over each individual MARC field and execute the fixes only |
70
|
|
|
|
|
|
|
in context over each individual field. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
If a MARC record contains: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
500 $aTest |
75
|
|
|
|
|
|
|
500 $aTest2$eskip |
76
|
|
|
|
|
|
|
500 $aTest3 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
then the fix |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
do marc_each() |
81
|
|
|
|
|
|
|
marc_map("500",note.$append) |
82
|
|
|
|
|
|
|
end |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
will have the same effect as |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
marc_map("500",note.$append) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
because C<marc_map> by default loops over all repeated MARC fields. But the C<marc_each> bind has the |
89
|
|
|
|
|
|
|
advantage to process fields in context. E.g. to only map fields where the $e doesn't contain 'skip' |
90
|
|
|
|
|
|
|
you can write: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
do marc_each() |
93
|
|
|
|
|
|
|
unless marc_match("500e",skip) |
94
|
|
|
|
|
|
|
marc_map("500",note.$append) |
95
|
|
|
|
|
|
|
end |
96
|
|
|
|
|
|
|
end |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |