Solidify caption/holding relationship
authorDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 15:55:21 +0000 (11:55 -0400)
committerDan Wells <dbw2@calvin.edu>
Tue, 2 Jul 2013 15:55:21 +0000 (11:55 -0400)
This commit:
- Makes sure that holding data is valid for the given caption
  for new holding objects
- Teaches field_values() to fall back to '*' (unknown marker)
  when a holding is missing data
- Allows the caption() method to be a setter

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm

index 920bfd2..d5571d1 100644 (file)
@@ -42,6 +42,9 @@ sub new {
             if (exists($self->{_mfhdh_FIELDS}->{$key})) {
                 carp("Duplicate, non-repeatable subfield '$key' found, ignoring");
                 next;
+            } elsif (!$caption->capfield($key)) {
+                carp("Subfield '$key' has no corresponding caption, ignoring");
+                next;
             }
             if ($self->{_mfhdh_COMPRESSED}) {
                 $self->{_mfhdh_FIELDS}->{$key}{HOLDINGS} = [split(/\-/, $val, -1)];
@@ -116,8 +119,15 @@ sub field_values {
     if (exists $self->fields->{$key}) {
         my @values = @{$self->fields->{$key}{HOLDINGS}};
         return \@values;
+    } elsif ($self->caption->capfield($key)) {
+        carp("No values found for existing caption subfield '$key', returning '*' (unknown value indicator)");
+        if ($self->is_compressed) {
+            return ['*', '*'];
+        } else {
+            return ['*'];
+        }
     } else {
-        return undef;
+        return;
     }
 }
 
@@ -161,6 +171,11 @@ sub is_open_ended {
 
 sub caption {
     my $self = shift;
+    my $caption = shift;
+
+    if ($caption) {
+        $self->{_mfhdh_CAPTION} = $caption;
+    }
 
     return $self->{_mfhdh_CAPTION};
 }