7 |
BEGIN { |
BEGIN { |
8 |
use Exporter (); |
use Exporter (); |
9 |
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
10 |
$VERSION = 0.09; |
$VERSION = 0.10; |
11 |
@ISA = qw (Exporter); |
@ISA = qw (Exporter); |
12 |
#Give a hoot don't pollute, do not export more than needed by default |
#Give a hoot don't pollute, do not export more than needed by default |
13 |
@EXPORT = qw (); |
@EXPORT = qw (); |
87 |
my $len = read($self->{fh}, $leader, 24); |
my $len = read($self->{fh}, $leader, 24); |
88 |
|
|
89 |
if ($len < 24) { |
if ($len < 24) { |
90 |
carp "short read of leader, aborting\n"; |
warn "short read of leader, aborting\n"; |
91 |
|
$self->{count}--; |
92 |
last; |
last; |
93 |
} |
} |
94 |
|
|
311 |
|
|
312 |
my $row = $self->fetch($mfn) || return; |
my $row = $self->fetch($mfn) || return; |
313 |
|
|
314 |
foreach my $rec_nr (keys %{$row}) { |
foreach my $tag (keys %{$row}) { |
315 |
foreach my $l (@{$row->{$rec_nr}}) { |
foreach my $l (@{$row->{$tag}}) { |
316 |
|
|
317 |
# remove end marker |
# remove end marker |
318 |
$l =~ s/\x1E$//; |
$l =~ s/\x1E$//; |
319 |
|
|
320 |
# filter output |
# filter output |
321 |
$l = $self->{'hash_filter'}->($l, $rec_nr) if ($self->{'hash_filter'}); |
$l = $self->{'hash_filter'}->($l, $tag) if ($self->{'hash_filter'}); |
322 |
|
|
323 |
my $val; |
my $val; |
324 |
|
|
351 |
$val = $l; |
$val = $l; |
352 |
} |
} |
353 |
|
|
354 |
push @{$rec->{$rec_nr}}, $val; |
push @{$rec->{$tag}}, $val; |
355 |
} |
} |
356 |
} |
} |
357 |
|
|
385 |
1; |
1; |
386 |
__END__ |
__END__ |
387 |
|
|
388 |
|
=head1 UTF-8 ENCODING |
389 |
|
|
390 |
|
This module does nothing with encoding. But, since MARC format is byte |
391 |
|
oriented even when using UTF-8 which has variable number of bytes for each |
392 |
|
character, file is opened in binary mode. |
393 |
|
|
394 |
|
As a result, all scalars recturned to perl don't have utf-8 flag. Solution is |
395 |
|
to use C<hash_filter> and L<Encode> to decode utf-8 encoding like this: |
396 |
|
|
397 |
|
use Encode; |
398 |
|
|
399 |
|
my $marc = new MARC::Fast( |
400 |
|
marcdb => 'utf8.marc', |
401 |
|
hash_filter => sub { |
402 |
|
Encode::decode( 'utf-8', $_[0] ); |
403 |
|
}, |
404 |
|
); |
405 |
|
|
406 |
|
This will affect C<to_hash>, but C<fetch> will still return binary representation |
407 |
|
since it doesn't support C<hash_filter>. |
408 |
|
|
409 |
=head1 AUTHOR |
=head1 AUTHOR |
410 |
|
|
411 |
Dobrica Pavlinusic |
Dobrica Pavlinusic |