4 |
_set_rec _set_lookup |
_set_rec _set_lookup |
5 |
_get_ds _clean_ds |
_get_ds _clean_ds |
6 |
_debug |
_debug |
7 |
|
_pack_subfields_hash |
8 |
|
|
9 |
tag search display |
tag search display |
10 |
marc marc_indicators marc_repeatable_subfield |
marc marc_indicators marc_repeatable_subfield |
24 |
|
|
25 |
#use base qw/WebPAC::Common/; |
#use base qw/WebPAC::Common/; |
26 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
|
use Encode qw/from_to/; |
|
27 |
use Storable qw/dclone/; |
use Storable qw/dclone/; |
28 |
|
|
29 |
# debugging warn(s) |
# debugging warn(s) |
36 |
|
|
37 |
=head1 VERSION |
=head1 VERSION |
38 |
|
|
39 |
Version 0.17 |
Version 0.18 |
40 |
|
|
41 |
=cut |
=cut |
42 |
|
|
43 |
our $VERSION = '0.17'; |
our $VERSION = '0.18'; |
44 |
|
|
45 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
46 |
|
|
469 |
foreach (@_) { |
foreach (@_) { |
470 |
my $v = $_; # make var read-write for Encode |
my $v = $_; # make var read-write for Encode |
471 |
next unless (defined($v) && $v !~ /^\s*$/); |
next unless (defined($v) && $v !~ /^\s*$/); |
|
from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); |
|
472 |
my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); |
my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); |
473 |
if (defined $sf) { |
if (defined $sf) { |
474 |
push @{ $marc_record->[ $marc_record_offset ] }, [ $f, $i1, $i2, $sf => $v ]; |
push @{ $marc_record->[ $marc_record_offset ] }, [ $f, $i1, $i2, $sf => $v ]; |
548 |
my $v = shift; |
my $v = shift; |
549 |
|
|
550 |
next unless (defined($v) && $v !~ /^\s*$/); |
next unless (defined($v) && $v !~ /^\s*$/); |
|
from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); |
|
551 |
warn "## ++ marc_compose($f,$sf,$v) ", dump( $m ),$/ if ($debug > 1); |
warn "## ++ marc_compose($f,$sf,$v) ", dump( $m ),$/ if ($debug > 1); |
552 |
if ($sf ne '+') { |
if ($sf ne '+') { |
553 |
push @$m, ( $sf, $v ); |
push @$m, ( $sf, $v ); |
720 |
This function should be used inside functions to create C<data_structure> described |
This function should be used inside functions to create C<data_structure> described |
721 |
above. |
above. |
722 |
|
|
723 |
|
=head2 _pack_subfields_hash |
724 |
|
|
725 |
|
@values = _pack_subfields_hash( $h, $include_subfields ) |
726 |
|
|
727 |
|
=cut |
728 |
|
|
729 |
|
sub _pack_subfields_hash { |
730 |
|
|
731 |
|
warn "## _pack_subfields_hash( ",dump(@_), " )\n" if ($debug > 1); |
732 |
|
|
733 |
|
my ($h,$include_subfields) = @_; |
734 |
|
|
735 |
|
|
736 |
|
if ( defined($h->{subfields}) ) { |
737 |
|
my $sfs = delete $h->{subfields} || die "no subfields?"; |
738 |
|
my @out; |
739 |
|
while (@$sfs) { |
740 |
|
my $sf = shift @$sfs; |
741 |
|
push @out, '^' . $sf if ($include_subfields); |
742 |
|
my $o = shift @$sfs; |
743 |
|
if ($o == 0 && ref( $h->{$sf} ) ne 'ARRAY' ) { |
744 |
|
# single element subfields are not arrays |
745 |
|
push @out, $h->{$sf}; |
746 |
|
} else { |
747 |
|
#warn "====> $f $sf $o $#$sfs ", dump( $sfs ), "\n"; |
748 |
|
push @out, $h->{$sf}->[$o]; |
749 |
|
} |
750 |
|
} |
751 |
|
return @out; |
752 |
|
} else { |
753 |
|
# FIXME this should probably be in alphabetical order instead of hash order |
754 |
|
values %{$h}; |
755 |
|
} |
756 |
|
} |
757 |
|
|
758 |
=head2 rec1 |
=head2 rec1 |
759 |
|
|
760 |
Return all values in some field |
Return all values in some field |
771 |
return unless (defined($rec) && defined($rec->{$f})); |
return unless (defined($rec) && defined($rec->{$f})); |
772 |
warn "rec1($f) = ", dump( $rec->{$f} ), $/ if ($debug > 1); |
warn "rec1($f) = ", dump( $rec->{$f} ), $/ if ($debug > 1); |
773 |
if (ref($rec->{$f}) eq 'ARRAY') { |
if (ref($rec->{$f}) eq 'ARRAY') { |
774 |
return map { |
my @out; |
775 |
if (ref($_) eq 'HASH') { |
foreach my $h ( @{ $rec->{$f} } ) { |
776 |
my $h = $_; |
if (ref($h) eq 'HASH') { |
777 |
if ( defined($h->{subfields}) ) { |
push @out, ( _pack_subfields_hash( $h ) ); |
|
my $sfs = delete $h->{subfields} || die "no subfields?"; |
|
|
my @out; |
|
|
while (@$sfs) { |
|
|
my $sf = shift @$sfs; |
|
|
my $o = shift @$sfs; |
|
|
if ($o == 0 && ref( $h->{$sf} ) ne 'ARRAY' ) { |
|
|
# single element subfields are not arrays |
|
|
push @out, $h->{$sf}; |
|
|
} else { |
|
|
warn "====> $f $sf $o $#$sfs ", dump( $sfs ), "\n"; |
|
|
push @out, $h->{$sf}->[$o]; |
|
|
} |
|
|
} |
|
|
return @out; |
|
|
} else { |
|
|
# FIXME this should probably be in alphabetical order instead of hash order |
|
|
values %{$h}; |
|
|
} |
|
778 |
} else { |
} else { |
779 |
$_; |
push @out, $h; |
780 |
} |
} |
781 |
} @{ $rec->{$f} }; |
} |
782 |
|
return @out; |
783 |
} elsif( defined($rec->{$f}) ) { |
} elsif( defined($rec->{$f}) ) { |
784 |
return $rec->{$f}; |
return $rec->{$f}; |
785 |
} |
} |