line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::marc_replace_all; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
607
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
205
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
656
|
use Catmandu::MARC; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
266
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
781
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.19'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has marc_path => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has regex => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has value => (fix_arg => 1); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub fix { |
17
|
3
|
|
|
3
|
0
|
3190
|
my ($self,$data) = @_; |
18
|
3
|
|
|
|
|
9
|
my $marc_path = $self->marc_path; |
19
|
3
|
|
|
|
|
16
|
my $regex = $self->regex; |
20
|
3
|
|
|
|
|
7
|
my $value = $self->value; |
21
|
3
|
|
|
|
|
12
|
return Catmandu::MARC->instance->marc_replace_all($data,$marc_path,$regex,$value); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Catmandu::Fix::marc_replace_all - regex replace (sub)field values in a MARC file |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Append to all the 650-p values the string "xyz" |
31
|
|
|
|
|
|
|
marc_replace_all('650p','$','xyz') |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Replace all 'Joe'-s in 100a to 'Joey' |
34
|
|
|
|
|
|
|
marc_replace_all('100a','\bJoe\b','Joey') |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Replace all 'Joe'-s in 100a to the value in field x.y.z |
37
|
|
|
|
|
|
|
marc_replace_all('100a','\bJoe\b',$.x.y.z) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Replace all the content of 100a with everything in curly brackets |
40
|
|
|
|
|
|
|
marc_replace_all('100a','^(.*)$','{$1}') |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Use regex search and replace on MARC field values. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 METHODS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 marc_replace_all(MARC_PATH , REGEX, VALUE) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
For each (sub)field matching the MARC_PATH replace the pattern found by REGEX to |
51
|
|
|
|
|
|
|
a new VALUE. This value can be a literal or |
52
|
|
|
|
|
|
|
reference an existing field in the record using the dollar JSON_PATH syntax. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 INLINE |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This Fix can be used inline in a Perl script: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
use Catmandu::Fix::marc_replace_all as => 'marc_replace_all'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $data = { record => [...] }; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$data = marc_replace_all($data, '245a', 'test' , 'rest'); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SEE ALSO |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L<Catmandu::Fix> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |