--- trunk/lib/WebPAC/Normalize.pm 2006/01/08 21:16:27 371 +++ trunk/lib/WebPAC/Normalize.pm 2006/01/08 21:50:34 372 @@ -198,9 +198,9 @@ my @v; if ($self->{'lookup_regex'} && $format =~ $self->{'lookup_regex'}) { - @v = $self->fill_in_to_arr($rec,$format); + @v = $self->_rec_to_arr($rec,$format,'fill_in'); } else { - @v = $self->parse_to_arr($rec,$format); + @v = $self->_rec_to_arr($rec,$format,'parse'); } if (! @v) { $log->debug("$field <",$self->{tag},"> format: $format no values"); @@ -410,40 +410,6 @@ return $out; } -=head2 parse_to_arr - -Similar to C, but returns array of all repeatable fields - - my @arr = $webpac->parse_to_arr($rec,'v250^a'); - -=cut - -sub parse_to_arr { - my $self = shift; - - my ($rec, $format_utf8) = @_; - - my $log = $self->_get_logger(); - - $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); - return if (! $format_utf8); - - my $i = 0; - my @arr; - - my $rec_size = { '_' => '_' }; - - while (my $v = $self->parse($rec,$format_utf8,$i++,\$rec_size)) { - push @arr, $v; - warn "parse rec_size = ", Dumper($rec_size); - } - - $log->debug("format '$format_utf8' returned ",--$i," elements: ", sub { join(" | ",@arr) }) if (@arr); - - return @arr; -} - - =head2 fill_in Workhourse of all: takes record from in-memory structure of database and @@ -546,20 +512,20 @@ } -=head2 fill_in_to_arr +=head2 _rec_to_arr -Similar to C, but returns array of all repeatable fields. Usable +Similar to C and C, but returns array of all repeatable fields. Usable for fields which have lookups, so they shouldn't be parsed but rather -Ced. +Cd or Ced. Last argument is name of operation: C or C. - my @arr = $webpac->fill_in_to_arr($rec,'[v900];;[v250^a]'); + my @arr = $webpac->fill_in_to_arr($rec,'[v900];;[v250^a]','paste'); =cut -sub fill_in_to_arr { +sub _rec_to_arr { my $self = shift; - my ($rec, $format_utf8) = @_; + my ($rec, $format_utf8, $code) = @_; my $log = $self->_get_logger(); @@ -567,13 +533,20 @@ return if (! $format_utf8); my $i = 0; + my $max = 0; my @arr; + my $rec_size = {}; - my $rec_size; - - while (my $v = $self->fill_in($rec,$format_utf8,$i,\$rec_size)) { + while ($i <= $max) { + my $v = $self->$code($rec,$format_utf8,$i++,\$rec_size) || next; push @arr, $v; - warn "rec_size = ", Dumper($rec_size); + if ($rec_size) { + foreach my $f (keys %{ $rec_size }) { + $max = $rec_size->{$f} if ($rec_size->{$f} > $max); + } + warn "max set to $max, rec_size = ", Dumper($rec_size); + undef $rec_size; + } } $log->debug("format '$format_utf8' returned ",--$i," elements: ", sub { join(" | ",@arr) }) if (@arr);