line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
package MARC::Utils::MARC2Ini; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
36200
|
use 5.008002; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
97
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our (@ISA, @EXPORT_OK); |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
5
|
require Exporter; |
13
|
1
|
|
|
|
|
23
|
@ISA = qw(Exporter); |
14
|
1
|
|
|
|
|
25
|
@EXPORT_OK = qw( marc2ini ini2marc ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use constant equals => ' = ' ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
18
|
1
|
|
|
1
|
|
4
|
use constant blank_line => '' ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
19
|
1
|
|
|
1
|
|
4
|
use constant null_section => '_' ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
1370
|
use MARC::Record; |
|
1
|
|
|
|
|
11748
|
|
|
1
|
|
|
|
|
966
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub quote { |
24
|
95
|
|
|
95
|
0
|
454
|
my( $data ) = @_; |
25
|
95
|
100
|
66
|
|
|
121
|
for( $data ) { return "'$_'" if /^ / or / $/ } # dumb quotes |
|
95
|
|
|
|
|
470
|
|
26
|
62
|
|
|
|
|
213
|
$data; # returned |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
30
|
|
|
|
|
|
|
sub marc2ini { |
31
|
1
|
|
|
1
|
0
|
972
|
my( $marc_record ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my @ini; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
5
|
for my $leader ( $marc_record->leader() ) { |
36
|
1
|
|
|
|
|
9
|
push @ini, join equals, leader => quote $leader; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
5
|
for my $field ( $marc_record->fields() ) { |
40
|
|
|
|
|
|
|
|
41
|
27
|
|
|
|
|
79
|
my $ftag = $field->tag(); |
42
|
|
|
|
|
|
|
|
43
|
27
|
100
|
|
|
|
130
|
if( $field->is_control_field() ) { |
44
|
4
|
|
|
|
|
23
|
push @ini, join equals, $ftag => quote $field->data(); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
else { |
48
|
23
|
|
|
|
|
104
|
push @ini, blank_line, "[$ftag]"; |
49
|
|
|
|
|
|
|
|
50
|
23
|
|
|
|
|
50
|
for my $i ( 1, 2 ) { |
51
|
46
|
|
|
|
|
111
|
push @ini, join equals, "ind$i" => quote $field->indicator( $i ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
23
|
|
|
|
|
57
|
for my $subfield ( $field->subfields ) { |
55
|
44
|
|
|
|
|
391
|
push @ini, join equals, $subfield->[0] => quote $subfield->[1]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
37
|
join( "\n" => @ini ) . "\n"; # returned |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
64
|
|
|
|
|
|
|
sub ini2marc { |
65
|
2
|
|
|
2
|
0
|
18
|
my( $ini_string ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
16
|
my $marc_record = MARC::Record->new(); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
1
|
|
9
|
open my $fh, '<', \$ini_string; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
60
|
|
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
1451
|
my $section = null_section; |
72
|
2
|
|
|
|
|
5
|
my( $tag, $data, @field ); |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
4
|
local *_; |
75
|
2
|
|
|
|
|
12
|
while( <$fh> ) { |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# comment or blank line |
78
|
283
|
100
|
66
|
|
|
2119
|
if( /^\s*[#;]/ or /^\s*$/ ) { next } |
|
47
|
|
|
|
|
135
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# [section] |
81
|
236
|
100
|
|
|
|
559
|
if( /^\[([^\]]*)\]/ ) { |
82
|
46
|
|
|
|
|
66
|
$section = $1; |
83
|
46
|
100
|
|
|
|
192
|
$marc_record->append_fields( MARC::Field->new( @field ) ) if @field; |
84
|
46
|
|
|
|
|
2939
|
@field = $section; |
85
|
46
|
|
|
|
|
158
|
next; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# tag = data (tag="data" tag='data') |
89
|
190
|
50
|
|
|
|
1326
|
if( /^\s*([^=:]+?)\s*[=:]\s*(.*)$/ ) { |
90
|
190
|
|
|
|
|
382
|
$tag = $1; |
91
|
190
|
|
|
|
|
260
|
$data = $2; |
92
|
190
|
100
|
|
|
|
577
|
$data = $2 if $data =~ /^(['"])(.*)\1$/; # dumb quotes |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# control fields |
96
|
190
|
100
|
|
|
|
317
|
if( $section eq null_section ) { |
97
|
10
|
100
|
|
|
|
18
|
if( $tag eq 'leader' ) { $marc_record->leader( $data ) } |
|
2
|
|
|
|
|
7
|
|
98
|
8
|
|
|
|
|
28
|
else { $marc_record->append_fields( MARC::Field->new( $tag, $data ) ) } |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
else { |
102
|
180
|
100
|
|
|
|
367
|
if( $tag =~ /^ind[12]$/ ) { push @field, $data } |
|
92
|
|
|
|
|
330
|
|
103
|
88
|
|
|
|
|
347
|
else { push @field, $tag, $data } |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
2
|
50
|
|
|
|
11
|
$marc_record->append_fields( MARC::Field->new( @field ) ) if @field; |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
111
|
$marc_record; #returned |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |