--- trunk2/lib/WebPAC.pm 2004/06/16 11:31:42 354 +++ trunk2/lib/WebPAC.pm 2004/06/16 11:41:50 355 @@ -156,30 +156,45 @@ } # create lookup + my $rec = $self->{'data'}->{$mfn}; + $self->create_lookup($rec, @{$arg->{'lookup'}}); - foreach my $i (@{$arg->{lookup}}) { - my $rec = $self->{'data'}->{$mfn}; - if ($i->{'eval'}) { - my $eval = $self->fill_in($rec,$i->{'eval'}); - my $key = $self->fill_in($rec,$i->{'key'}); - my @val = $self->fill_in($rec,$i->{'val'}); - if ($key && @val && eval $eval) { - push @{$self->{'lookup'}->{$key}}, @val; - } - } else { - my $key = $self->fill_in($rec,$i->{'key'}); - my @val = $self->fill_in($rec,$i->{'val'}); - if ($key && @val) { - push @{$self->{'lookup'}->{$key}}, @val; - } - } - } } # store max mfn and return it. return $self->{'max_mfn'} = $maxmfn; } +=head2 create_lookup + +Create lookup from record using lookup definition. + +=cut + +sub create_lookup { + my $self = shift; + + my $rec = shift || confess "need record to create lookup"; + confess("need HASH as first argument!") if ($rec !~ /HASH/o); + + foreach my $i (@_) { + if ($i->{'eval'}) { + my $eval = $self->fill_in($rec,$i->{'eval'}); + my $key = $self->fill_in($rec,$i->{'key'}); + my @val = $self->fill_in($rec,$i->{'val'}); + if ($key && @val && eval $eval) { + push @{$self->{'lookup'}->{$key}}, @val; + } + } else { + my $key = $self->fill_in($rec,$i->{'key'}); + my @val = $self->fill_in($rec,$i->{'val'}); + if ($key && @val) { + push @{$self->{'lookup'}->{$key}}, @val; + } + } + } +} + =head2 fill_in Workhourse of all: takes record from in-memory structure of database and @@ -209,9 +224,7 @@ my $i = shift || 0; # FIXME remove for speedup? - if ($rec !~ /HASH/o) { - confess("need HASH as first argument!"); - } + confess("need HASH as first argument!") if ($rec !~ /HASH/o); my $found = 0; @@ -255,10 +268,12 @@ =head2 lookup -This function will perform lookups on format supplied to it. +Perform lookups on format supplied to it. my $txt = $self->lookup('[v900]'); +Lookups can be nested (like C<[d:[a:[v900]]]>). + =cut sub lookup {