--- trunk/lib/WebPAC/Normalize.pm 2006/02/15 15:54:12 397 +++ trunk/lib/WebPAC/Normalize.pm 2006/04/30 12:17:19 436 @@ -13,11 +13,11 @@ =head1 VERSION -Version 0.08 +Version 0.09 =cut -our $VERSION = '0.08'; +our $VERSION = '0.09'; =head1 SYNOPSIS @@ -137,6 +137,37 @@ $self ? return $self : return undef; } +=head2 all_tags + +Returns all tags in document in specified order + + my $sorted_tags = $self->all_tags(); + +=cut + +sub all_tags { + my $self = shift; + + if (! $self->{_tags_by_order}) { + + my $log = $self->_get_logger; + # sanity check + $log->logdie("can't find self->{inport_xml}->{indexer}") unless ($self->{import_xml}->{indexer}); + + my @tags = keys %{ $self->{'import_xml'}->{'indexer'}}; + $log->debug("unsorted tags: " . join(", ", @tags)); + + @tags = sort { $self->_sort_by_order } @tags; + + $log->debug("sorted tags: " . join(",", @tags) ); + + $self->{_tags_by_order} = \@tags; + } + + return $self->{_tags_by_order}; +} + + =head2 data_structure @@ -172,19 +203,13 @@ $log->debug("cache miss, creating"); } - my @sorted_tags; - if ($self->{tags_by_order}) { - @sorted_tags = @{$self->{tags_by_order}}; - } else { - @sorted_tags = sort { $self->_sort_by_order } keys %{$self->{'import_xml'}->{'indexer'}}; - $self->{tags_by_order} = \@sorted_tags; - } + my $tags = $self->all_tags(); - my $ds; + $log->debug("tags: ",sub { join(", ",@{ $tags }) }); - $log->debug("tags: ",sub { join(", ",@sorted_tags) }); + my $ds; - foreach my $field (@sorted_tags) { + foreach my $field (@{ $tags }) { my $row; @@ -364,7 +389,7 @@ # we will skip delimiter before first occurence of field! push @out, $del unless($found_any->{$fld_type} == 1); - push @out, $tmp; + push @out, $tmp if ($tmp); } $f_step++; } @@ -633,7 +658,8 @@ if ($$rec->{$f}->[$i] =~ /HASH/o) { my $out; foreach my $k (keys %{$$rec->{$f}->[$i]}) { - $out .= '$' . $k .':' . $$rec->{$f}->[$i]->{$k}." "; + my $v = $$rec->{$f}->[$i]->{$k}; + $out .= '$' . $k .':' . $v if ($v); } return $out; } else {