--- trunk/lib/WebPAC/Input.pm 2005/12/31 16:50:11 339 +++ trunk/lib/WebPAC/Input.pm 2006/05/14 19:45:26 496 @@ -14,11 +14,11 @@ =head1 VERSION -Version 0.03 +Version 0.04 =cut -our $VERSION = '0.03'; +our $VERSION = '0.04'; =head1 SYNOPSIS @@ -47,9 +47,10 @@ ); $db->open('/path/to/database'); - print "database size: ",$db->size,"\n"; - while (my $rec = $db->fetch) { - } + print "database size: ",$db->size,"\n"; + while (my $rec = $db->fetch) { + # do something with $rec + } @@ -63,6 +64,8 @@ module => 'WebPAC::Input::MARC', code_page => 'ISO-8859-2', low_mem => 1, + recode => 'char pairs', + no_progress_bar => 1, ); C is low-level file format module. See L and @@ -74,6 +77,11 @@ Default is not to use C options (see L below). +C is optional string constisting of character or words pairs that +should be replaced in input stream. + +C disables progress bar output on C + This function will also call low-level C if it exists with same parametars. @@ -183,11 +191,40 @@ # create Text::Iconv object $self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'}); + my $filter_ref; + + if ($self->{recode}) { + my @r = split(/\s/, $self->{recode}); + if ($#r % 2 != 1) { + $log->logwarn("recode needs even number of elements (some number of valid pairs)"); + } else { + my $recode; + while (@r) { + my $from = shift @r; + my $to = shift @r; + $recode->{$from} = $to; + } + + my $regex = join '|' => keys %{ $recode }; + + $log->debug("using recode regex: $regex"); + + $filter_ref = sub { + my $t = shift; + $t =~ s/($regex)/$recode->{$1}/g; + return $t; + }; + + } + + } + my ($db, $size) = $self->{open_db}->( $self, path => $arg->{path}, + filter => $filter_ref, ); - unless ($db) { + unless (defined($db)) { $log->logwarn("can't open database $arg->{path}, skipping..."); return; } @@ -242,7 +279,7 @@ # create lookup $self->{'lookup'}->add( $rec ) if ($rec && $self->{'lookup'}); - $self->progress_bar($pos,$to_rec); + $self->progress_bar($pos,$to_rec) unless ($self->{no_progress_bar}); } @@ -288,7 +325,7 @@ return; } - $self->progress_bar($mfn,$self->{max_pos}); + $self->progress_bar($mfn,$self->{max_pos}) unless ($self->{no_progress_bar}); my $rec;