| 1 | package Catmandu::Fix::marc_replace_all; | ||
| 2 | |||
| 3 | 1 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Catmandu::MARC; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Catmandu::Fix::Has; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | with 'Catmandu::Fix::Inlineable'; | |
| 9 | |||
| 10 | 1 | our $VERSION = '1.33'; | |
| 11 | |||
| 12 | 1 | has marc_path => (fix_arg => 1); | |
| 13 | 1 | has regex => (fix_arg => 1); | |
| 14 | 1 | has value => (fix_arg => 1); | |
| 15 | |||
| 16 | 3 | ▶ | sub fix { |
|
Subroutine
fix: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 17 | 3 | my ($self,$data) = @_; | |
| 18 | 3 | my $marc_path = $self->marc_path; | |
| 19 | 3 | my $regex = $self->regex; | |
| 20 | 3 | my $value = $self->value; | |
| 21 | 3 | 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 | 1; | |