[open-ils-commits] r12500 - in trunk/Open-ILS/src/perlmods/OpenILS/Utils: . MFHD MFHD/test (djfiander)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Mar 12 16:11:33 EDT 2009


Author: djfiander
Date: 2009-03-12 16:11:29 -0400 (Thu, 12 Mar 2009)
New Revision: 12500

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt
Log:
Redo MFHD, MFHD::Holding, and MFHD::Caption so that they are enhanced MARC::Record (for MFHD) and MARC::Field (for the other two) objects.

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm	2009-03-12 18:35:05 UTC (rev 12499)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm	2009-03-12 20:11:29 UTC (rev 12500)
@@ -4,33 +4,33 @@
 use Carp;
 
 use DateTime;
-use MARC::Record;
+use MARC::Field;
 
+our @ISA = qw(MARC::Field);
+
 sub new
 {
     my $proto = shift;
     my $class = ref($proto) || $proto;
-    my $caption = shift;
-    my $self = {};
+    my $self = shift;
     my $last_enum = undef;
 
-    $self->{CAPTION} = $caption;
-    $self->{ENUMS} = {};
-    $self->{CHRONS} = {};
-    $self->{PATTERN} = {};
-    $self->{COPY} = undef;
-    $self->{UNIT} = undef;
-    $self->{COMPRESSIBLE} = 1;	# until proven otherwise
+    $self->{_mfhdc_ENUMS} = {};
+    $self->{_mfhdc_CHRONS} = {};
+    $self->{_mfhdc_PATTERN} = {};
+    $self->{_mfhdc_COPY} = undef;
+    $self->{_mfhdc_UNIT} = undef;
+    $self->{_mfhdc_COMPRESSIBLE} = 1;	# until proven otherwise
 
-    foreach my $subfield ($caption->subfields) {
+    foreach my $subfield ($self->subfields) {
 	my ($key, $val) = @$subfield;
 	if ($key eq '8') {
 	    $self->{LINK} = $val;
 	} elsif ($key =~ /[a-h]/) {
 	    # Enumeration Captions
-	    $self->{ENUMS}->{$key} = {CAPTION => $val,
-				      COUNT => undef,
-				      RESTART => undef};
+	    $self->{_mfhdc_ENUMS}->{$key} = {CAPTION => $val,
+					     COUNT => undef,
+					     RESTART => undef};
 	    if ($key =~ /[ag]/) {
 		$last_enum = undef;
 	    } else {
@@ -38,28 +38,28 @@
 	    }
 	} elsif ($key =~ /[i-m]/) {
 	    # Chronology captions
-	    $self->{CHRONS}->{$key} = $val;
+	    $self->{_mfhdc_CHRONS}->{$key} = $val;
 	} elsif ($key eq 'u') {
 	    # Bib units per next higher enumeration level
 	    carp('$u specified for top-level enumeration')
 	      unless defined($last_enum);
-	    $self->{ENUMS}->{$last_enum}->{COUNT} = $val;
+	    $self->{_mfhdc_ENUMS}->{$last_enum}->{COUNT} = $val;
 	} elsif ($key eq 'v') {
 	    carp '$v specified for top-level enumeration'
 	      unless defined($last_enum);
-	    $self->{ENUMS}->{$last_enum}->{RESTART} = ($val eq 'r');
+	    $self->{_mfhdc_ENUMS}->{$last_enum}->{RESTART} = ($val eq 'r');
 	} elsif ($key =~ /[npwxz]/) {
 	    # Publication Pattern ('o' == type of unit, 'q'..'t' undefined)
-	    $self->{PATTERN}->{$key} = $val;
+	    $self->{_mfhdc_PATTERN}->{$key} = $val;
 	} elsif ($key eq 'y') {
 	    # Publication pattern: 'y' is repeatable
-	    $self->{PATTERN}->{y} = [] if (!defined $self->{PATTERN}->{y});
-	    push @{$self->{PATTERN}->{y}}, $val;
+	    $self->{_mfhdc_PATTERN}->{y} = [] if (!defined $self->{_mfhdc_PATTERN}->{y});
+	    push @{$self->{_mfhdc_PATTERN}->{y}}, $val;
 	} elsif ($key eq 'o') {
 	    # Type of unit
-	    $self->{UNIT} = $val;
+	    $self->{_mfhdc_UNIT} = $val;
 	} elsif ($key eq 't') {
-	    $self->{COPY} = $val;
+	    $self->{_mfhdc_COPY} = $val;
 	} else {
 	    carp "Unknown caption subfield '$key'";
 	}
@@ -70,25 +70,25 @@
     # of "issues" per "volume", or whether numbering of issues
     # restarts, then we can't compress.
     foreach my $key ('b', 'c', 'd', 'e', 'f', 'h') {
-	if (exists $self->{ENUMS}->{$key}) {
-	    my $pattern = $self->{ENUMS}->{$key};
+	if (exists $self->{_mfhdc_ENUMS}->{$key}) {
+	    my $pattern = $self->{_mfhdc_ENUMS}->{$key};
 	    if (!$pattern->{RESTART} || !$pattern->{COUNT}
 		|| ($pattern->{COUNT} eq 'var')
 		|| ($pattern->{COUNT} eq 'und')) {
-		$self->{COMPRESSIBLE} = 0;
+		$self->{_mfhdc_COMPRESSIBLE} = 0;
 		last;
 	    }
 	}
     }
 
     # If there's a $x subfield and a $j, then it's compressible
-    if (exists $self->{PATTERN}->{x} && exists $self->{CHRONS}->{'j'}) {
-	$self->{COMPRESSIBLE} = 1;
+    if (exists $self->{_mfhdc_PATTERN}->{x} && exists $self->{_mfhdc_CHRONS}->{'j'}) {
+	$self->{_mfhdc_COMPRESSIBLE} = 1;
     }
 
     bless ($self, $class);
 
-    if (exists $self->{PATTERN}->{y}) {
+    if (exists $self->{_mfhdc_PATTERN}->{y}) {
 	$self->decode_pattern;
     }
 
@@ -97,7 +97,7 @@
 
 sub decode_pattern {
     my $self = shift;
-    my $pattern = $self->{PATTERN}->{y};
+    my $pattern = $self->{_mfhdc_PATTERN}->{y};
 
     # XXX WRITE ME (?)
 }
@@ -105,27 +105,45 @@
 sub compressible {
     my $self = shift;
 
-    return $self->{COMPRESSIBLE};
+    return $self->{_mfhdc_COMPRESSIBLE};
 }
 
-sub caption {
+sub chrons {
     my $self = shift;
-    my $key;
+    my $key = shift;
 
-    if (@_) {
-	$key = shift;
-	if (exists $self->{ENUMS}->{$key}) {
-	    return $self->{ENUMS}->{$key}->{CAPTION};
-	} elsif (exists $self->{CHRONS}->{$key}) {
-	    return $self->{CHRONS}->{$key};
-	} else {
-	    return undef;
-	}
+    if (exists $self->{_mfhdc_CHRONS}->{$key}) {
+	return $self->{_mfhdc_CHRONS}->{$key};
     } else {
-	return $self->{CAPTION};
+	return undef;
     }
 }
 
+sub capfield {
+    my $self = shift;
+    my $key = shift;
+
+    if (exists $self->{_mfhdc_ENUMS}->{$key}) {
+	return $self->{_mfhdc_ENUMS}->{$key};
+    } elsif (exists $self->{_mfhdc_CHRONS}->{$key}) {
+	return $self->{_mfhdc_CHRONS}->{$key};
+    } else {
+	return undef;
+    }
+}
+
+sub capstr {
+    my $self = shift;
+    my $key = shift;
+    my $val = $self->capfield($key);
+
+    if (ref $val) {
+	return $val->{CAPTION};
+    } else {
+	return $val;
+    }
+}
+
 # If items are identified by chronology only, with no separate
 # enumeration (eg, a newspaper issue), then the chronology is
 # recorded in the enumeration subfields $a - $f.  We can tell
@@ -138,18 +156,18 @@
     my $self = shift;
 
     # There is always a '$a' subfield in well-formed fields.
-    return 0 if exists $self->{CHRONS}->{i};
+    return 0 if exists $self->{_mfhdc_CHRONS}->{i};
 
     foreach my $key ('a' .. 'f') {
 	my $enum;
 
-	last if !exists $self->{ENUMS}->{$key};
+	last if !exists $self->{_mfhdc_ENUMS}->{$key};
 
-	$enum = $self->{ENUMS}->{$key};
+	$enum = $self->{_mfhdc_ENUMS}->{$key};
 	return 0 if defined $enum->{COUNT} || defined $enum->{RESTART};
     }
 
-    return (exists $self->{PATTERN}->{w} && exists $self->{PATTERN}->{y});
+    return (exists $self->{_mfhdc_PATTERN}->{w} && exists $self->{_mfhdc_PATTERN}->{y});
 }
 
 my %daynames = (
@@ -325,7 +343,7 @@
     my $pubcode = shift;
     my @date = @_;
 
-    foreach my $regularity ($self->{PATTERN}->{y}) {
+    foreach my $regularity ($self->{_mfhdc_PATTERN}->{y}) {
 	next unless $regularity =~ m/^$pubcode/;
 
 	my $chroncode= substr($regularity, 1, 1);

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm	2009-03-12 18:35:05 UTC (rev 12499)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm	2009-03-12 20:11:29 UTC (rev 12500)
@@ -7,54 +7,53 @@
 
 use Data::Dumper;
 
-use MARC::Record;
+use MARC::Field;
 
+our @ISA = qw(MARC::Field);
+
 sub new {
     my $proto = shift;
     my $class = ref($proto) || $proto;
     my $seqno = shift;
-    my $holding = shift;
+    my $self = shift;
     my $caption = shift;
-    my $self = {};
     my $last_enum = undef;
 
-    $self->{SEQNO} = $seqno;
-    $self->{HOLDING} = $holding;
-    $self->{CAPTION} = $caption;
-    $self->{SUBFIELDS} = {};
-    $self->{DESCR} = {};
-    $self->{COPY} = undef;
-    $self->{BREAK} = undef;
-    $self->{NOTES} = {};
-    $self->{COPYRIGHT} = [];
+    $self->{_mfhdh_SEQNO} = $seqno;
+    $self->{_mfhdh_CAPTION} = $caption;
+    $self->{_mfhdh_DESCR} = {};
+    $self->{_mfhdh_COPY} = undef;
+    $self->{_mfhdh_BREAK} = undef;
+    $self->{_mfhdh_NOTES} = {};
+    $self->{_mfhdh_COPYRIGHT} = [];
 
-    foreach my $subfield ($holding->subfields) {
+    foreach my $subfield ($self->subfields) {
 	my ($key, $val) = @$subfield;
 	if ($key =~ /[a-h]/) {
 	    # Enumeration details of holdings
-	    $self->{SUBFIELDS}->{$key} = {HOLDINGS => $val,
-				     UNIT     => undef,};
+	    $self->{_mfhdh_SUBFIELDS}->{$key} = {HOLDINGS => $val,
+						 UNIT     => undef,};
 	    $last_enum = $key;
 	} elsif ($key =~ /[i-m]/) {
-	    $self->{SUBFIELDS}->{$key} = $val;
-	    if (!exists $caption->{CHRONS}->{$key}) {
+	    $self->{_mfhdh_SUBFIELDS}->{$key} = $val;
+	    if (!$caption->capstr($key)) {
 		warn "Holding '$seqno' specified enumeration level '$key' not included in caption $caption->{LINK}";
 	    }
 	} elsif ($key eq 'o') {
 	    warn '$o specified prior to first enumeration'
 	      unless defined($last_enum);
-	    $self->{SUBFIELDS}->{$last_enum}->{UNIT} = $val;
+	    $self->{_mfhdh_SUBFIELDS}->{$last_enum}->{UNIT} = $val;
 	    $last_enum = undef;
 	} elsif ($key =~ /[npq]/) {
-	    $self->{DESCR}->{$key} = $val;
+	    $self->{_mfhdh_DESCR}->{$key} = $val;
 	} elsif ($key eq 's') {
-	    push @{$self->{COPYRIGHT}}, $val;
+	    push @{$self->{_mfhdh_COPYRIGHT}}, $val;
 	} elsif ($key eq 't') {
-	    $self->{COPY} = $val;
+	    $self->{_mfhdh_COPY} = $val;
 	} elsif ($key eq 'w') {
 	    carp "Unrecognized break indicator '$val'"
 	      unless $val =~ /^[gn]$/;
-	    $self->{BREAK} = $val;
+	    $self->{_mfhdh_BREAK} = $val;
 	}
     }
 
@@ -62,9 +61,21 @@
     return $self;
 }
 
+sub seqno {
+    my $self = shift;
+
+    return $self->{_mfhdh_SEQNO};
+}
+
+sub caption {
+    my $self = shift;
+
+    return $self->{_mfhdh_CAPTION};
+}
+
 sub format_chron {
     my $self = shift;
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
     my @keys;
     my $str = '';
     my %month = ( '01' => 'Jan.', '02' => 'Feb.', '03' => 'Mar.',
@@ -81,9 +92,9 @@
 	my $chron;
 	my $sep;
 
-	last if !defined $caption->caption($key);
+	last if !defined $caption->capstr($key);
 
-	$capstr = $caption->caption($key);
+	$capstr = $caption->capstr($key);
 	if (substr($capstr,0,1) eq '(') {
 	    # a caption enclosed in parentheses is not displayed
 	    $capstr = '';
@@ -92,10 +103,10 @@
 	# If this is the second level of chronology, then it's
 	# likely to be a month or season, so we should use the
 	# string name rather than the number given.
-	if (($i == 1) && exists $month{$self->{SUBFIELDS}->{$key}}) {
-	    $chron = $month{$self->{SUBFIELDS}->{$key}};
+	if (($i == 1) && exists $month{$self->{_mfhdh_SUBFIELDS}->{$key}}) {
+	    $chron = $month{$self->{_mfhdh_SUBFIELDS}->{$key}};
 	} else {
-	    $chron = $self->{SUBFIELDS}->{$key};
+	    $chron = $self->{_mfhdh_SUBFIELDS}->{$key};
 	}
 
 
@@ -107,7 +118,7 @@
 
 sub format {
     my $self = shift;
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
     my $str = "";
 
     if ($caption->enumeration_is_chronology) {
@@ -125,53 +136,53 @@
 	    my $chron;
 	    my $sep;
 
-	    last if !defined $caption->caption($key);
+	    last if !defined $caption->capstr($key);
 
-	    # 	printf("fmt %s: '%s'\n", $key, $caption->caption($key));
+	    # 	printf("fmt %s: '%s'\n", $key, $caption->capstr($key));
 
-	    $capstr = $caption->caption($key);
+	    $capstr = $caption->capstr($key);
 	    if (substr($capstr, 0, 1) eq '(') {
 		# a caption enclosed in parentheses is not displayed
 		$capstr = '';
 	    }
-	    $str .= ($key eq 'a' ? "" : ':') . $capstr . $self->{SUBFIELDS}->{$key}->{HOLDINGS};
+	    $str .= ($key eq 'a' ? "" : ':') . $capstr . $self->{_mfhdh_SUBFIELDS}->{$key}->{HOLDINGS};
 	}
 
 	# Chronology
-	if (defined $caption->caption('i')) {
+	if (defined $caption->capstr('i')) {
 	    $str .= '(';
 	    $str .= $self->format_chron('i'..'l');
 	    $str .= ')';
 	}
 
-	if (exists $caption->{ENUMS}->{'g'}) {
+	if ($caption->capstr('g')) {
 	    # There's at least one level of alternative enumeration
 	    $str .= '=';
 	    foreach my $key ('g', 'h') {
-		$str .= ($key eq 'g' ? '' : ':') . $caption->caption($key) . $self->{SUBFIELDS}->{$key}->{HOLDINGS};
+		$str .= ($key eq 'g' ? '' : ':') . $caption->capstr($key) . $self->{_mfhdh_SUBFIELDS}->{$key}->{HOLDINGS};
 	    }
 
 	    # This assumes that alternative chronology is only ever
 	    # provided if there is an alternative enumeration.
-	    if (exists $caption->{CHRONS}->{m}) {
+	    if ($caption->capstr('m')) {
 		# Alternative Chronology
 		$str .= '(';
-		$str .= $caption->caption('m') . $self->{SUBFIELDS}->{m}->{HOLDINGS};
+		$str .= $caption->capstr('m') . $self->{_mfhdh_SUBFIELDS}->{m}->{HOLDINGS};
 		$str .= ')';
 	    }
 	}
     }
 
     # Public Note
-    $str .= ' '. $caption->{ENUMS}->{'z'} if (defined $caption->caption('z'));
+    $str .= ' '. $caption->capstr('z') if (defined $caption->capstr('z'));
 
     # Breaks in the sequence
-    if ($self->{BREAK} eq 'n') {
+    if ($self->{_mfhdh_BREAK} eq 'n') {
 	$str .= ' non-gap break';
-    } elsif ($self->{BREAK} eq 'g') {
+    } elsif ($self->{_mfhdh_BREAK} eq 'g') {
 	$str .= ' gap';
-    } elsif ($self->{BREAK}) {
-	warn "unrecognized break indicator '$self->{BREAK}'";
+    } elsif ($self->{_mfhdh_BREAK}) {
+	warn "unrecognized break indicator '$self->{_mfhdh_BREAK}'";
     }
 
     return $str;
@@ -257,14 +268,14 @@
     my @new;
     my $incr;
 
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
     my $reg = $caption->{REGULARITY};
     my $pattern = $caption->{PATTERN};
     my $freq = $pattern->{w};
 
     foreach my $i (0.. at keys) {
-	$new[$i] = $cur[$i] = $self->{SUBFIELDS}->{$keys[$i]}
-	  if exists $self->{SUBFIELDS}->{$keys[$i]};
+	$new[$i] = $cur[$i] = $self->{_mfhdh_SUBFIELDS}->{$keys[$i]}
+	  if exists $self->{_mfhdh_SUBFIELDS}->{$keys[$i]};
     }
 
     if (is_combined($new[-1])) {
@@ -289,19 +300,19 @@
 sub next_alt_enum {
     my $self = shift;
     my $next = shift;
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
 
     # First handle any "alternative enumeration", since they're
     # a lot simpler, and don't depend on the the calendar
     foreach my $key ('h', 'g') {
 	next if !exists $next->{$key};
-	if (!exists $caption->{ENUMS}->{$key}) {
+	if (!$caption->capstr($key)) {
 	    warn "Holding data exists for $key, but no caption specified";
 	    $next->{$key} += 1;
 	    last;
 	}
 
-	my $cap = $caption->{ENUMS}->{$key};
+	my $cap = $caption->capfield($key);
 	if ($cap->{RESTART} && $cap->{COUNT}
 	    && ($next->{$key} == $cap->{COUNT})) {
 	    $next->{$key} = 1;
@@ -315,7 +326,7 @@
 sub next_enum {
     my $self = shift;
     my $next = shift;
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
     my $carry;
 
     # $carry keeps track of whether we need to carry into the next
@@ -331,7 +342,7 @@
     $carry = 0;
     foreach my $key (reverse('b'.. 'f')) {
 	next if !exists $next->{$key};
-	if (!exists $caption->{ENUMS}->{$key}) {
+	if (!$caption->capstr($key)) {
 	    # Just assume that it increments continuously and give up
 	    warn "Holding data exists for $key, but no caption specified";
 	    $next->{$key} += 1;
@@ -339,7 +350,7 @@
 	    last;
 	}
 
-	my $cap = $caption->{ENUMS}->{$key};
+	my $cap = $caption->capfield($key);
 	if ($cap->{RESTART} && $cap->{COUNT}
 	    && ($next->{$key} eq $cap->{COUNT})) {
 	    $next->{$key} = 1;
@@ -362,7 +373,7 @@
     # 2) Increment the highest level of enumeration (either by date
     #    or because $carry is set because of the above loop
 
-    if (!%{$caption->{CHRONS}}) {
+    if (!%{$caption->{_mfhdc_CHRONS}}) {
 	# The simple case: if there is no chronology specified
 	# then just check $carry and return
 	$next->{'a'} += $carry;
@@ -379,20 +390,20 @@
 #
 sub next {
     my $self = shift;
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
     my $next = {};
     my $carry;
 
     # Initialize $next with current enumeration & chronology, then
     # we can just operate on $next, based on the contents of the caption
     foreach my $key ('a' .. 'h') {
-	$next->{$key} = $self->{SUBFIELDS}->{$key}->{HOLDINGS}
-	  if exists $self->{SUBFIELDS}->{$key};
+	$next->{$key} = $self->{_mfhdh_SUBFIELDS}->{$key}->{HOLDINGS}
+	  if exists $self->{_mfhdh_SUBFIELDS}->{$key};
     }
 
     foreach my $key ('i'..'m') {
-	$next->{$key} = $self->{SUBFIELDS}->{$key}
-	  if exists $self->{SUBFIELDS}->{$key};
+	$next->{$key} = $self->{_mfhdh_SUBFIELDS}->{$key}
+	  if exists $self->{_mfhdh_SUBFIELDS}->{$key};
     }
 
     if ($caption->enumeration_is_chronology) {
@@ -417,7 +428,7 @@
 sub match {
     my $self = shift;
     my $pat = shift;
-    my $caption = $self->{CAPTION};
+    my $caption = $self->{_mfhdh_CAPTION};
 
     foreach my $key ('a'..'f') {
 	my $nextkey;
@@ -426,14 +437,14 @@
 	# If the next smaller enumeration exists, and is numbered
 	# continuously, then we don't need to check this one, because
 	# gaps in issue numbering matter, not changes in volume numbering
-	next if (exists $self->{SUBFIELDS}->{$nextkey}
-		 && !$caption->{ENUMS}->{$nextkey}->{RESTART});
+	next if (exists $self->{_mfhdh_SUBFIELDS}->{$nextkey}
+		 && !$caption->capfield($nextkey)->{RESTART});
 
 	# If a subfield exists in $self but not in $pat, or vice versa
 	# or if the field has different values, then fail
-	if (exists($self->{SUBFIELDS}->{$key}) != exists($pat->{$key})
+	if (exists($self->{_mfhdh_SUBFIELDS}->{$key}) != exists($pat->{$key})
 	    || (exists $pat->{$key}
-		&& ($self->{SUBFIELDS}->{$key}->{HOLDINGS} ne $pat->{$key}))) {
+		&& ($self->{_mfhdh_SUBFIELDS}->{$key}->{HOLDINGS} ne $pat->{$key}))) {
 	    return 0;
 	}
     }
@@ -447,8 +458,8 @@
 sub validate {
     my $self = shift;
 
-    foreach my $key (keys %{$self->{SUBFIELDS}}) {
-	if (!exists $self->{CAPTION}->{ENUMS}->{$key}) {
+    foreach my $key (keys %{$self->{_mfhdh_SUBFIELDS}}) {
+	if (!$self->{_mfhdh_CAPTION}->capfield($key)) {
 	    return 0;
 	}
     }

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt	2009-03-12 18:35:05 UTC (rev 12499)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt	2009-03-12 20:11:29 UTC (rev 12500)
@@ -45,6 +45,9 @@
 *** Monthly, iss # restarts, Cal. change: Jan, Combined iss: 5/6 May/Jun, 7/8 Jul/Aug 
 853 ## $815$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08$yce25/6,7/8
 
+*** Monthly, iss # restarts, Cal change: Jan, July issue omitted
+853 ## $816$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$yom07
+
 ** Calculating the publication info for the next issue
 *** Calcuating enumeration (volume, issue)
 **** current issue is 'normal'

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm	2009-03-12 18:35:05 UTC (rev 12499)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm	2009-03-12 20:11:29 UTC (rev 12500)
@@ -8,31 +8,36 @@
 use MFHD::Caption;
 use MFHD::Holding;
 
+our @ISA;
+
+ at ISA = qw(MARC::Record);
+
 sub new {
     my $proto = shift;
     my $class = ref($proto) || $proto;
-    my $self = {};
-    my $rec = shift;
+    my $self = shift;
 
-    $self->{RECORD} = $rec;
-    $self->{CAPTIONS} = {};
-    $self->{COMPRESSIBLE} = (substr($rec->leader, 17, 1) =~ /[45]/);
+    $self->{_mfhd_CAPTIONS} = {};
+    $self->{_mfhd_COMPRESSIBLE} = (substr($self->leader, 17, 1) =~ /[45]/);
 
     foreach my $field ('853', '854', '855') {
 	my $captions = {};
-	foreach my $caption ($rec->field($field)) {
+	foreach my $caption ($self->field($field)) {
 	    my $cap_id;
 
 	    $cap_id = $caption->subfield('8') || '0';
+	    print "handling caption '$cap_id'\n";
+
 	    if (exists $captions->{$cap_id}) {
-		carp "Multiple unlabelled MFHD captions";
+		carp "Multiple MFHD captions with label '$cap_id'";
 	    }
+
 	    $captions->{$cap_id} = new MFHD::Caption($caption);
-	    if ($self->{COMPRESSIBLE}) {
-		$self->{COMPRESSIBLE} &&= $captions->{$cap_id}->compressible;
+	    if ($self->{_mfhd_COMPRESSIBLE}) {
+		$self->{_mfhd_COMPRESSIBLE} &&= $captions->{$cap_id}->compressible;
 	    }
 	}
-	$self->{CAPTIONS}->{$field} = $captions;
+	$self->{_mfhd_CAPTIONS}->{$field} = $captions;
     }
 
     foreach my $field ('863', '864', '865') {
@@ -41,9 +46,8 @@
 
 	($cap_field = $field) =~ s/6/5/;
 
-	foreach my $hfield ($rec->field($field)) {
-	    my $linkage;
-	    my ($link_id, $seqno);
+	foreach my $hfield ($self->field($field)) {
+	    my ($linkage, $link_id, $seqno);
 	    my $holding;
 
 	    $linkage = $hfield->subfield('8');
@@ -53,14 +57,14 @@
 		$holdings->{$link_id} = {};
 	    }
 	    $holding = new MFHD::Holding($seqno, $hfield,
-					 $self->{CAPTIONS}->{$cap_field}->{$link_id});
+					 $self->{_mfhd_CAPTIONS}->{$cap_field}->{$link_id});
 	    $holdings->{$link_id}->{$seqno} = $holding;
 
-	    if ($self->{COMPRESSIBLE}) {
-		$self->{COMPRESSIBLE} &&= $holding->validate;
+	    if ($self->{_mfhd_COMPRESSIBLE}) {
+		$self->{_mfhd_COMPRESSIBLE} &&= $holding->validate;
 	    }
 	}
-	$self->{HOLDINGS}->{$field} = $holdings;
+	$self->{_mfhd_HOLDINGS}->{$field} = $holdings;
     }
 
     bless ($self, $class);
@@ -70,14 +74,14 @@
 sub compressible {
     my $self = shift;
 
-    return $self->{COMPRESSIBLE};
+    return $self->{_mfhd_COMPRESSIBLE};
 }
 
 sub captions {
     my $self = shift;
     my $field = shift;
 
-    return sort keys %{$self->{CAPTIONS}->{$field}}
+    return sort keys %{$self->{_mfhd_CAPTIONS}->{$field}}
 }
 
 sub holdings {
@@ -85,7 +89,7 @@
     my $field = shift;
     my $capid = shift;
 
-    return sort {$a->{SEQNO} <=> $b->{SEQNO}} values %{$self->{HOLDINGS}->{$field}->{$capid}};
+    return sort {$a->seqno <=> $b->seqno} values %{$self->{_mfhd_HOLDINGS}->{$field}->{$capid}};
 }
 
 1;



More information about the open-ils-commits mailing list