--- trunk/lib/WebPAC/Input.pm 2006/05/15 13:15:01 507 +++ trunk/lib/WebPAC/Input.pm 2006/07/05 19:52:45 585 @@ -16,11 +16,11 @@ =head1 VERSION -Version 0.05 +Version 0.07 =cut -our $VERSION = '0.05'; +our $VERSION = '0.07'; =head1 SYNOPSIS @@ -44,7 +44,6 @@ my $db = WebPAC::Input->new( module => 'WebPAC::Input::ISIS', config => $config, - lookup => $lookup_obj, low_mem => 1, ); @@ -64,7 +63,7 @@ my $db = new WebPAC::Input( module => 'WebPAC::Input::MARC', - code_page => 'ISO-8859-2', + encoding => 'ISO-8859-2', low_mem => 1, recode => 'char pairs', no_progress_bar => 1, @@ -73,7 +72,7 @@ C is low-level file format module. See L and L. -Optional parametar C specify application code page (which will be +Optional parametar C specify application code page (which will be used internally). This should probably be your terminal encoding, and by default, it C. @@ -96,6 +95,9 @@ my $log = $self->_get_logger; + $log->logconfess("code_page argument is not suppored any more. change it to encoding") if ($self->{lookup}); + $log->logconfess("lookup argument is not suppored any more. rewrite call to lookup_ref") if ($self->{lookup}); + $log->logconfess("specify low-level file format module") unless ($self->{module}); my $module = $self->{module}; $module =~ s#::#/#g; @@ -121,7 +123,7 @@ $self->{init}->($self, @_); } - $self->{'code_page'} ||= 'ISO-8859-2'; + $self->{'encoding'} ||= 'ISO-8859-2'; # running with low_mem flag? well, use DBM::Deep then. if ($self->{'low_mem'}) { @@ -163,6 +165,10 @@ offset => 6000, lookup => $lookup_obj, stats => 1, + lookup_ref => sub { + my ($k,$v) = @_; + # store lookup $k => $v + }, ); By default, C is assumed to be C<852>. @@ -173,6 +179,9 @@ C create optional report about usage of fields and subfields +C is closure to call when adding key => $value combinations to +lookup. + Returns size of database, regardless of C and C parametars, see also C. @@ -184,6 +193,10 @@ my $log = $self->_get_logger(); + $log->logconfess("lookup argument is not suppored any more. rewrite call to lookup_coderef") if ($arg->{lookup}); + $log->logconfess("lookup_coderef must be CODE, not ",ref($arg->{lookup_coderef})) + if ($arg->{lookup_coderef} && ref($arg->{lookup_coderef}) ne 'CODE'); + $log->logcroak("need path") if (! $arg->{'path'}); my $code_page = $arg->{'code_page'} || '852'; @@ -194,7 +207,7 @@ } # create Text::Iconv object - $self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'}); + $self->{iconv} = Text::Iconv->new($code_page,$self->{'encoding'}); ## FIXME remove! my $filter_ref; @@ -227,6 +240,7 @@ my ($db, $size) = $self->{open_db}->( $self, path => $arg->{path}, filter => $filter_ref, + %{ $arg }, ); unless (defined($db)) { @@ -243,7 +257,7 @@ my $to_rec = $size; if (my $s = $self->{offset}) { - $log->info("skipping to MFN $s"); + $log->debug("skipping to MFN $s"); $from_rec = $s; } else { $self->{offset} = $from_rec; @@ -258,7 +272,7 @@ # store size for later $self->{size} = ($to_rec - $from_rec) ? ($to_rec - $from_rec + 1) : 0; - $log->info("processing $self->{size}/$size records [$from_rec-$to_rec] convert $code_page -> $self->{code_page}", $self->{stats} ? ' [stats]' : ''); + $log->info("processing $self->{size}/$size records [$from_rec-$to_rec] convert $code_page -> $self->{encoding}", $self->{stats} ? ' [stats]' : ''); # read database for (my $pos = $from_rec; $pos <= $to_rec; $pos++) { @@ -282,7 +296,7 @@ } # create lookup - $self->{'lookup'}->add( $rec ) if ($rec && $self->{'lookup'}); + $arg->{'lookup_coderef'}->( $rec ) if ($rec && $arg->{'lookup_coderef'}); # update counters for statistics if ($self->{stats}) { @@ -451,7 +465,7 @@ my $v = $s->{fld}->{$f} || die "no s->{fld}->{$f}"; $max_fld = $v if ($v > $max_fld); - my $o = sprintf("%4d %d ~", $f, $v); + my $o = sprintf("%4s %d ~", $f, $v); if (defined($s->{sf}->{$f})) { map { @@ -464,7 +478,7 @@ } $o; - } sort { $a <=> $b } keys %{ $s->{fld} } + } sort { $a cmp $b } keys %{ $s->{fld} } ); $log->debug( sub { Dumper($s) } );