--- trunk/lib/WebPAC/Normalize.pm 2005/12/23 21:37:05 317 +++ trunk/lib/WebPAC/Normalize.pm 2006/01/08 20:27:11 364 @@ -194,15 +194,18 @@ $log->logdie("expected tag HASH and got $tag") unless (ref($tag) eq 'HASH'); $format = $tag->{'value'} || $tag->{'content'}; - $log->debug("format: $format"); - my @v; if ($self->{'lookup_regex'} && $format =~ $self->{'lookup_regex'}) { @v = $self->fill_in_to_arr($rec,$format); } else { @v = $self->parse_to_arr($rec,$format); } - next if (! @v); + if (! @v) { + $log->debug("$field <",$self->{tag},"> format: $format no values"); +# next; + } else { + $log->debug("$field <",$self->{tag},"> format: $format values: ", join(",", @v)); + } if ($tag->{'sort'}) { @v = $self->sort_arr(@v); @@ -225,7 +228,7 @@ foreach my $type (@types) { # append to previous line? - $log->debug("type: $type ",sub { join(" ",@v) }, " ", $row->{'append'} || 'no append'); + $log->debug("tag $field / $type [",sub { join(",",@v) }, "] ", $row->{'append'} || 'no append'); if ($tag->{'append'}) { # I will delimit appended part with @@ -317,7 +320,7 @@ my @out; - $log->debug("format: $format"); + $log->debug("format: $format [$i]"); my $eval_code; # remove eval{...} from beginning @@ -328,7 +331,7 @@ $filter_name = $1 if ($format =~ s/^filter{([^}]+)}//s); # did we found any (att all) field from format in row? - my $found_any = 0; + my $found_any; # prefix before first field which we preserve it $found_any my $prefix; @@ -339,24 +342,33 @@ my $del = $1 || ''; $prefix = $del if ($f_step == 1); + my $fld_type = lc($2); + # repeatable index my $r = $i; - $r = 0 if (lc("$2") eq 's'); + if ($fld_type eq 's') { + if ($found_any->{'v'}) { + $r = 0; + } else { + return; + } + } my $found = 0; my $tmp = $self->get_data(\$rec,$3,$4,$r,\$found); if ($found) { - $found_any += $found; + $found_any->{$fld_type} += $found; # we will skip delimiter before first occurence of field! - push @out, $del unless($found_any == 1); + push @out, $del unless($found_any->{$fld_type} == 1); push @out, $tmp; } $f_step++; } - return if (! $found_any); + # test if any fields found? + return if (! $found_any->{'v'} && ! $found_any->{'s'}); my $out = join('',@out); @@ -470,6 +482,7 @@ } my $found = 0; + my $just_single = 1; my $eval_code; # remove eval{...} from beginning @@ -481,9 +494,14 @@ # do actual replacement of placeholders # repeatable fields - $format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges; + if ($format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges) { + $just_single = 0; + } + # non-repeatable fields - $format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges; + if ($format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges) { + return if ($i > 0 && $just_single); + } if ($found) { $log->debug("format: $format"); @@ -538,8 +556,8 @@ my $i = 0; my @arr; - while (my @v = $self->fill_in($rec,$format_utf8,$i++)) { - push @arr, @v; + while (my $v = $self->fill_in($rec,$format_utf8,$i++)) { + push @arr, $v; } $log->debug("format '$format_utf8' returned ",--$i," elements: ", sub { join(" | ",@arr) }) if (@arr); @@ -585,7 +603,8 @@ if ($$rec->{$f}->[$i] =~ /HASH/o) { my $out; foreach my $k (keys %{$$rec->{$f}->[$i]}) { - $out .= $$rec->{$f}->[$i]->{$k}." "; + my $v = $$rec->{$f}->[$i]->{$k}; + $out .= "$v " if ($v); } return $out; } else {