]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm
Merging acq-experiment to trunk, since rel_1_4 has been branched.
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Utils / MFHD / Caption.pm
1 package MFHD::Caption;
2 use strict;
3 use integer;
4 use Carp;
5
6 use MARC::Record;
7
8 sub new
9 {
10     my $proto = shift;
11     my $class = ref($proto) || $proto;
12     my $caption = shift;
13     my $self = {};
14     my $last_enum = undef;
15
16     $self->{CAPTION} = $caption;
17     $self->{ENUMS} = {};
18     $self->{CHRONS} = {};
19     $self->{PATTERN} = {};
20     $self->{COPY} = undef;
21     $self->{UNIT} = undef;
22
23     foreach my $subfield ($caption->subfields) {
24         my ($key, $val) = @$subfield;
25         if ($key eq '8') {
26             $self->{LINK} = $val;
27         } elsif ($key =~ /[a-h]/) {
28             # Enumeration Captions
29             $self->{ENUMS}->{$key} = {CAPTION => $val,
30                                       COUNT => undef,
31                                       RESTART => undef};
32             if ($key =~ /[ag]/) {
33                 $last_enum = undef;
34             } else {
35                 $last_enum = $key;
36             }
37         } elsif ($key =~ /[i-m]/) {
38             # Chronology captions
39             $self->{CHRONS}->{$key} = $val;
40         } elsif ($key eq 'u') {
41             # Bib units per next higher enumeration level
42             carp('$u specified for top-level enumeration')
43               unless defined($last_enum);
44             $self->{ENUMS}->{$last_enum}->{COUNT} = $val;
45         } elsif ($key eq 'v') {
46             carp '$v specified for top-level enumeration'
47               unless defined($last_enum);
48             $self->{ENUMS}->{$last_enum}->{RESTART} = ($val eq 'r');
49         } elsif ($key =~ /[npw-z]/) {
50             # Publication Pattern ('o' == type of unit, 'q'..'t' undefined)
51             $self->{PATTERN}->{$key} = $val;
52         } elsif ($key eq 'o') {
53             # Type of unit
54             $self->{UNIT} = $val;
55         } elsif ($key eq 't') {
56             $self->{COPY} = $val;
57         } else {
58             carp "Unknown caption subfield '$key'";
59         }
60     }
61
62     bless ($self, $class);
63     return $self;
64 }
65
66 sub caption {
67     my $self = shift;
68     my $key;
69
70     if (@_) {
71         $key = shift;
72         return $self->{ENUMS}->{$key}->{CAPTION};
73     } else {
74         return $self->{CAPTION};
75     }
76 }
77
78 1;