--- trunk/lib/WebPAC/Normalize.pm 2005/07/24 11:17:44 29 +++ trunk/lib/WebPAC/Normalize.pm 2005/11/15 16:56:44 64 @@ -81,13 +81,15 @@ }, db => $db_obj, lookup_regex => $lookup->regex, + lookup => $lookup_obj, ); Parametar C defines user supplied snippets of perl code which can be use with C notation. Recommended parametar C is used to enable parsing of lookups -in structures. +in structures. If you pass this parametar, you must also pass C +which is C object. =cut @@ -96,6 +98,19 @@ my $self = {@_}; bless($self, $class); + my $r = $self->{'lookup_regex'} ? 1 : 0; + my $l = $self->{'lookup'} ? 1 : 0; + + my $log = $self->_get_logger(); + + # those two must be in pair + if ( ($r & $l) != ($r || $l) ) { + my $log = $self->_get_logger(); + $log->logdie("lookup_regex and lookup must be in pair"); + } + + $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup')); + $self ? return $self : return undef; } @@ -156,7 +171,10 @@ #print "field $field [",$self->{'tag'},"] = ",Dumper($self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}}); foreach my $tag (@{$self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}}}) { - my $format = $tag->{'value'} || $tag->{'content'}; + my $format; + + $log->logdie("expected tag HASH and got $tag") unless (ref($tag) eq 'HASH'); + $format = $tag->{'value'} || $tag->{'content'}; $log->debug("format: $format"); @@ -239,6 +257,8 @@ } + $log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'}); + $self->{'db'}->save_ds( ds => \@ds, current_filename => $self->{'current_filename'}, @@ -443,7 +463,11 @@ } # do we have lookups? if ($self->{'lookup'}) { - return $self->lookup($format); + if ($self->{'lookup'}->can('lookup')) { + return $self->{'lookup'}->lookup($format); + } else { + $log->warn("Have lookup object but can't invoke lookup method"); + } } else { return $format; } @@ -516,7 +540,7 @@ if ($sf && $$rec->{$f}->[$i]->{$sf}) { $$found++ if (defined($$found)); return $$rec->{$f}->[$i]->{$sf}; - } elsif ($$rec->{$f}->[$i]) { + } elsif (! $sf && $$rec->{$f}->[$i]) { $$found++ if (defined($$found)); # it still might have subfield, just # not specified, so we'll dump all @@ -529,6 +553,8 @@ } else { return $$rec->{$f}->[$i]; } + } else { + return ''; } } else { return ''; @@ -569,7 +595,7 @@ $log->debug("using format $name [$format] on $data to produce: $out"); if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) { - return $self->lookup($out); + return $self->{'lookup'}->lookup($out); } else { return $out; }