1 package OpenILS::Utils::MFHD;
7 use base 'MARC::Record';
9 use OpenILS::Utils::MFHD::Caption;
10 use OpenILS::Utils::MFHD::Holding;
14 my $class = ref($proto) || $proto;
17 $self->{_mfhd_CAPTIONS} = {};
18 $self->{_mfhd_COMPRESSIBLE} = (substr($self->leader, 17, 1) =~ /[45]/);
20 foreach my $field ('853', '854', '855') {
22 foreach my $caption ($self->field($field)) {
25 $cap_id = $caption->subfield('8') || '0';
27 if (exists $captions->{$cap_id}) {
28 carp "Multiple MFHD captions with label '$cap_id'";
31 $captions->{$cap_id} = new MFHD::Caption($caption);
32 if ($self->{_mfhd_COMPRESSIBLE}) {
33 $self->{_mfhd_COMPRESSIBLE} &&= $captions->{$cap_id}->compressible;
36 $self->{_mfhd_CAPTIONS}->{$field} = $captions;
39 foreach my $field ('863', '864', '865') {
43 ($cap_field = $field) =~ s/6/5/;
45 foreach my $hfield ($self->field($field)) {
46 my ($linkage, $link_id, $seqno);
49 $linkage = $hfield->subfield('8');
50 ($link_id, $seqno) = split(/\./, $linkage);
52 if (!exists $holdings->{$link_id}) {
53 $holdings->{$link_id} = {};
55 $holding = new MFHD::Holding($seqno, $hfield,
56 $self->{_mfhd_CAPTIONS}->{$cap_field}->{$link_id});
57 $holdings->{$link_id}->{$seqno} = $holding;
59 if ($self->{_mfhd_COMPRESSIBLE}) {
60 $self->{_mfhd_COMPRESSIBLE} &&= $holding->validate;
63 $self->{_mfhd_HOLDINGS}->{$field} = $holdings;
66 bless ($self, $class);
73 return $self->{_mfhd_COMPRESSIBLE};
80 return sort keys %{$self->{_mfhd_CAPTIONS}->{$field}}
88 return sort {$a->seqno <=> $b->seqno} values %{$self->{_mfhd_HOLDINGS}->{$field}->{$capid}};