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 =~ /[npw-z]/) {
51 # Publication Pattern ('o' == type of unit, 'q'..'t' undefined)
52 $self->{PATTERN}->{$key} = $val;
53 } elsif ($key eq 'o') {
56 } elsif ($key eq 't') {
59 carp "Unknown caption subfield '$key'";
63 # subsequent levels of enumeration (primary and alternate)
64 # If an enumeration level doesn't document the number
65 # of "issues" per "volume", or whether numbering of issues
66 # restarts, then we can't compress.
67 foreach my $key ('b', 'c', 'd', 'e', 'f', 'h') {
68 if (exists $self->{ENUMS}->{$key}) {
69 my $pattern = $self->{ENUMS}->{$key};
70 if (!$pattern->{RESTART} || !$pattern->{COUNT}
71 || ($pattern->{COUNT} eq 'var')
72 || ($pattern->{COUNT} eq 'und')) {
73 $self->{COMPRESSIBLE} = 0;
79 # If there's a $x subfield and a $j, then it's compressible
80 if (exists $self->{PATTERN}->{x} && exists $self->{CHRONS}->{'j'}) {
81 $self->{COMPRESSIBLE} = 1;
84 bless ($self, $class);
91 return $self->{COMPRESSIBLE};
100 if (exists $self->{ENUMS}->{$key}) {
101 return $self->{ENUMS}->{$key}->{CAPTION};
102 } elsif (exists $self->{CHRONS}->{$key}) {
103 return $self->{CHRONS}->{$key};
108 return $self->{CAPTION};
112 # If items are identified by chronology only, with no separate
113 # enumeration (eg, a newspaper issue), then the chronology is
114 # recorded in the enumeration subfields $a - $f. We can tell
115 # that this is the case if there are $a - $f subfields and no
116 # chronology subfields ($i-$k), and none of the $a-$f subfields
117 # have associated $u or $v subfields, but there are $w and $y
120 sub enumeration_is_chronology {
123 # There is always a '$a' subfield in well-formed fields.
124 return 0 if exists $self->{CHRONS}->{i};
126 foreach my $key ('a' .. 'f') {
129 last if !exists $self->{ENUMS}->{$key};
131 $enum = $self->{ENUMS}->{$key};
132 return 0 if defined $enum->{COUNT} || defined $enum->{RESTART};
135 return (exists $self->{PATTERN}->{w} && exists $self->{PATTERN}->{y});