11 my $class = ref($proto) || $proto;
14 my $last_enum = undef;
16 $self->{CAPTION} = $caption;
19 $self->{PATTERN} = {};
20 $self->{COPY} = undef;
21 $self->{UNIT} = undef;
22 $self->{COMPRESSIBLE} = 1; # until proven otherwise
24 foreach my $subfield ($caption->subfields) {
25 my ($key, $val) = @$subfield;
28 } elsif ($key =~ /[a-h]/) {
29 # Enumeration Captions
30 $self->{ENUMS}->{$key} = {CAPTION => $val,
38 } elsif ($key =~ /[i-m]/) {
40 $self->{CHRONS}->{$key} = $val;
41 } elsif ($key eq 'u') {
42 # Bib units per next higher enumeration level
43 carp('$u specified for top-level enumeration')
44 unless defined($last_enum);
45 $self->{ENUMS}->{$last_enum}->{COUNT} = $val;
46 } elsif ($key eq 'v') {
47 carp '$v specified for top-level enumeration'
48 unless defined($last_enum);
49 $self->{ENUMS}->{$last_enum}->{RESTART} = ($val eq 'r');
50 } elsif ($key =~ /[npwxz]/) {
51 # Publication Pattern ('o' == type of unit, 'q'..'t' undefined)
52 $self->{PATTERN}->{$key} = $val;
53 } elsif ($key eq 'y') {
54 # Publication pattern: 'y' is repeatable
55 $self->{PATTERN}->{y} = [] if (!defined $self->{PATTERN}->{y});
56 push @{$self->{PATTERN}->{y}}, $val;
57 } elsif ($key eq 'o') {
60 } elsif ($key eq 't') {
63 carp "Unknown caption subfield '$key'";
67 # subsequent levels of enumeration (primary and alternate)
68 # If an enumeration level doesn't document the number
69 # of "issues" per "volume", or whether numbering of issues
70 # restarts, then we can't compress.
71 foreach my $key ('b', 'c', 'd', 'e', 'f', 'h') {
72 if (exists $self->{ENUMS}->{$key}) {
73 my $pattern = $self->{ENUMS}->{$key};
74 if (!$pattern->{RESTART} || !$pattern->{COUNT}
75 || ($pattern->{COUNT} eq 'var')
76 || ($pattern->{COUNT} eq 'und')) {
77 $self->{COMPRESSIBLE} = 0;
83 # If there's a $x subfield and a $j, then it's compressible
84 if (exists $self->{PATTERN}->{x} && exists $self->{CHRONS}->{'j'}) {
85 $self->{COMPRESSIBLE} = 1;
88 bless ($self, $class);
90 if (exists $self->{PATTERN}->{y}) {
91 $self->decode_pattern;
99 my $pattern = $self->{PATTERN}->{y};
105 return $self->{COMPRESSIBLE};
114 if (exists $self->{ENUMS}->{$key}) {
115 return $self->{ENUMS}->{$key}->{CAPTION};
116 } elsif (exists $self->{CHRONS}->{$key}) {
117 return $self->{CHRONS}->{$key};
122 return $self->{CAPTION};
126 # If items are identified by chronology only, with no separate
127 # enumeration (eg, a newspaper issue), then the chronology is
128 # recorded in the enumeration subfields $a - $f. We can tell
129 # that this is the case if there are $a - $f subfields and no
130 # chronology subfields ($i-$k), and none of the $a-$f subfields
131 # have associated $u or $v subfields, but there are $w and $y
134 sub enumeration_is_chronology {
137 # There is always a '$a' subfield in well-formed fields.
138 return 0 if exists $self->{CHRONS}->{i};
140 foreach my $key ('a' .. 'f') {
143 last if !exists $self->{ENUMS}->{$key};
145 $enum = $self->{ENUMS}->{$key};
146 return 0 if defined $enum->{COUNT} || defined $enum->{RESTART};
149 return (exists $self->{PATTERN}->{w} && exists $self->{PATTERN}->{y});