2 |
|
|
3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
use blib; |
6 |
|
use WebPAC::Common; |
7 |
use base 'WebPAC::Common'; |
use base 'WebPAC::Common'; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
572 |
|
|
573 |
Returns value from record. |
Returns value from record. |
574 |
|
|
575 |
my $text = $self->get_data(\$rec,$f,$sf,$i,\$found); |
my $text = $self->get_data(\$rec,$f,$sf,$i,\$found,\$fld_occurances); |
576 |
|
|
577 |
Arguments are: |
Required arguments are: |
|
record reference C<$rec>, |
|
|
field C<$f>, |
|
|
optional subfiled C<$sf>, |
|
|
index for repeatable values C<$i>. |
|
578 |
|
|
579 |
Optinal variable C<$found> will be incremeted if there |
=over 8 |
|
is field. |
|
580 |
|
|
581 |
Returns value or empty string. |
=item C<$rec> |
582 |
|
|
583 |
|
record reference |
584 |
|
|
585 |
|
=item C<$f> |
586 |
|
|
587 |
|
field |
588 |
|
|
589 |
|
=item C<$sf> |
590 |
|
|
591 |
|
optional subfield |
592 |
|
|
593 |
|
=item C<$i> |
594 |
|
|
595 |
|
index offset for repeatable values ( 0 ... $#occurances ) |
596 |
|
|
597 |
|
=item C<$found> |
598 |
|
|
599 |
|
optional variable that will be incremeted if preset |
600 |
|
|
601 |
|
=item C<$fld_occurances> |
602 |
|
|
603 |
|
hash to hold maximum occurances of C<field\tsubfield> combinations |
604 |
|
(which can be accessed using keys in same format) |
605 |
|
|
606 |
|
=back |
607 |
|
|
608 |
|
Returns value or empty string, updates C<$found> and C<fld_occurences> |
609 |
|
if present. |
610 |
|
|
611 |
=cut |
=cut |
612 |
|
|
613 |
sub get_data { |
sub get_data { |
614 |
my $self = shift; |
my $self = shift; |
615 |
|
|
616 |
my ($rec,$f,$sf,$i,$found) = @_; |
my ($rec,$f,$sf,$i,$found,$cache) = @_; |
617 |
|
|
618 |
|
return '' unless ($$rec->{$f} && ref($$rec->{$f}) eq 'ARRAY'); |
619 |
|
|
620 |
|
if (defined($$cache)) { |
621 |
|
$$cache->{"$f\t$sf"} ||= $$#rec->{$f}; |
622 |
|
} |
623 |
|
|
624 |
if ($$rec->{$f}) { |
return '' unless ($$rec->{$f}->[$i]); |
625 |
return '' if (! $$rec->{$f}->[$i]); |
|
626 |
|
{ |
627 |
no strict 'refs'; |
no strict 'refs'; |
628 |
if ($sf && $$rec->{$f}->[$i]->{$sf}) { |
if (defined($sf)) { |
629 |
$$found++ if (defined($$found)); |
$$found++ if (defined($$found) && $$rec->{$f}->[$i]->{$sf}); |
630 |
return $$rec->{$f}->[$i]->{$sf}; |
return $$rec->{$f}->[$i]->{$sf}; |
631 |
} elsif (! $sf && $$rec->{$f}->[$i]) { |
} else { |
632 |
$$found++ if (defined($$found)); |
$$found++ if (defined($$found)); |
633 |
# it still might have subfield, just |
# it still might have subfields, just |
634 |
# not specified, so we'll dump all |
# not specified, so we'll dump some debug info |
635 |
if ($$rec->{$f}->[$i] =~ /HASH/o) { |
if ($$rec->{$f}->[$i] =~ /HASH/o) { |
636 |
my $out; |
my $out; |
637 |
foreach my $k (keys %{$$rec->{$f}->[$i]}) { |
foreach my $k (keys %{$$rec->{$f}->[$i]}) { |
638 |
my $v = $$rec->{$f}->[$i]->{$k}; |
$out .= '$' . $k .':' . $$rec->{$f}->[$i]->{$k}." "; |
|
$out .= "$v " if ($v); |
|
639 |
} |
} |
640 |
return $out; |
return $out; |
641 |
} else { |
} else { |
642 |
return $$rec->{$f}->[$i]; |
return $$rec->{$f}->[$i]; |
643 |
} |
} |
|
} else { |
|
|
return ''; |
|
644 |
} |
} |
|
} else { |
|
|
return ''; |
|
645 |
} |
} |
646 |
} |
} |
647 |
|
|