| 1 | package Catmandu::Fix::Bind::marc_each; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Catmandu::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Catmandu::MARC; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Catmandu::Fix::Has; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.33'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | has var => (fix_opt => 1); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | has __marc => (is => 'lazy'); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub _build___marc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build___marc: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | Catmandu::MARC->instance; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | sub unit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | my ($self,$data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | $data; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 10 | ▶ | sub bind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=9 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | my ($self,$mvar,$code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 10 | ▶ | my $rows = $mvar->{record} // []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mvar->{"record"} // []
MC/DC0%0/1
$mvar->{"record"} // []
$mvar->{"record"}
Truth table50%1/2
A
A= $mvar->{"record"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | my @new = (); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | for my $row (@{$rows}) { | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 125 | $mvar->{record} = [$row]; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 125 | ▶ | if ($self->var) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $mvar->{$self->var} = $self->__marc->marc_copy($mvar,"***")->[0]->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 125 | my $fixed = $code->($mvar); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 116 | ▶ | push @new , @{$fixed->{record}} if defined $fixed && exists $fixed->{record} && defined $fixed->{record}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $fixed and exists $fixed->{"record"} and defined $fixed->{"record"}
defined $fixed and exists $fixed->{"record"}
MC/DC33%1/3
defined $fixed and exists $fixed->{"record"} and defined $fixed->{"record"}
defined $fixed
exists $fixed->{"record"}
defined $fixed->{"record"}
Truth table50%2/4
A and B and C
A= defined $fixedB= exists $fixed->{"record"}C= defined $fixed->{"record"}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 116 | ▶ | if ($self->var) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | delete $mvar->{$self->var}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $mvar->{record} = \@new if exists $mvar->{record}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | $mvar; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | Catmandu::Fix::Bind::marc_each - a binder that loops over MARC fields | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Only add the 720 field to the authors when the $e subfield contains a 'promotor' | ||||||||||||||||||||||||||||||||||||||||||
| 65 | do marc_each() | ||||||||||||||||||||||||||||||||||||||||||
| 66 | if marc_match("720e","promotor") | ||||||||||||||||||||||||||||||||||||||||||
| 67 | marc_map("720ab",authors.$append) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | end | ||||||||||||||||||||||||||||||||||||||||||
| 69 | end | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # Delete all the 500 fields | ||||||||||||||||||||||||||||||||||||||||||
| 72 | do marc_each() | ||||||||||||||||||||||||||||||||||||||||||
| 73 | if marc_has("500") | ||||||||||||||||||||||||||||||||||||||||||
| 74 | reject() | ||||||||||||||||||||||||||||||||||||||||||
| 75 | end | ||||||||||||||||||||||||||||||||||||||||||
| 76 | end | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | The marc_each binder will iterate over each individual MARC field and execute | ||||||||||||||||||||||||||||||||||||||||||
| 81 | the fixes on each individual field. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | When a MARC record contains: | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 500 $aTest | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 500 $aTest2$eskip | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 500 $aTest3 | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | then the Fix bellow will copy all 500 fields to note field, except for 500 fields | ||||||||||||||||||||||||||||||||||||||||||
| 90 | with a subfield $e equal to "skip". | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | do marc_each() | ||||||||||||||||||||||||||||||||||||||||||
| 93 | unless marc_match("500e",skip) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | marc_map("500",note.$append) | ||||||||||||||||||||||||||||||||||||||||||
| 95 | end | ||||||||||||||||||||||||||||||||||||||||||
| 96 | end | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | The result will be: | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | note: [Test,Test3] | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head2 var | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | Optional loop variable which contains a HASH containing MARC field information | ||||||||||||||||||||||||||||||||||||||||||
| 107 | with the following fields: | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | tag - The names of the MARC field | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ind1 - The value of the first indicator | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ind2 - The value of the second indicator | ||||||||||||||||||||||||||||||||||||||||||
| 112 | subfields - An array of subfield items. Each subfield item is a | ||||||||||||||||||||||||||||||||||||||||||
| 113 | hash of the subfield code and subfield value | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | Given the MARC field: | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 500[1, ] $aTest$bRest | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | the loop variable will contain: | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | tag: 500 | ||||||||||||||||||||||||||||||||||||||||||
| 122 | ind1: 1 | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ind2: ' ' | ||||||||||||||||||||||||||||||||||||||||||
| 124 | subfields: | ||||||||||||||||||||||||||||||||||||||||||
| 125 | - a : Test | ||||||||||||||||||||||||||||||||||||||||||
| 126 | - b : Rest | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | The loop variables can be used to have extra control over the processing of the | ||||||||||||||||||||||||||||||||||||||||||
| 129 | MARC fields. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | do marc_each(var:this) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # Set the indicator1 of all MARC 500 field to the value "3" | ||||||||||||||||||||||||||||||||||||||||||
| 133 | if all_match(this.tag,500) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | set_field(tag.ind1,3) | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # Store the result in the MARC file | ||||||||||||||||||||||||||||||||||||||||||
| 136 | marc_remove(500) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | marc_paste(this) | ||||||||||||||||||||||||||||||||||||||||||
| 138 | end | ||||||||||||||||||||||||||||||||||||||||||
| 139 | end | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | L<Catmandu::Fix::Bind> | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||||||||||||