--- trunk/lib/WebPAC/Normalize.pm 2006/01/08 20:27:11 364 +++ trunk/lib/WebPAC/Normalize.pm 2006/01/08 20:32:06 368 @@ -2,6 +2,8 @@ use warnings; use strict; +use blib; +use WebPAC::Common; use base 'WebPAC::Common'; use Data::Dumper; @@ -570,51 +572,76 @@ Returns value from record. - my $text = $self->get_data(\$rec,$f,$sf,$i,\$found); + my $text = $self->get_data(\$rec,$f,$sf,$i,\$found,\$fld_occurances); -Arguments are: -record reference C<$rec>, -field C<$f>, -optional subfiled C<$sf>, -index for repeatable values C<$i>. +Required arguments are: -Optinal variable C<$found> will be incremeted if there -is field. +=over 8 -Returns value or empty string. +=item C<$rec> + +record reference + +=item C<$f> + +field + +=item C<$sf> + +optional subfield + +=item C<$i> + +index offset for repeatable values ( 0 ... $#occurances ) + +=item C<$found> + +optional variable that will be incremeted if preset + +=item C<$fld_occurances> + +hash to hold maximum occurances of C combinations +(which can be accessed using keys in same format) + +=back + +Returns value or empty string, updates C<$found> and C +if present. =cut sub get_data { my $self = shift; - my ($rec,$f,$sf,$i,$found) = @_; + my ($rec,$f,$sf,$i,$found,$cache) = @_; + + return '' unless ($$rec->{$f} && ref($$rec->{$f}) eq 'ARRAY'); + + if (defined($$cache)) { + $$cache->{"$f\t$sf"} ||= $$#rec->{$f}; + } - if ($$rec->{$f}) { - return '' if (! $$rec->{$f}->[$i]); + return '' unless ($$rec->{$f}->[$i]); + + { no strict 'refs'; - if ($sf && $$rec->{$f}->[$i]->{$sf}) { - $$found++ if (defined($$found)); + if (defined($sf)) { + $$found++ if (defined($$found) && $$rec->{$f}->[$i]->{$sf}); return $$rec->{$f}->[$i]->{$sf}; - } elsif (! $sf && $$rec->{$f}->[$i]) { + } else { $$found++ if (defined($$found)); - # it still might have subfield, just - # not specified, so we'll dump all + # it still might have subfields, just + # not specified, so we'll dump some debug info if ($$rec->{$f}->[$i] =~ /HASH/o) { my $out; foreach my $k (keys %{$$rec->{$f}->[$i]}) { - my $v = $$rec->{$f}->[$i]->{$k}; - $out .= "$v " if ($v); + $out .= '$' . $k .':' . $$rec->{$f}->[$i]->{$k}." "; } return $out; } else { return $$rec->{$f}->[$i]; } - } else { - return ''; } - } else { - return ''; } }