--- trunk/lib/WebPAC/Normalize.pm 2006/09/08 17:47:58 661 +++ trunk/lib/WebPAC/Normalize.pm 2006/09/11 14:29:01 669 @@ -36,11 +36,11 @@ =head1 VERSION -Version 0.18 +Version 0.19 =cut -our $VERSION = '0.18'; +our $VERSION = '0.19'; =head1 SYNOPSIS @@ -722,7 +722,11 @@ =head2 _pack_subfields_hash - @values = _pack_subfields_hash( $h, $include_subfields ) + @subfields = _pack_subfields_hash( $h ); + $subfields = _pack_subfields_hash( $h, 1 ); + +Return each subfield value in array or pack them all together and return scalar +with subfields (denoted by C<^>) and values. =cut @@ -732,7 +736,6 @@ my ($h,$include_subfields) = @_; - if ( defined($h->{subfields}) ) { my $sfs = delete $h->{subfields} || die "no subfields?"; my @out; @@ -742,16 +745,34 @@ my $o = shift @$sfs; if ($o == 0 && ref( $h->{$sf} ) ne 'ARRAY' ) { # single element subfields are not arrays +#warn "====> $sf $o / $#$sfs ", dump( $sfs, $h->{$sf} ), "\n"; + push @out, $h->{$sf}; } else { -#warn "====> $f $sf $o $#$sfs ", dump( $sfs ), "\n"; +#warn "====> $sf $o / $#$sfs ", dump( $sfs, $h->{$sf} ), "\n"; push @out, $h->{$sf}->[$o]; } } - return @out; + if ($include_subfields) { + return join('', @out); + } else { + return @out; + } } else { - # FIXME this should probably be in alphabetical order instead of hash order - values %{$h}; + if ($include_subfields) { + my $out = ''; + foreach my $sf (sort keys %$h) { + if (ref($h->{$sf}) eq 'ARRAY') { + $out .= '^' . $sf . join('^' . $sf, @{ $h->{$sf} }); + } else { + $out .= '^' . $sf . $h->{$sf}; + } + } + return $out; + } else { + # FIXME this should probably be in alphabetical order instead of hash order + values %{$h}; + } } }