line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
package MARC::Utils::MARC2Pairs; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
48571
|
use 5.008002; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
181
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our (@ISA, @EXPORT_OK); |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
13
|
require Exporter; |
13
|
1
|
|
|
|
|
25
|
@ISA = qw(Exporter); |
14
|
1
|
|
|
|
|
22
|
@EXPORT_OK = qw( marc2pairs pairs2marc ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1168
|
use MARC::Record; |
|
1
|
|
|
|
|
46250
|
|
|
1
|
|
|
|
|
63
|
|
18
|
1
|
|
|
1
|
|
1305
|
use Data::Pairs qw( pairs_add pairs_get_array ); |
|
1
|
|
|
|
|
2997
|
|
|
1
|
|
|
|
|
520
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
sub marc2pairs { |
22
|
1
|
|
|
1
|
0
|
1412
|
my( $marc_record ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
my $pairs = []; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
6
|
for my $leader ( $marc_record->leader() ) { |
27
|
1
|
|
|
|
|
17
|
pairs_add( $pairs, leader => $leader ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
26
|
for my $field ( $marc_record->fields() ) { |
31
|
|
|
|
|
|
|
|
32
|
27
|
|
|
|
|
514
|
my $ftag = $field->tag(); |
33
|
|
|
|
|
|
|
|
34
|
27
|
100
|
|
|
|
146
|
if( $field->is_control_field() ) { |
35
|
4
|
|
|
|
|
25
|
pairs_add( $pairs, $ftag => $field->data() ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
else { |
39
|
23
|
|
|
|
|
96
|
my $subpairs = []; |
40
|
|
|
|
|
|
|
|
41
|
23
|
|
|
|
|
39
|
for my $i ( 1, 2 ) { |
42
|
46
|
|
|
|
|
977
|
pairs_add( $subpairs, "ind$i" => $field->indicator( $i ) ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
23
|
|
|
|
|
729
|
for my $subfield ( $field->subfields ) { |
46
|
44
|
|
|
|
|
971
|
pairs_add( $subpairs, $subfield->[0] => $subfield->[1] ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
23
|
|
|
|
|
501
|
pairs_add( $pairs, $ftag => $subpairs ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
17
|
$pairs; # returned |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
57
|
|
|
|
|
|
|
sub pairs2marc { |
58
|
2
|
|
|
2
|
0
|
53
|
my( $pairs ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
19
|
my $marc_record = MARC::Record->new(); |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
34
|
for my $field ( pairs_get_array( $pairs ) ) { |
63
|
|
|
|
|
|
|
|
64
|
56
|
|
|
|
|
3515
|
my( $ftag, $fdata ) = %$field; |
65
|
|
|
|
|
|
|
|
66
|
56
|
100
|
|
|
|
161
|
if( $ftag eq 'leader' ) { |
|
|
100
|
|
|
|
|
|
67
|
2
|
|
|
|
|
12
|
$marc_record->leader( $fdata ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
elsif( ref $fdata ) { |
71
|
46
|
|
|
|
|
45
|
my( $ind1, $ind2, @subfields ); |
72
|
|
|
|
|
|
|
|
73
|
46
|
|
|
|
|
115
|
for my $subfield ( pairs_get_array( $fdata ) ) { |
74
|
180
|
|
|
|
|
2901
|
my( $sftag, $sfdata ) = %$subfield; |
75
|
180
|
100
|
|
|
|
4774
|
if( $sftag eq 'ind1' ) { $ind1 = $sfdata } |
|
46
|
100
|
|
|
|
97
|
|
76
|
46
|
|
|
|
|
176
|
elsif( $sftag eq 'ind2' ) { $ind2 = $sfdata } |
77
|
88
|
|
|
|
|
230
|
else { push @subfields, $sftag, $sfdata } |
78
|
|
|
|
|
|
|
} |
79
|
46
|
|
|
|
|
284
|
$marc_record->append_fields( MARC::Field->new( |
80
|
|
|
|
|
|
|
$ftag, $ind1, $ind2, @subfields ) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# control field |
84
|
|
|
|
|
|
|
else { |
85
|
8
|
|
|
|
|
32
|
$marc_record->append_fields( MARC::Field->new( $ftag, $fdata ) ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
166
|
$marc_record; #returned |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |