18 |
|
|
19 |
=head1 VERSION |
=head1 VERSION |
20 |
|
|
21 |
Version 0.02 |
Version 0.03 |
22 |
|
|
23 |
=cut |
=cut |
24 |
|
|
25 |
our $VERSION = '0.02'; |
our $VERSION = '0.03'; |
26 |
|
|
27 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
28 |
|
|
34 |
# same with 101 |
# same with 101 |
35 |
101 |
101 |
36 |
# field 200 have valid subfields a-g |
# field 200 have valid subfields a-g |
37 |
200 a b c d e f g |
# and field e is repeatable |
38 |
|
200 a b c d e* f g |
39 |
# field 205 can have only subfield a |
# field 205 can have only subfield a |
40 |
205 a |
# and must exists |
41 |
|
205! a |
42 |
# while 210 can have a c or d |
# while 210 can have a c or d |
43 |
210 a c d |
210 a c d |
44 |
|
|
84 |
|
|
85 |
my $fld = shift @d; |
my $fld = shift @d; |
86 |
|
|
87 |
|
if ($fld =~ s/!$//) { |
88 |
|
$self->{must_exist}->{$fld}++; |
89 |
|
} |
90 |
|
|
91 |
$log->logdie("need field name in line $curr_line: $l") unless (defined($fld)); |
$log->logdie("need field name in line $curr_line: $l") unless (defined($fld)); |
92 |
|
|
93 |
if (@d) { |
if (@d) { |
129 |
|
|
130 |
$log->debug("rec = ", sub { Dumper($rec) }, "keys = ", keys %{ $rec }); |
$log->debug("rec = ", sub { Dumper($rec) }, "keys = ", keys %{ $rec }); |
131 |
|
|
132 |
|
my $fields; |
133 |
|
|
134 |
foreach my $f (keys %{ $rec }) { |
foreach my $f (keys %{ $rec }) { |
135 |
|
|
136 |
next if (!defined($f) || $f eq '' || $f eq '000'); |
next if (!defined($f) || $f eq '' || $f eq '000'); |
137 |
|
|
138 |
if (! defined($r->{$f})) { |
$fields->{$f}++; |
139 |
|
|
140 |
|
if ( ! defined($r->{$f}) ) { |
141 |
push @errors, "field '$f' shouldn't exists"; |
push @errors, "field '$f' shouldn't exists"; |
142 |
next; |
next; |
143 |
} |
} |
144 |
|
|
145 |
|
|
146 |
if (ref($rec->{$f}) ne 'ARRAY') { |
if (ref($rec->{$f}) ne 'ARRAY') { |
147 |
push @errors, "field '$f' isn't repetable, probably bug in parsing input data"; |
push @errors, "field '$f' isn't repetable, probably bug in parsing input data"; |
148 |
next; |
next; |
159 |
|
|
160 |
my $h = dclone( $v ); |
my $h = dclone( $v ); |
161 |
|
|
162 |
|
my $sf_repeatable; |
163 |
|
|
164 |
delete($v->{subfields}) if (defined($v->{subfields})); |
delete($v->{subfields}) if (defined($v->{subfields})); |
165 |
|
|
166 |
foreach my $sf (keys %{ $v }) { |
foreach my $sf (keys %{ $v }) { |
167 |
|
|
168 |
# permited subfield? |
# is non-repeatable but with multiple values? |
169 |
if (! first { $_ eq $sf } @{ $r->{$f} }) { |
if ( ! first { $_ eq $sf.'*' } @{$r->{$f}} ) { |
170 |
push @errors, "$f has unknown subfield: $sf"; |
if ( ref($v->{$sf}) eq 'ARRAY' ) { |
171 |
|
$sf_repeatable->{$sf}++; |
172 |
|
}; |
173 |
|
if (! first { $_ eq $sf } @{ $r->{$f} }) { |
174 |
|
push @errors, "$f has unknown subfield: $sf"; |
175 |
|
} |
176 |
} |
} |
177 |
|
|
178 |
# is repeatable? |
} |
179 |
if ( ref($v->{$sf}) eq 'ARRAY' ) { |
if (my @r_sf = sort keys( %$sf_repeatable )) { |
180 |
push @errors, "$f subfield $sf is repeatable: " . |
my $plural = $#r_sf > 0 ? 1 : 0; |
181 |
join('', _pack_subfields_hash( dclone($h), 1) ); |
|
182 |
### FIXME |
push @errors, "$f subfield" . |
183 |
} |
( $plural ? 's ' : ' ' ) . |
184 |
|
join(', ', @r_sf) . |
185 |
|
( $plural ? ' are ' : ' is ' ) . |
186 |
|
'repeatable in: ' . |
187 |
|
join('', _pack_subfields_hash( $h, 1) ); |
188 |
} |
} |
189 |
} |
} |
190 |
} elsif (ref($v) eq 'HASH') { |
} elsif (ref($v) eq 'HASH') { |
193 |
} |
} |
194 |
} |
} |
195 |
|
|
196 |
|
foreach my $must (sort keys %{ $self->{must_exist} }) { |
197 |
|
next if ($fields->{$must}); |
198 |
|
push @errors, |
199 |
|
"field $must should exist, but it doesn't"; |
200 |
|
} |
201 |
|
|
202 |
#$log->logcluck("return from this function is ARRAY") unless wantarray; |
#$log->logcluck("return from this function is ARRAY") unless wantarray; |
203 |
|
|
204 |
$log->debug("errors: ", join(", ", @errors)) if (@errors); |
$log->debug("errors: ", join(", ", @errors)) if (@errors); |