Moose/Formater/UnimarcToMarc21.pm

filter: Statementstmt 5.7% 36 / 623 Branchbran 0.0% 0 / 462 Conditioncond 0.0% 0 / 41 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 1 totaltotal 3.6% 42 / 1162 CC 324 SCAR 114.1
CC
324
Cov
3%
__ANON__
96410.0
procedure_title
240.0
__ANON__
2.0
CRAP 90032.3
↑ Summary Moose/Lint/Checker/RulesFile.pm »
1 package MARC::Moose::Formater::UnimarcToMarc21;
2 4 $MARC::Moose::Formater::UnimarcToMarc21::VERSION = '1.0.46';
3 # ABSTRACT: Convert biblio record from UNIMARC to MARC21
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 extends 'MARC::Moose::Formater';
10  
11 4 ▶use List::Util qw/ first /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use MARC::Moose::Field::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use MARC::Moose::Field::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # Equivalence UNIMARC author type code > MARC21
17 # Each UNIMARC code points to a array ref which first entry contains MARC21
18 # code and second MARC21 author type description. The second entry isn't used
19 # yet.
20 4 my %authcode = map { /^(\d*) (\w*) (.*)$/; $1 => [$2, $3] } split /\n/, <<EOS;
21 005 act actor
22 010 adp adapter
23 020 ann annotator
24 030 arr arranger
25 040 art artist
26 050 asg assignee
27 060 asn associated name
28 065 auc auctioneer
29 070 aut author
30 072 aqt author in quotations or text abstract
31 075 aft author of afterword, colophon, etc.
32 080 aui author of introd
33 090 aus author of screenplay
34 100 ant bibl. antecedent
35 110 bnd binder
36 120 bdd binding designer
37 130 bkd book designer
38 140 bjd bkjacket designer
39 150 bpd bkplate designer
40 160 bsl bookseller
41 170 cll calligrapher
42 180 ctg cartographer
43 190 cns censor
44 200 chr choreographer
45 205 clb collaborator
46 210 cmm commentator
47 212 cwt commentator for written text
48 220 com compiler
49 230 cmp composer
50 240 cmt compositor
51 245 ccp conceptor
52 250 cnd conductor
53 255 csp consultant to a project
54 260 cph copyright holder
55 270 crr corrector
56 273 cur curator
57 275 dnc dancer
58 280 dte dedicatee
59 290 dto dedicator
60 295 dgg degree grantor
61 300 drt director
62 305 dis dissertant
63 310 dst distributor
64 320 dnr donor
65 330 dub dubious author
66 340 edt editor
67 350 egr engraver
68 360 etr etcher
69 365 exp expert
70 370 flm film editor
71 380 frg forger
72 390 fmo former owner
73 400 fnd funder
74 410 grt graphic technician
75 420 hnr honoree
76 430 ilu illuminator
77 440 ill illustrator
78 450 ins inscriber
79 460 ive interviewee
80 470 ivr interviewer
81 480 lbt librettist
82 490 lse licensee
83 500 lso licensor
84 510 ltg lithographer
85 520 lyr lyricist
86 530 mte metal engraver
87 540 mon monitor/contractor
88 545 mus musician
89 550 nrt narrator
90 555 opn opponent
91 557 orm organizer of meeting
92 560 org originator
93 570 oth other
94 580 ppm papermaker
95 582 pta patent applicant
96 584 inv inventor
97 587 pth patent holder
98 590 prf performer
99 595 res research
100 600 pht photographer
101 610 prt printer
102 620 pop printer of plates
103 630 pro producer
104 635 prg programmer
105 640 pfr proofreader
106 650 pbl publisher
107 651 pbd publishing director
108 660 rcp recipient
109 670 rce recording engineer
110 673 rth research team head
111 675 rev reviewer
112 677 rtm research team member
113 680 rbr rubricator
114 690 sce scenarist
115 695 sad scientific advisor
116 700 scr scribe
117 705 scl sulptor
118 710 sec secretary
119 720 sgn signer
120 721 sng singer
121 723 spn sponsor
122 725 stn standards body
123 727 ths thesis advisor
124 730 trl translator
125 740 tyd type designer
126 750 tyg typographer
127 755 voc vocalist
128 760 wde wood engraver
129 770 wam writer of accompanying material
130 EOS
131  
132 # UNIMARC 100 Type of pub
133 4 my %typeofpub = map { /(\w) (\w)/; $1 => $2; } split /\n/, <<EOS;
134 a c
135 b d
136 c u
137 d s
138 e r
139 f q
140 g m
141 h t
142 i p
143 j e
144 EOS
145  
146 # UNIMARC 100 Target Audience Code
147 4 my %target_audience = map { /(\w|\|) (\w|\|)/; $1 => $2; } split /\n/, <<EOS;
148 b a
149 c b
150 a j
151 d c
152 e d
153 k e
154 m g
155 | |
156 EOS
157  
158 # List of moved fields unchanged
159 4 my @unchanged;
160 4 push @unchanged, [$_, 500] for 300..315;
161 4 push @unchanged, [317, 561],
162 [320, 504],
163 [321, 500],
164 [322, 508],
165 [323, 511],
166 [324, 500],
167 [328, 502],
168 [330, 520],
169 [332, 524],
170 [333, 521],
171 [337, 538],
172 [686, '084'];
173  
174 # Tags with non-filing indicator (pos 1 or 2)
175 4 my $nonfiling_tags = [
176 [ qw/130 630 730 740 830/ ],
177 [ qw/240 242 243 245 440 830/ ],
178 ];
179  
180 # NSB/NSE characters
181 4 my $ns_characters = [
182 [ "\x08", "\x09" ],
183 [ "\x88", "\x89" ]
184 ];
185  
186  
187  
188 # Procedure 4 Title
189 sub procedure_title {
190 0 ▶ my ($self, $subf) = @_;
Subroutine procedure_title: not called CC=15 SCAR=54.8
Pod undocumented
191  
192 0 my @sf;
193 0 my ($h_index) = (-1);
194 0 my @equivals = (
195 [ 'a', 'a' ],
196 [ 'j', 'f' ],
197 [ 'n', 'g' ],
198 [ 'h', 'n', '.' ],
199 [ 'k', 'f', '.' ],
200 [ 'l', 'k', '.' ],
201 [ 'm', 'l', '.' ],
202 [ 'q', 's', '.' ],
203 [ 'r', 'r', ',' ],
204 [ 's', 's', ',' ],
205 [ 't', 'o', ';' ],
206 [ 'u', 'r', ',' ],
207 [ 'x', 'x', ',' ],
208 );
209 0 for ( @$subf ) {
210 0 my ($letter, $value) = @$_;
211 0 ▶ if ( my $equival = first { $_->[0] eq $letter } @equivals ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $equival = &first(sub { $_->[0] eq $letter; } , @equivals)) { } 0 0 0
212 0 my ($from, $to, $sep) = @$equival;
213 0 ▶ if ( $sep && @sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep and @sf) 0 0 0
Condition0%0/3
$sep and @sf
!ll&&!rl&&r
000
MC/DC0%0/2
$sep and @sf
$sep @sf
Truth table0%0/3
A and B
A= $sepB= @sf
ABresult
0X0
100
111
214 0 my $match = $sep;
215 0 ▶ $match = '\.' if $match eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $match eq "." 0 0 0
216 0 ▶ if ( $sf[-1]->[0] !~ /$match$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sf[-1][0] =~ /$match$/) 0 0 0
217 0 $sf[-1]->[1] .= $sep;
218 }
219 }
220 0 push @sf, [ $to => $value ];
221 }
222 else {
223 0 for ($letter) {
224 0 ▶ if ( /e/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/e/) { } 0 0 0
elsif (/i/) { } 0 0 0
225 0 ▶ next unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
226 0 ▶ if ( $sf[-1][0] =~ /a|n|p/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf[-1][0] =~ /a|n|p/) { } 0 0 0
227 0 $sf[-1]->[1] .= ' :';
228 0 push @sf, [ b => $value ];
229 }
230 else {
231 0 $sf[-1]->[1] .= " : $value";
232 }
233 }
234 elsif ( /i/ ) {
235 0 ▶ if ( @sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) 0 0 0
236 0 ▶ if ( $sf[-1]->[0] eq 'h' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf[-1][0] eq 'h') { } 0 0 0
237 0 ▶ $sf[-1]->[1] .= ',' if $sf[-1]->[1] !~ /,$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sf[-1][1] =~ /,$/ 0 0 0
238 }
239 else {
240 0 $sf[-1]->[1] .= '.';
241 }
242 }
243 0 push @sf, [ p => $value ];
244 }
245 }
246 }
247 }
248  
249 0 return \@sf;
250 }
251  
252  
253 override 'format' => sub {
254 0 ▶ my ($self, $unimarc) = @_;
Subroutine __ANON__: not called CC=310 SCAR=114.8
255  
256 0 my $record = MARC::Moose::Record->new();
257  
258 0 $record->_leader(" nam a22 7a 4500");
259  
260 0 my $code008 = '120130t xxu||||| |||| 00| 0 ||| d';
261  
262 0 my @sf040;
263  
264 # 001 => 001
265 0 for my $field ( $unimarc->field('001' ) ) {
266 0 $record->append($field->clone());
267 }
268  
269 # ISBN 010 => 020
270 0 for my $field ( $unimarc->field('010') ) {
271 0 my @sf;
272 0 for ( @{$field->subf} ) {
273 0 my ($letter, $value) = @$_;
274 0 for ($letter) {
275 0 ▶ if ( /a|z/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/a|z/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/d/) { } 0 0 0
276 0 $value =~ s/-//g;
277 0 push @sf, [ $letter => $value ];
278 }
279 elsif ( /b/ ) {
280 0 ▶ $value = "($value)" unless $value =~ /^\(/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\(/ 0 0 0
281 0 ▶ if (@sf) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) { } 0 0 0
282 0 $sf[-1]->[1] .= " $value";
283 }
284 else {
285 0 push @sf, [ c => $value ];
286 }
287 }
288 elsif ( /d/ ) {
289 0 ▶ if (@sf) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) 0 0 0
290 0 $sf[-1]->[1] .= " :";
291 }
292 0 push @sf, [ c => $value ];
293 }
294 }
295 }
296 0 $record->append( MARC::Moose::Field::Std->new(
297 tag => '020', subf => \@sf ) );
298 }
299  
300 # ISSN 011 => 022
301 # Except 011$b$d => 365
302 0 for my $field ( $unimarc->field('011') ) {
303 0 my (@sf, @price);
304 0 for ( @{$field->subf} ) {
305 0 my ($letter, $value) = @$_;
306 0 for ($letter) {
307 0 ▶ if ( /a/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/z/) { } 0 0 0
elsif (/b|d/) { } 0 0 0
308 0 $value =~ s/-//g;
309 0 push @sf, [ a => $value ];
310 }
311 elsif ( /z/ ) {
312 0 $value =~ s/-//g;
313 0 push @sf, [ y => $value ];
314 }
315 elsif ( /b|d/ ) {
316 0 ▶ $value = "($value)" unless $value =~ /^\(/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\(/ 0 0 0
317 0 ▶ my $newlet = $letter eq 'b' ? 'b' : 'd';
Branch: 1 branch
BranchTrueFalseTotal
$letter eq 'b' ? : 0 0 0
318 0 push @price, [ $newlet => $value ];
319 }
320 }
321 }
322 0 ▶ $record->append( MARC::Moose::Field::Std->new(
Branch: 1 branch
BranchTrueFalseTotal
if @sf 0 0 0
323 tag => '022', subf => \@sf ) ) if @sf;
324 0 ▶ $record->append(MARC::Moose::Field::Std->new(
Branch: 1 branch
BranchTrueFalseTotal
if @price 0 0 0
325 tag => '365', subf => \@price ) ) if @price;
326 }
327  
328 # EAN 076 => 024. Get only $a subfield
329 0 for my $field ( $unimarc->field('073') ) {
330 0 my $value = $field->subfield('a');
331 0 ▶ next unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
332 0 $record->append( MARC::Moose::Field::Std->new(
333 tag => '024', subf => [ [ a => $value ] ] ) );
334 }
335  
336 # 100 => 008
337 0 ▶ if ( my $field = $unimarc->field('100') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $field = $unimarc->field(100)) 0 0 0
338 0 my $code100 = $field->subfield('a');
339 0 ▶ if ( $code100 && length($code100) > 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code100 and length $code100 > 20) 0 0 0
Condition0%0/3
$code100 and length $code100 > 20
!ll&&!rl&&r
000
MC/DC0%0/2
$code100 and length $code100 > 20
$code100 length $code100 > 20
Truth table0%0/3
A and B
A= $code100B= length $code100 > 20
ABresult
0X0
100
111
340 # Date entered on file
341 0 substr $code008, 0, 6, substr($code100, 2, 6);
342  
343 # Type of publication date
344 0 my $value = substr($code100, 8, 1);
345 0 ▶ $value = $typeofpub{$value} || ' ';
Condition0%0/2
$typeofpub{$value} || ' '
l!l
00
MC/DC0%0/1
$typeofpub{$value} || ' '
$typeofpub{$value}
Truth table0%0/2
A
A= $typeofpub{$value}
Aresult
11
00
346 0 substr $code008, 6, 1, $value;
347  
348 # Date 1
349 0 $value = substr($code100, 9, 4);
350 0 if ( 1 ) { #FIXME Determine if it's a serials
351 # Not serials
352 0 my $count = 0;
353 0 ▶ for ( split //, $value ) { $count++ if / /; }
Branch: 1 branch
BranchTrueFalseTotal
if / / 0 0 0
354 0 ▶ $value =~ s/ /0/g if $count <= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $count <= 3 0 0 0
355 }
356 else {
357 # A serials
358 $value =~ s/ /u/g;
359 }
360 0 substr $code008, 7, 4, $value;
361  
362 # Date 2
363 0 $value = substr($code100, 13, 4);
364 0 if ( 1 ) { #FIXME Determine if it's a serials
365 # Not serials
366 0 my $count = 0;
367 0 ▶ for ( split //, $value ) { $count++ if / /; }
Branch: 1 branch
BranchTrueFalseTotal
if / / 0 0 0
368 0 ▶ $value =~ s/ /0/g if $count <= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $count <= 3 0 0 0
369 }
370 else {
371 # A serials
372 $value =~ s/ /u/g;
373 }
374 0 substr $code008, 11, 4, $value;
375  
376 # 3 positions for target audience
377 0 $value = substr($code100, 17, 3);
378 0 ▶ for (my $i=0; $i < 3; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 3) 0 0 0
379 0 $value = substr($code100, 17+$i, 1);
380 0 ▶ $value = $target_audience{$value} || ' ';
Condition0%0/2
$target_audience{$value} || ' '
l!l
00
MC/DC0%0/1
$target_audience{$value} || ' '
$target_audience{$value}
Truth table0%0/2
A
A= $target_audience{$value}
Aresult
11
00
381 0 substr $code008, 17+$i, 1, $value;
382 }
383
384 # Language of cataloging
385 0 push @sf040, [ b => substr($code100, 22, 3) ];
386  
387 # Alphabet of title, converted if serials
388 # FIXME
389 0 if ( 0 ) {
390 substrr $code008, 33, 1, substr($code100,34,1);
391 }
392 }
393 }
394  
395 # Language 101 => 041 and 008
396 0 ▶ if ( my $field = $unimarc->field('101') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $field = $unimarc->field('101')) { } 0 0 0
397 # FIXME: à virer
398 0 ▶ if ( ref($field) eq 'MARC::Moose::Field::Control' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "MARC::Moose::Field::Control") 0 0 0
399 0 say $unimarc->as('Text');
400 0 exit;
401 }
402 0 my @all = @{$field->subf};
403 0 my $count_a = 0;
404 0 my (@sf, @sf_b);
405 0 for (@all) {
406 0 my ($letter, $value) = @$_;
407 0 for ($letter) {
408 0 ▶ if ( /a/ ) {
Branch: 9 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/c/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/e/) { } 0 0 0
elsif (/f|g/) { } 0 0 0
elsif (/j/) { } 0 0 0
elsif (/h/) { } 0 0 0
elsif (/i/) { } 0 0 0
409 0 ▶ next if $count_a >= 6;
Branch: 1 branch
BranchTrueFalseTotal
if $count_a >= 6 0 0 0
410 0 $count_a++;
411 0 ▶ if ( $count_a == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count_a == 1) 0 0 0
412 0 $value .= ' ';
413 0 $value = substr($value, 0, 3);
414 0 substr $code008, 35, 3, $value;
415 }
416 0 push @sf, [ a => $value];
417 }
418 0 elsif ( /c/ ) { push @sf, [ h => $value ]; }
419 0 elsif ( /b/ ) { push @sf_b, $value; }
420 0 elsif ( /d/ ) { push @sf, [ b => $value ]; }
421 0 elsif ( /e/ ) { push @sf, [ f => $value ]; }
422 elsif ( /f|g/ ) { }
423 0 elsif ( /j/ ) { push @sf, [ b => $value ]; }
424 0 elsif ( /h/ ) { push @sf, [ e => $value ]; }
425 0 elsif ( /i/ ) { push @sf, [ g => $value ]; }
426 }
427 }
428 0 ▶ if ( @sf_b ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf_b) 0 0 0
429 0 for ( @sf ) {
430 0 ▶ if ($_->[0] eq 'h') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[0] eq "h") 0 0 0
431 0 $_->[1] .= ' ' . join(' ', @sf_b);
432 0 last;
433 }
434 }
435 }
436 0 my $ind1 = $field->ind1;
437 0 ▶ $ind1 = '0' if $ind1 eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $ind1 eq " " 0 0 0
438 0 ▶ $ind1 = '1' if $ind1 eq '2';
Branch: 1 branch
BranchTrueFalseTotal
if $ind1 eq 2 0 0 0
439 0 $record->append( MARC::Moose::Field::Std->new(
440 tag => '041',
441 ind1 => $ind1,
442 subf => \@sf ) );
443 }
444 else {
445 0 substr($code008, 35, 3) = '|||';
446 }
447  
448 # 125 => 008
449 # FIXME: 125$b isn't handled at all
450 0 ▶ if ( my $field = $unimarc->field('125') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $field = $unimarc->field(125)) 0 0 0
451 0 my $value = $field->subfield('a');
452 0 my ($pos0, $pos1);
453 0 ▶ $pos0 = substr($value, 0, 1) if $value && length($value) >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $value and length $value >= 1 0 0 0
Condition0%0/3
$value and length $value >= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$value and length $value >= 1
$value length $value >= 1
Truth table0%0/3
A and B
A= $valueB= length $value >= 1
ABresult
0X0
100
111
454 0 ▶ $pos1 = substr($value, 1, 1) if $value && length($value) >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $value and length $value >= 2 0 0 0
Condition0%0/3
$value and length $value >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$value and length $value >= 2
$value length $value >= 2
Truth table0%0/3
A and B
A= $valueB= length $value >= 2
ABresult
0X0
100
111
455 0 ▶ $pos0 ||= '|';
Condition0%0/2
$pos0 ||= "|"
l!l
00
MC/DC0%0/1
$pos0 ||= "|"
$pos0
Truth table0%0/2
A
A= $pos0
Aresult
11
00
456 0 ▶ $pos0 = 'n' if $pos0 eq 'x';
Branch: 1 branch
BranchTrueFalseTotal
if $pos0 eq "x" 0 0 0
457 0 ▶ $pos1 ||= '|';
Condition0%0/2
$pos1 ||= "|"
l!l
00
MC/DC0%0/1
$pos1 ||= "|"
$pos1
Truth table0%0/2
A
A= $pos1
Aresult
11
00
458 0 ▶ $pos1 = 'n' if $pos1 eq 'x';
Branch: 1 branch
BranchTrueFalseTotal
if $pos1 eq "x" 0 0 0
459 0 ▶ $pos1 = ' ' if $pos1 eq 'y';
Branch: 1 branch
BranchTrueFalseTotal
if $pos1 eq "y" 0 0 0
460 0 substr($code008, 20, 2) = $pos0 . $pos1;
461 }
462  
463 0 $record->append( MARC::Moose::Field::Control->new(
464 tag => '008', value => $code008 ) );
465  
466 # Title
467 0 for my $field ( $unimarc->field('200') ) {
468 0 my @sf;
469 0 my ($a_index, $h_index) = (-1, -1);
470 SUBFIELD200:
471 0 for ( @{$field->subf} ) {
472 0 my ($letter, $value) = @$_;
473 0 for ($letter) {
474 0 ▶ if ( /a/ ) {
Branch: 10 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/c/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/e/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/g/) { } 0 0 0
elsif (/h/) { } 0 0 0
elsif (/i/) { } 0 0 0
elsif (/v|z|5|6|7/) { } 0 0 0
475 0 ▶ if ( $a_index == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_index == -1) { } 0 0 0
476 0 push @sf, [ a => $value ];
477 0 $a_index = $#sf;
478 }
479 else {
480 0 $sf[$a_index]->[1] .= " ; $value";
481 }
482 }
483 elsif ( /b/) {
484 0 ▶ if ( $h_index == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h_index == -1) { } 0 0 0
485 0 push @sf, [ h => $value ];
486 0 $h_index = $#sf;
487 }
488 else {
489 0 ▶ if ( $#sf == $h_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#sf == $h_index) { } 0 0 0
490 0 $sf[$h_index]->[1] .= " + $value";
491 }
492 else {
493 0 $sf[-1]->[1] .= " ($value)";
494 }
495 }
496 }
497 elsif ( /c/ ) {
498 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
499 0 $sf[-1]->[1] .= ". $value";
500 }
501 elsif ( /d/ ) {
502 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
503 0 ▶ if ( $sf[-1]->[0] =~ /a|n|p/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf[-1][0] =~ /a|n|p/) { } 0 0 0
504 0 $sf[-1]->[1] .= ' =';
505 0 $value =~ s/^= //;
506 0 push @sf, [ b => $value ];
507 }
508 else {
509 0 $sf[-1]->[1] .= " = $value";
510 }
511 }
512 elsif ( /e/ ) {
513 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
514 0 ▶ if ( $sf[-1]->[0] =~ /a|n|p/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf[-1][0] =~ /a|n|p/) { } 0 0 0
515 0 $sf[-1]->[1] .= ' :';
516 0 push @sf, [ b => $value ];
517 }
518 else {
519 0 $sf[-1]->[1] .= " : $value";
520 }
521 }
522 elsif ( /f/) {
523 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
524 0 ▶ if ( $sf[-1]->[0] =~ /a|b|n|p/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf[-1][0] =~ /a|b|n|p/) { } 0 0 0
525 0 $sf[-1]->[1] .= ' /';
526 0 push @sf, [ c => $value ];
527 }
528 else {
529 0 $sf[-1]->[1] .= " / $value";
530 }
531 }
532 elsif ( /g/) {
533 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
534 0 $sf[-1]->[1] .= " ; $value";
535 }
536 elsif ( /h/ ) {
537 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
538 0 ▶ if ( $sf[-1]->[0] =~ /a|n|p/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf[-1][0] =~ /a|n|p/) { } 0 0 0
539 0 $sf[-1]->[1] .= '.';
540 0 push @sf, [ n => $value ];
541 }
542 else {
543 #$sf[-1]->[1] .= ". $value";
544 0 push @sf, [ n => $value ];
545 }
546 }
547 elsif ( /i/ ) {
548 0 ▶ next SUBFIELD200 unless @sf; #FIXME warning required
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
549 0 ▶ if ( @sf && $sf[-1]->[0] =~ /a|n|p/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf and $sf[-1][0] =~ /a|n|p/) { } 0 0 0
Condition0%0/3
@sf and $sf[-1][0] =~ /a|n|p/
!ll&&!rl&&r
000
MC/DC0%0/2
@sf and $sf[-1][0] =~ /a|n|p/
@sf $sf[-1][0] =~ /a|n|p/
Truth table0%0/3
A and B
A= @sfB= $sf[-1][0] =~ /a|n|p/
ABresult
0X0
100
111
550 0 $sf[-1]->[1] .= ',';
551 0 push @sf, [ p => $value ];
552 }
553 else {
554 0 $sf[-1]->[1] .= ". $value";
555 }
556 }
557 0 elsif ( /v|z|5|6|7/ ) { next SUBFIELD200 }
558 }
559 }
560 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
561 0 ▶ $sf[$h_index]->[1] = '[' . $sf[$h_index]->[1] . ']' unless $h_index == -1;
Branch: 1 branch
BranchTrueFalseTotal
unless $h_index == -1 0 0 0
562 # Point final
563 0 ▶ if (@sf) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) 0 0 0
564 0 my $last_value = $sf[-1][1];
565 0 my $last_char = substr($last_value, length($last_value)-1);
566 0 ▶ $sf[-1][1] = "$last_value." if $last_char !~ /[.?,;:]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $last_char =~ /[.?,;:]/ 0 0 0
567 }
568  
569 # Indicators
570 0 my ($ind1, $ind2) = ($field->ind1, 0);
571 0 for ($ind1) {
572 0 ▶ if ( /0/ ) { }
Branch: 2 branches
BranchTrueFalseTotal
if (/0/) { } 0 0 0
elsif (/1/) { } 0 0 0
573 elsif ( /1/ ) {
574 #FIXME Test marc21 100/110/111/130 presence
575 0 ▶ $ind1 = $unimarc->field('700|710' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$unimarc->field('700|710') ? : 0 0 0
576 }
577 0 else { $ind1 = 1; }
578 }
579 0 $record->append( MARC::Moose::Field::Std->new(
580 tag => '245', ind1 => $ind1, ind2 => $ind2,
581 subf => \@sf ) );
582 }
583
584 # TODO 204
585  
586 # 205 => 250
587 0 for my $field ($unimarc->field('205') ) {
588 0 my @sf;
589 0 my ($a_index, $b_index) = (-1, -1);
590 0 for ( @{$field->subf} ) {
591 0 my ($letter, $value) = @$_;
592 0 for ($letter) {
593 0 ▶ if ( /a/ ) {
Branch: 5 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/g/) { } 0 0 0
594 0 ▶ if ( $a_index == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_index == -1) { } 0 0 0
595 0 push @sf, [ a => $value ];
596 0 $a_index = $#sf;
597 }
598 else {
599 0 $sf[$a_index]->[1] .= ", $value";
600 }
601 }
602 elsif ( /b/ ) {
603 0 ▶ if ( @sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) { } 0 0 0
604 0 $sf[-1]->[1] .= ", $value";
605 }
606 else {
607 0 push @sf, [ a => $value ];
608 0 $a_index = $#sf;
609 }
610 }
611 elsif ( /d/ ) {
612 0 ▶ if ( $b_index == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_index == -1) { } 0 0 0
613 0 push @sf, [ b => $value];
614 0 $b_index = $#sf;
615 }
616 else {
617 0 $sf[-1]->[1] .= " $value";
618 }
619 }
620 elsif ( /f/ ) {
621 0 ▶ if ( $b_index == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_index == -1) { } 0 0 0
622 0 ▶ $sf[-1]->[1] .= " / " if @sf;
Branch: 1 branch
BranchTrueFalseTotal
if @sf 0 0 0
623 0 push @sf, [ b => $value];
624 0 $b_index = $#sf;
625 }
626 else {
627 0 $sf[-1]->[1] .= " / $value";
628 }
629 }
630 elsif ( /g/ ) {
631 0 ▶ if ( @sf ) { $sf[-1]->[1] .= " / $value"; }
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) { } 0 0 0
632 0 else { push @sf, [ a => $value ] }
633 }
634 }
635 }
636 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
637 0 ▶ if ( $b_index >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_index >= 1) 0 0 0
638 0 my $value = $sf[$b_index]->[1];
639 0 ▶ if ( $value =~ /= $/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /= $/) 0 0 0
640 0 $value =~ s/= $//;
641 0 $sf[$b_index]->[1] = $value;
642 0 $sf[$b_index-1]->[1] .= '= ';
643 }
644 }
645 # Point final
646 0 ▶ $sf[-1][1] = $sf[-1][1] . '.' if @sf && $sf[-1][1] !~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
if @sf and not $sf[-1][1] =~ /\.$/ 0 0 0
Condition0%0/3
@sf and not $sf[-1][1] =~ /\.$/
!ll&&!rl&&r
000
MC/DC0%0/2
@sf and not $sf[-1][1] =~ /\.$/
@sf not $sf[-1][1] =~ /\.$/
Truth table0%0/3
A and not(B)
A= @sfB= not $sf[-1][1] =~ /\.$/
ABresult
0X0
100
111
647 0 $record->append( MARC::Moose::Field::Std->new(
648 tag => '250', ind1 => $field->ind1, ind2 => $field->ind2,
649 subf => \@sf ) );
650 }
651  
652 # TODO 206
653  
654 # 207 => 362
655 0 for my $field ($unimarc->field('207') ) {
656 0 my @sf;
657 0 my $a_index = -1;
658 0 for ( @{$field->subf} ) {
659 0 my ($letter, $value) = @$_;
660 0 for ($letter) {
661 0 ▶ if ( /a/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/v/) { } 0 0 0
662 0 ▶ if ( $a_index == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_index == -1) { } 0 0 0
663 0 push @sf, [ a => $value ];
664 0 $a_index = $#sf;
665 }
666 else {
667 0 my $prev = $sf[$a_index]->[1];
668 0 $prev =~ s/ *$//;
669 0 $prev =~ s/;$//;
670 0 $prev =~ s/ *$//;
671 0 $sf[$a_index]->[1] = "$prev ; $value";
672 }
673 }
674 elsif ( /v/ ) {
675 0 push @sf, [ z => $value ];
676 }
677 }
678 }
679 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
680 # Point at the end
681 0 ▶ $sf[-1][1] = $sf[-1][1] . '.' if @sf && $sf[-1][1] !~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
if @sf and not $sf[-1][1] =~ /\.$/ 0 0 0
Condition0%0/3
@sf and not $sf[-1][1] =~ /\.$/
!ll&&!rl&&r
000
MC/DC0%0/2
@sf and not $sf[-1][1] =~ /\.$/
@sf not $sf[-1][1] =~ /\.$/
Truth table0%0/3
A and not(B)
A= @sfB= not $sf[-1][1] =~ /\.$/
ABresult
0X0
100
111
682 0 $record->append( MARC::Moose::Field::Std->new(
683 tag => '362', ind2 => $field->ind1,
684 subf => \@sf ) );
685 }
686  
687 #TODO 208
688  
689 # 210/214 => 260
690 0 for my $field ( $unimarc->field('210|214') ) {
691 0 my @sf;
692 0 for ( @{$field->subf} ) {
693 0 my ($letter, $value) = @$_;
694 0 $value =~ s/^ *//, $value =~ s/ *$//;
695 0 my %found;
696 0 for ($letter) {
697 0 ▶ if ( /a/ ) {
Branch: 12 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/c/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/e/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/g/) { } 0 0 0
elsif (/h/) { } 0 0 0
elsif (/j/) { } 0 0 0
elsif (/k/) { } 0 0 0
elsif (/l/) { } 0 0 0
elsif (/m/) { } 0 0 0
698 0 push @sf, [ a => $value ];
699 }
700 elsif ( /b/ ) {
701 0 ▶ $value = "($value)" if $value !~ /^\(/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\(/ 0 0 0
702 0 ▶ if ( @sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) { } 0 0 0
703 0 $sf[-1]->[1] .= " $value";
704 }
705 else {
706 0 push @sf, [ a => $value ];
707 }
708 }
709 elsif ( /c/ ) {
710 0 push @sf, [ b => $value ];
711 }
712 elsif ( /d/ ) {
713 0 push @sf, [ c => $value ];
714 }
715 elsif ( /e/ ) {
716 0 push @sf, [ e => $value ];
717 }
718 elsif ( /f/ ) {
719 0 ▶ unless ( $found{$letter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found{$letter}) 0 0 0
720 0 $found{$letter} = 1;
721 0 ▶ $sf[-1]->[1] .= ", $value" if @sf;
Branch: 1 branch
BranchTrueFalseTotal
if @sf 0 0 0
722 }
723 }
724 elsif ( /g/ ) {
725 0 ▶ unless ( $found{$letter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found{$letter}) 0 0 0
726 0 $found{$letter} = 1;
727 0 push @sf, [ f => $value ];
728 }
729 }
730 elsif ( /h/ ) {
731 0 ▶ unless ( $found{$letter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found{$letter}) 0 0 0
732 0 $found{$letter} = 1;
733 0 push @sf, [ g => $value ];
734 }
735 }
736 elsif ( /j/ ) {
737 0 $record->append( MARC::Moose::Field::Std->new(
738 tag => '265', subf => [ a => $value ] ) );
739 }
740 elsif ( /k/ ) {
741 0 $record->append( MARC::Moose::Field::Std->new(
742 tag => '265', ind1 => '0', ind2 => '0',
743 subf => [ a => $value ] ) );
744 }
745 elsif ( /l/ ) {
746 0 $record->append( MARC::Moose::Field::Std->new(
747 tag => '265', ind1 => '1', ind2 => '0',
748 subf => [ [ a => $value ] ] ) );
749 }
750 elsif ( /m/ ) {
751 0 $record->append( MARC::Moose::Field::Std->new(
752 tag => '265', ind1 => '2', ind2 => '0',
753 subf => [ a => $value ] ) );
754 }
755 }
756 }
757 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
758 # Ponctuation
759 0 ▶ for (my $i=0; $i < @sf; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @sf) 0 0 0
760 0 my ($letter, $value) = @{$sf[$i]};
761 0 for ($letter) {
762 0 ▶ if ( /a/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/b|f/) { } 0 0 0
elsif (/c|g/) { } 0 0 0
763 0 ▶ $sf[$i-1]->[1] .= ' ;' if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 0 0
764 }
765 elsif ( /b|f/ ) {
766 0 ▶ $sf[$i-1]->[1] .= ' :' if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 0 0
767 }
768 elsif ( /c|g/ ) {
769 0 ▶ $sf[$i-1]->[1] .= ',' if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 0 0
770 }
771 }
772 0 ▶ $value = "($value)" if $letter =~ /e|f|g/;
Branch: 1 branch
BranchTrueFalseTotal
if $letter =~ /e|f|g/ 0 0 0
773 0 ▶ if ( $value =~ /^= / ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^= /) 0 0 0
774 0 $value =~ s/^= //;
775 0 ▶ $sf[$i-1]->[1] .= ' =' if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 0 0
776 }
777 0 $sf[$i]->[1] = $value;
778 }
779 0 ▶ $sf[-1][1] = $sf[-1][1] . '.' if @sf && $sf[-1][1] !~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
if @sf and not $sf[-1][1] =~ /\.$/ 0 0 0
Condition0%0/3
@sf and not $sf[-1][1] =~ /\.$/
!ll&&!rl&&r
000
MC/DC0%0/2
@sf and not $sf[-1][1] =~ /\.$/
@sf not $sf[-1][1] =~ /\.$/
Truth table0%0/3
A and not(B)
A= @sfB= not $sf[-1][1] =~ /\.$/
ABresult
0X0
100
111
780 0 $record->append( MARC::Moose::Field::Std->new( tag => '260', subf => \@sf ) );
781 }
782  
783 # TODO 211 => 263
784  
785 # 215 => 300
786 0 for my $field ( $unimarc->field('215') ) {
787 0 my @sf;
788 SUBFIELD215:
789 0 for ( @{$field->subf} ) {
790 0 my ($letter, $value) = @$_;
791 0 $value =~ s/^ *//, $value =~ s/ *$//;
792 0 for ($letter) {
793 0 ▶ if ( /c/ ) { $letter = 'b'; }
Branch: 3 branches
BranchTrueFalseTotal
if (/c/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/6|7/) { } 0 0 0
794 0 elsif ( /d/ ) { $letter = 'c'; }
795 0 elsif ( /6|7/ ) { next SUBFIELD215; }
796 }
797 0 push @sf, [ $letter => $value ];
798 }
799 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
800 # Ponctuation
801 0 ▶ for (my $i=1; $i < @sf; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @sf) 0 0 0
802 0 my ($letter, $value) = @{$sf[$i]};
803 0 for ($letter) {
804 0 ▶ if ( /b/ ) { $sf[$i-1]->[1] .= ' :'; }
Branch: 3 branches
BranchTrueFalseTotal
if (/b/) { } 0 0 0
elsif (/c/) { } 0 0 0
elsif (/e/) { } 0 0 0
805 0 elsif ( /c/ ) { $sf[$i-1]->[1] .= ' ;'; }
806 0 elsif ( /e/ ) { $sf[$i-1]->[1] .= ' + '; }
807 }
808 }
809 0 ▶ $sf[-1][1] = $sf[-1][1] . '.' if $sf[-1][1] !~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sf[-1][1] =~ /\.$/ 0 0 0
810 0 $record->append( MARC::Moose::Field::Std->new( tag => '300', subf => \@sf ) );
811 }
812  
813 # 225 => 490
814 0 for my $field ( $unimarc->field('225') ) {
815 0 my (@sf, @a, @vx);
816 0 my $prev_letter = '';
817 0 for ( @{$field->subf} ) {
818 0 my ($letter, $value) = @$_;
819 0 $value =~ s/^ *//, $value =~ s/ *$//;
820 0 $value =~ s/\x88//g, $value =~ s/\x89//;
821 0 for ($letter) {
822 0 ▶ if ( /a/ ) { push @a, $value; }
Branch: 7 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/e/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/h/) { } 0 0 0
elsif (/i/) { } 0 0 0
elsif (/v|x/) { } 0 0 0
823 0 elsif ( /d/ ) { push @a, " = $value" }
824 0 elsif ( /e/ ) { push @a, " : $value" }
825 0 elsif ( /f/ ) { push @a, " / $value" }
826 0 elsif ( /h/ ) { push @a, ". $value" }
827 elsif ( /i/ ) {
828 0 ▶ push @a, $prev_letter eq 'h' ? ", $value " : ". $value";
Branch: 1 branch
BranchTrueFalseTotal
$prev_letter eq 'h' ? : 0 0 0
829 }
830 0 elsif ( /v|x/ ) { push @vx, [ $letter => $value ] }
831 }
832 0 $prev_letter = $letter;
833 }
834 0 ▶ next unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 0 0
835 0 push @sf, [ a => join('', @a) ];
836 0 push @sf, @vx;
837 0 ▶ $record->append( MARC::Moose::Field::Std->new(
Branch: 1 branch
BranchTrueFalseTotal
$field->ind1 =~ /0|2/ ? : 0 0 0
838 tag => '490',
839 ind1 => $field->ind1 =~ /0|2/ ? 1 : 0,
840 subf => \@sf ) );
841 }
842  
843 # 230 => 256
844 0 for my $field ( $unimarc->field('230') ) {
845 0 $record->append($field->clone('256'));
846 }
847  
848 # Unchanged fields
849 0 for my $fromto ( @unchanged ) {
850 0 my ($from, $to) = @$fromto;
851 0 for my $field ( $unimarc->field($from) ) {
852 0 $record->append($field->clone($to));
853 }
854 }
855  
856 # 325 => 533
857 0 for my $field ( $unimarc->field('325') ) {
858 0 $record->append( MARC::Moose::Field::Std->new(
859 tag => '533',
860 subf => [ [ n => $field->subfield('a') ] ] ) );
861 }
862  
863 # 326 => 533
864 0 for my $field ( $unimarc->field('326') ) {
865 # FIXME Should be done depending on biblio record type:
866 # MAP, SERIALS
867 0 my $type = 'SERIALS';
868 0 my $new_field;
869 0 ▶ if ( $type =~ /SERIALS/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /SERIALS/) 0 0 0
870 0 $new_field = $field->clone('310');
871 }
872 0 $record->append($new_field);
873 }
874  
875 # 327 => 505
876 0 for my $field ( $unimarc->field('327') ) {
877 0 my $ind1 = $field->ind1;
878 0 ▶ $ind1 = 0 if $ind1 =~ /1/;
Branch: 1 branch
BranchTrueFalseTotal
if $ind1 =~ /1/ 0 0 0
879 0 ▶ $ind1 = 1 if $ind1 =~ /0/;
Branch: 1 branch
BranchTrueFalseTotal
if $ind1 =~ /0/ 0 0 0
880 0 my @a = map { $_->[1] } @{$field->subf};
881 0 $record->append( MARC::Moose::Field::Std->new(
882 tag => '505', ind1 => $ind1,
883 subf => [ [ a => join(' ', @a) ] ] ) );
884 }
885  
886 # 329 => 505
887 # This is French (CCfr) specific field without equivalent in MARC21
888 # Concatained into 505 field
889 0 for my $field ( $unimarc->field('359') ) {
890 0 my @a = map { $_->[1] } @{$field->subf};
891 0 $record->append( MARC::Moose::Field::Std->new(
892 tag => '505', ind1 => '0',
893 subf => [ [ a => join(' -- ', @a) ] ] ) );
894 }
895  
896  
897 # 336 => 500
898 0 for my $field ( $unimarc->field('336') ) {
899 0 $record->append( MARC::Moose::Field::Std->new(
900 tag => '500',
901 subf => [ [ a => 'Type of computer file: ' . $field->subfield('a') ] ] ) );
902 }
903  
904 # 345 => 037
905 0 for my $field ( $unimarc->field('345') ) {
906 0 my @sf;
907 0 for ( @{$field->subf} ) {
908 0 my ($letter, $value) = @$_;
909 0 ▶ $letter = $letter eq 'a' ? 'b' :
Branch: 4 branches
BranchTrueFalseTotal
$letter eq 'a' ? : 0 0 0
$letter eq 'b' ? : 0 0 0
$letter eq 'c' ? : 0 0 0
$letter eq 'd' ? : 0 0 0
910 $letter eq 'b' ? 'a' :
911 $letter eq 'c' ? 'f' :
912 $letter eq 'd' ? 'c' : $letter;
913 0 push @sf, [ $letter => $value ];
914 }
915 0 $record->append( MARC::Moose::Field::Std->new(
916 tag => '037', subf => \@sf ) );
917 }
918  
919 # TODO 410 411 421 422 423 430 431 432 433 434 435 436 437 440 441 442 443
920 # 444 445 446 447 448 451 452 453
921  
922 # 454 => 765
923 0 for my $ft ( (
924 [410, 760],
925 [411, 762],
926 [421, 770],
927 [422, 772],
928 [423, 777],
929 [430, 780, 0],
930 [431, 780, 1],
931 [432, 780, 2],
932 [433, 780, 3],
933 [434, 780, 5],
934 [435, 780, 6],
935 [436, 780, 4],
936 [437, 780, 7],
937 [440, 785, 0],
938 [441, 785, 1],
939 [442, 785, 2],
940 [443, 785, 3],
941 [444, 785, 4],
942 [445, 785, 5],
943 [446, 785, 6],
944 [447, 785, 7],
945 [448, 785, 8],
946 [451, 775],
947 [452, 776],
948 [453, 767],
949 [454, 765],
950 [455, 787, 8, 'Reproduction of:'],
951 [456, 787, 8, 'Reproduced as:'],
952 [461, 773],
953 [462, 774],
954 [463, 773],
955 [464, 774],
956 [470, 787, 8, 'Item reviewed:'],
957 [488, 787, 8, 'Reproduced as:'],
958 [491, 774],
959 [492, 774],
960 [493, 773],
961 [494, 773],
962 ) ) {
963 0 my ($from, $to, $ind2, $text) = @$ft;
964 0 ▶ $ind2 = ' ' unless $ind2;
Branch: 1 branch
BranchTrueFalseTotal
unless $ind2 0 0 0
965 0 for my $field ( $unimarc->field($from) ) {
966 0 my @sf;
967 0 ▶ push @sf, [ i => $text ] if $text;
Branch: 1 branch
BranchTrueFalseTotal
if $text 0 0 0
968 0 for ( @{$field->subf} ) {
969 0 my ($letter, $value) = @$_;
970 0 ▶ if ( $letter eq 't') {
Branch: 1 branch
BranchTrueFalseTotal
if ($letter eq "t") 0 0 0
971 0 $value =~ s/\x{0088}//g;
972 0 $value =~ s/\x{0089}//g;
973 }
974 0 ▶ $letter = $letter eq '1' ? 'a' :
Branch: 4 branches
BranchTrueFalseTotal
$letter eq '1' ? : 0 0 0
$letter eq '3' ? : 0 0 0
$letter eq 'v' ? : 0 0 0
$letter eq 'y' ? : 0 0 0
975 $letter eq '3' ? 'w' :
976 $letter eq 'v' ? 'g' :
977 $letter eq 'y' ? 'z' : $letter;
978 0 push @sf, [ $letter => $value ];
979 }
980 0 ▶ my $ind1 = $field->ind2 =~ /0/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$field->ind2 =~ /0/ ? : 0 0 0
981 0 $record->append( MARC::Moose::Field::Std->new(
982 tag => $to, ind1 => $ind1, ind2 =>$ind2, subf => \@sf ) );
983 }
984 }
985  
986 # 500 => 240 or 130
987 0 for my $field ( $unimarc->field('500|503|517|540|541') ) {
988 0 my ($ind1, $ind2) = ($field->ind1, $field->ind2);
989 0 my $tag = '240';
990 0 ▶ if ( $ind2 eq '0' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ind2 eq '0') { } 0 0 0
elsif ($ind2 eq '1') { } 0 0 0
991 0 $ind2 = 0;
992 }
993 elsif ( $ind2 eq '1' ) {
994 0 $tag = '130';
995 0 ($ind1, $ind2) = (0, ' ');
996 }
997 else {
998 0 ($ind1, $ind2) = (1, 0);
999 }
1000 0 $record->append( MARC::Moose::Field::Std->new(
1001 tag => $tag, ind1 => $ind1, ind2 => $ind2,
1002 subf => $self->procedure_title($field->subf) ) );
1003 }
1004  
1005 # 545 => 773, on passe t en a
1006 0 for my $field ( $unimarc->field('545') ) {
1007 0 $field->tag('773');
1008 0 ▶ $field->subf( [ grep { $_->[0] = 't' if $_->[0] eq 'a'; $_ } @{$field->subf} ] );
Branch: 1 branch
BranchTrueFalseTotal
if $_->[0] eq "a" 0 0 0
1009 0 $record->append( $field );
1010 }
1011  
1012 # 600 => 600
1013 # Suppr 6 et 7. f => d
1014 0 for my $field ( $unimarc->field('600') ) {
1015 0 my @names;
1016 my $date;
1017 # Skip $6 and $7
1018 0 my @sf;
1019 0 my $date_available = 0;
1020 SUBFIELD600:
1021 0 for ( @{$field->subf} ) {
1022 0 my ($letter, $value) = @$_;
1023 0 $value =~ s/^ *//; $value =~ s/ *$//;
1024 0 ▶ next unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
1025 0 for ($letter) {
1026 0 ▶ if ( /6|7/ ) { next SUBFIELD600; }
Branch: 5 branches
BranchTrueFalseTotal
if (/6|7/) { } 0 0 0
elsif (/a|b/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/y/) { } 0 0 0
elsif (/z/) { } 0 0 0
1027 0 elsif ( /a|b/ ) { push @names, $value; next; }
1028 0 elsif ( /f/ ) { $date_available = 1; $letter = 'd'; }
1029 0 elsif ( /y/ ) { $letter = 'z'; }
1030 0 elsif ( /z/ ) { $letter = 'y'; }
1031 0 push @sf, [ $letter => $value ];
1032 }
1033 }
1034 0 my @sf_complete;
1035 0 my $notpushed = 1;
1036 0 for (@sf) {
1037 0 my ($letter, $value) = @$_;
1038 0 ▶ if ($letter gt 'a' && $notpushed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($letter gt "a" and $notpushed) 0 0 0
Condition0%0/3
$letter gt "a" and $notpushed
!ll&&!rl&&r
000
MC/DC0%0/2
$letter gt "a" and $notpushed
$letter gt "a" $notpushed
Truth table0%0/3
A and B
A= $letter gt "a"B= $notpushed
ABresult
0X0
100
111
1039 0 ▶ push @sf_complete, [ a => join(', ', @names) . ($date_available ? ',' : '') ];
Branch: 1 branch
BranchTrueFalseTotal
$date_available ? : 0 0 0
1040 0 $notpushed = 0;
1041 }
1042 0 push @sf_complete, $_;
1043 }
1044 0 $record->append( MARC::Moose::Field::Std->new(
1045 tag => '600', subf => \@sf_complete ) );
1046 }
1047  
1048 # 605 => 630 - 606 => 650 - 607 => 651 - 608 => 650
1049 # On conserve à leur place les lettres a x j (subdivision de forme)
1050 # On inverse y et z. et déplacée en v.
1051 # On suppr les $3
1052 0 for my $fromto ( ( [601, 650], [604, 600], [605, 630], [606, 650], [607, 651], [608, 650] ) ) {
1053 0 my ($from, $to) = @$fromto;
1054 0 for my $field ( $unimarc->field($from) ) {
1055 0 my @sf;
1056 0 for ( @{$field->subf} ) {
1057 0 my ($letter, $value) = @$_;
1058 0 $value =~ s/^ *//, $value =~ s/ *$//;
1059 0 ▶ next if $letter =~ /3/;
Branch: 1 branch
BranchTrueFalseTotal
if $letter =~ /3/ 0 0 0
1060 0 ▶ if ( $letter eq 'j' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($letter eq 'j') { } 0 0 0
elsif ($letter eq 'y') { } 0 0 0
elsif ($letter eq 'z') { } 0 0 0
1061 0 $letter = 'v';
1062 }
1063 elsif ( $letter eq 'y' ) {
1064 0 $letter = 'z';
1065 }
1066 elsif ( $letter eq 'z' ) {
1067 0 $letter = 'y';
1068 }
1069 0 push @sf, [ $letter => $value ];
1070 }
1071 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
1072 0 ▶ $sf[-1][1] = $sf[-1][1] . '.' if $sf[-1][1] !~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sf[-1][1] =~ /\.$/ 0 0 0
1073 0 $record->append( MARC::Moose::Field::Std->new(
1074 tag => $to, subf => \@sf ) );
1075 }
1076 }
1077  
1078 # 675 => 080, $v and $z aren't converted
1079 0 for my $field ( $unimarc->field('675') ) {
1080 0 my @sf = grep { $_->[0] !~ /v|z/; } @{$field->subf};
1081 0 $record->append( MARC::Moose::Field::Std->new(
1082 tag => '080', subf => \@sf ) );
1083 }
1084  
1085 # 676 => 082, $v => $2
1086 0 for my $field ( $unimarc->field('676') ) {
1087 0 ▶ my @sf = map { $_->[0] = '2' if $_->[0] eq 'v'; $_; } @{$field->subf};
Branch: 1 branch
BranchTrueFalseTotal
if $_->[0] eq "v" 0 0 0
1088 0 $record->append( MARC::Moose::Field::Std->new(
1089 tag => '082', subf => \@sf ) );
1090 }
1091  
1092 # Les auteurs 700 => 100,
1093 # Suppr sous $3, $6 et $7 $9
1094 0 for my $fromto ( ( [700, 100], [701, 700], [702, 700] ) ) {
1095 0 my ($from, $to) = @$fromto;
1096 0 for my $field ( $unimarc->field($from) ) {
1097 0 my $ind1 = $field->ind2;
1098 0 my @sf;
1099 my @codes;
1100 0 for ( @{$field->subf} ) {
1101 0 my ($letter, $value) = @$_;
1102 0 for ($letter) {
1103 0 ▶ if ( /a/ ) {
Branch: 7 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/c/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/g/) { } 0 0 0
elsif (/4/) { } 0 0 0
1104 0 push @sf, [ a => $value ];
1105 }
1106 elsif ( /b/ ) {
1107 0 ▶ if ( @sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) { } 0 0 0
1108 0 $sf[-1]->[1] .= ", $value";
1109 }
1110 else {
1111 0 push @sf, [ a => $value ];
1112 }
1113 }
1114 elsif ( /c/ ) {
1115 0 $sf[-1]->[1] .= ',';
1116 0 push @sf, [ c => $value ];
1117 }
1118 elsif ( /d/ ) {
1119 0 push @sf, [ b => $value ];
1120 }
1121 elsif ( /f/ ) {
1122 0 ▶ $sf[-1]->[1] .= ',' if @sf;
Branch: 1 branch
BranchTrueFalseTotal
if @sf 0 0 0
1123 0 push @sf, [ d => $value ];
1124 }
1125 elsif ( /g/ ) {
1126 0 $sf[-1]->[1] .= '(';
1127 0 push @sf, [ q => "$value)" ];
1128 }
1129 elsif ( /4/ ) {
1130 0 ▶ next if $from eq '700' && $value eq '070';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq 700 and $value eq "070" 0 0 0
Condition0%0/3
$from eq 700 and $value eq "070"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq 700 and $value eq "070"
$from eq 700 $value eq "070"
Truth table0%0/3
A and B
A= $from eq 700B= $value eq "070"
ABresult
0X0
100
111
1131 0 my $code = $authcode{$value};
1132 0 ▶ next unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
1133 0 push @codes, $code->[0];
1134 }
1135 }
1136 }
1137 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
1138 0 my $value = $sf[-1]->[1];
1139 0 $value =~ s/ *$//;
1140 0 $value =~ s/\.*$//;
1141 0 ▶ $value .= '.' if $value !~ /[-\?]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /[-\?]$/ 0 0 0
1142 0 $sf[-1]->[1] = $value;
1143 0 push @sf, [ 4 => $_ ] for @codes;
1144 0 $record->append( MARC::Moose::Field::Std->new(
1145 tag => $to, ind1 => $field->ind2, subf => \@sf ) );
1146 }
1147 }
1148  
1149 # Les collectivités
1150 # Suppr sous $3, $6 et $7 $9
1151 SUBFIELD_CORPORATE:
1152 0 for my $fromto ( ( [710, 110, 111], [711, 710, 711], [712, 710, 711] ) ) {
1153 0 my ($from, $to_corporate, $to_meeting) = @$fromto;
1154 0 for my $field ( $unimarc->field($from) ) {
1155 0 my @sf;
1156 my @codes;
1157 0 for ( @{$field->subf} ) {
1158 0 my ($letter, $value) = @$_;
1159 0 for ($letter) {
1160 0 ▶ if ( /a/ ) {
Branch: 9 branches
BranchTrueFalseTotal
if (/a/) { } 0 0 0
elsif (/g/) { } 0 0 0
elsif (/h/) { } 0 0 0
elsif (/g/) { } 0 0 0
elsif (/b/) { } 0 0 0
elsif (/d/) { } 0 0 0
elsif (/e/) { } 0 0 0
elsif (/f/) { } 0 0 0
elsif (/4/) { } 0 0 0
1161 0 push @sf, [ a => $value ];
1162 }
1163 elsif ( /g/ ) {
1164 0 ▶ $value = "($value)" unless $value =~ /^\(/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\(/ 0 0 0
1165 0 ▶ $sf[-1]->[1] .= " $value" if @sf;
Branch: 1 branch
BranchTrueFalseTotal
if @sf 0 0 0
1166 }
1167 elsif ( /h/ ) {
1168 0 $sf[-1]->[1] .= " $value";
1169 }
1170 elsif ( /g/ ) {
1171 0 $sf[-1]->[1] .= " ($value)";
1172 }
1173 elsif ( /b/ ) {
1174 0 ▶ if ( @sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sf) 0 0 0
1175 0 ▶ $sf[-1]->[1] .= '.' unless $sf[-1]->[1] =~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sf[-1][1] =~ /\.$/ 0 0 0
1176 }
1177 0 push @sf, [ b => $value ];
1178 }
1179 elsif ( /d/ ) {
1180 0 ▶ $value = "($value" unless $value =~ /^\(/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\(/ 0 0 0
1181 0 push @sf, [ n => $value ];
1182 }
1183 elsif ( /e/ ) {
1184 0 $value = " :$value)";
1185 0 push @sf, [ c => $value ];
1186 }
1187 elsif ( /f/ ) {
1188 0 ▶ $value = $sf[-1]->[0] eq 'n'
Branch: 2 branches
BranchTrueFalseTotal
if @sf 0 0 0
$sf[-1][0] eq 'n' ? : 0 0 0
1189 ? " :$value"
1190 : "($value" if @sf;
1191 0 push @sf, [ d => $value ];
1192 }
1193 elsif ( /4/ ) {
1194 0 ▶ next SUBFIELD_CORPORATE if $from eq '700' && $value eq '070';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq 700 and $value eq "070" 0 0 0
Condition0%0/3
$from eq 700 and $value eq "070"
!ll&&!rl&&r
000
MC/DC0%0/2
$from eq 700 and $value eq "070"
$from eq 700 $value eq "070"
Truth table0%0/3
A and B
A= $from eq 700B= $value eq "070"
ABresult
0X0
100
111
1195 0 my $code = $authcode{$value};
1196 0 ▶ next SUBFIELD_CORPORATE unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
1197 0 push @codes, $code->[0];
1198 }
1199 }
1200 }
1201 0 ▶ next unless @sf;
Branch: 1 branch
BranchTrueFalseTotal
unless @sf 0 0 0
1202 0 my $value = $sf[-1]->[1];
1203 0 $value =~ s/ *$//;
1204 0 $value =~ s/\.*$//;
1205 0 $value .= '.';
1206 0 $sf[-1]->[1] = $value;
1207 0 push @sf, [ 4 => $_ ] for @codes;
1208 0 ▶ my $to = $field->ind1 eq '1' ? $to_meeting : $to_corporate;
Branch: 1 branch
BranchTrueFalseTotal
$field->ind1 eq '1' ? : 0 0 0
1209 0 $record->append( MARC::Moose::Field::Std->new(
1210 tag => $to, ind1 => $field->ind2, subf => \@sf ) );
1211 }
1212 }
1213  
1214 # Populate non-filing indicator based on UNIMARC NSB/NSE
1215 {
1216 0 my $first = 1;
1217 0 for my $tags (@$nonfiling_tags) {
1218 0 for my $tag (@$tags) {
1219 0 for my $field ($record->field($tag)) {
1220 0 for (@{$field->subf}) {
1221 0 ▶ next if $_->[0] ne 'a';
Branch: 1 branch
BranchTrueFalseTotal
if $_->[0] ne "a" 0 0 0
1222 # Found Main title
1223 0 my $title = $_->[1];
1224 0 ▶ next unless $title;
Branch: 1 branch
BranchTrueFalseTotal
unless $title 0 0 0
1225 0 for my $ns (@$ns_characters) {
1226 0 my ($nsb, $nse) = @$ns;
1227 0 ▶ next if $title !~ /^$nsb(.*)$nse(.)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $title =~ /^$nsb(.*)$nse(.)/ 0 0 0
1228 0 my $len = length($1);
1229 0 ▶ $len++ if $2 eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq " " 0 0 0
1230 0 ▶ $len = 0 if $len >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $len >= 10 0 0 0
1231 0 $title =~ s/$nsb//g;
1232 0 $title =~ s/$nse//g;
1233 0 $_->[1] = $title;
1234 0 ▶ if ($first) { $field->ind1($len); }
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 0 0 0
1235 0 else { $field->ind2($len); }
1236 0 last;
1237 }
1238 0 last;
1239 }
1240 }
1241 }
1242 0 $first = 0;
1243 }
1244 }
1245  
1246 # Some fields are kept, as they are: 856, 801, 9xx
1247 0 ▶ if ( my @fields = $unimarc->field('801|856|9..') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@fields) = $unimarc->field("801|856|9..")) 0 0 0
1248 0 $record->append(@fields)
1249 }
1250  
1251 # Clean non-filing characters in all fields
1252 0 for my $field (@{$record->fields}) {
1253 0 ▶ next if ref $field eq 'MARC::Moose::Field::Control';
Branch: 1 branch
BranchTrueFalseTotal
if ref $field eq "MARC::Moose::Field::Control" 0 0 0
1254 0 for (@{$field->subf} ) {
1255 0 ▶ next if $_->[0] !~ /[a-z0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->[0] =~ /[a-z0-9]/ 0 0 0
1256 0 $_->[1] =~ s/\x08|\x09//g;
1257 }
1258 }
1259  
1260 0 return $record;
1261 4 };
1262  
1263 4 __PACKAGE__->meta->make_immutable;
1264  
1265 4 1;
1266  
1267 __END__
1268  
1269 =pod
1270  
1271 =encoding UTF-8
1272  
1273 =head1 NAME
1274  
1275 MARC::Moose::Formater::UnimarcToMarc21 - Convert biblio record from UNIMARC to MARC21
1276  
1277 =head1 VERSION
1278  
1279 version 1.0.46
1280  
1281 =head1 SYNOPSYS
1282  
1283 Read a UNIMARC ISO2709 file and dump it to STDOUT in text transformed into
1284 MARC21:
1285  
1286 my $reader = MARC::Moose::Reader::File::Iso2709->new(
1287 file => 'biblio-unimarc.iso' );
1288 my $formater = MARC::Moose::Formater::UnimarcToMarc21->new();
1289 while ( my $unimarc = $reader->read() ) {
1290 my $marc21 = $formater->format($unimarc);
1291 print $marc21->as('Text');
1292 }
1293  
1294 Same with shortcut:
1295  
1296 my $reader = MARC::Moose::Reader::File::Iso2709->new(
1297 file => 'biblio-unimarc.iso' );
1298 while ( my $unimarc = $reader->read() ) {
1299 print $unimarc->as('UnimarcToMarc21')->as('Text');
1300 }
1301  
1302 Read a UNIMARC ISO2709 file and dump it to another ISO2709 file transformed
1303 into MARC21:
1304  
1305 my $reader = MARC::Moose::Reader::File::Iso2709->new(
1306 file => 'biblio-unimarc.iso' );
1307 my $writer = MARC::Moose::Writer->new(
1308 fh => IO::File->new('koha.mrc', '>:encoding(utf8)'),
1309 formater => MARC::Moose::Formater::Iso2709->new() )
1310 );
1311 my $tomarc21 = MARC::Moose::Formater::UnimarcToMarc21->new();
1312 while ( my $unimarc = $reader->read() ) {
1313 $writer->write( $tomarc21->format($unimarc) );
1314 }
1315  
1316 =head1 COMMAND LINE
1317  
1318 If you don't want to write a Perl script, you can use the L<marcmoose> command.
1319 This way, you can for example convert a ISO 2709 UNIMARC file named
1320 C<unimarc.iso> into a ISO 2709 MARC21 file named C<marc.iso>:
1321  
1322 marcmoose --parser iso2709 --formater iso2709 --converter unimarctomarc21
1323 --output marc.iso unimarc.iso
1324  
1325 =head1 AUTHOR
1326  
1327 Frédéric Demians <f.demians@tamil.fr>
1328  
1329 =head1 COPYRIGHT AND LICENSE
1330  
1331 This software is copyright (c) 2022 by Frédéric Demians.
1332  
1333 This is free software; you can redistribute it and/or modify it under
1334 the same terms as the Perl 5 programming language system itself.
1335  
1336 =cut
↑ Summary Moose/Lint/Checker/RulesFile.pm »