--- trunk/lib/WebPAC/Input.pm 2006/09/06 19:25:22 636 +++ trunk/lib/WebPAC/Input.pm 2006/09/25 15:26:12 707 @@ -16,11 +16,11 @@ =head1 VERSION -Version 0.12 +Version 0.13 =cut -our $VERSION = '0.12'; +our $VERSION = '0.13'; =head1 SYNOPSIS @@ -107,7 +107,7 @@ #eval $self->{module} .'->import'; # check if required subclasses are implemented - foreach my $subclass (qw/open_db fetch_rec init/) { + foreach my $subclass (qw/open_db fetch_rec init dump_rec/) { my $n = $self->{module} . '::' . $subclass; if (! defined &{ $n }) { my $missing = "missing $subclass in $self->{module}"; @@ -162,11 +162,10 @@ code_page => 'cp852', limit => 500, offset => 6000, - lookup => $lookup_obj, stats => 1, - lookup_ref => sub { - my ($k,$v) = @_; - # store lookup $k => $v + lookup_coderef => sub { + my $rec = shift; + # store lookups }, modify_records => { 900 => { '^a' => { ' : ' => '^b' } }, @@ -183,8 +182,7 @@ C create optional report about usage of fields and subfields -C is closure to call when adding C<< key => 'value' >> combinations to -lookup. +C is closure to called to save data into lookups C specify mapping from subfields to delimiters or from delimiters to subfields, as well as oprations on fields (if subfield is @@ -209,6 +207,8 @@ $log->logconfess("lookup_coderef must be CODE, not ",ref($arg->{lookup_coderef})) if ($arg->{lookup_coderef} && ref($arg->{lookup_coderef}) ne 'CODE'); + $log->debug( $arg->{lookup_coderef} ? '' : 'not ', "using lookup_coderef"); + $log->logcroak("need path") if (! $arg->{'path'}); my $code_page = $arg->{'code_page'} || 'cp852'; @@ -298,7 +298,7 @@ $log->debug("position: $pos\n"); - my $rec = $self->{fetch_rec}->($self, $db, $pos, sub { + my $rec = $self->{fetch_rec}->($self, $pos, sub { my ($l,$f_nr) = @_; # return unless defined($l); # return $l unless ($rec_regex && $f_nr); @@ -348,7 +348,7 @@ if ($self->{stats}) { # fetch clean record with regexpes applied for statistics - my $rec = $self->{fetch_rec}->($self, $db, $pos); + my $rec = $self->{fetch_rec}->($self, $pos); foreach my $fld (keys %{ $rec }) { $self->{_stats}->{fld}->{ $fld }++; @@ -546,6 +546,19 @@ return $out; } +=head2 dump + +Display humanly readable dump of record + +=cut + +sub dump { + my $self = shift; + + return $self->{dump_rec}->($self, $self->{pos}); + +} + =head2 modify_record_regexps Generate hash with regexpes to be applied using l. @@ -627,7 +640,7 @@ my $regexpes; - CORE::open(my $fh, $modify_path) || $log->die("can't open modify file $modify_path: $!"); + CORE::open(my $fh, $modify_path) || $log->logdie("can't open modify file $modify_path: $!"); my ($f,$sf);