Add ability to catch Encode.xs failures on UTF8 bad leaders.
authorRobin H. Johnson <rjohnson@sitka.bclibraries.ca>
Mon, 31 Oct 2011 07:54:33 +0000 (00:54 -0700)
committerRobin H. Johnson <rjohnson@sitka.bclibraries.ca>
Mon, 31 Oct 2011 07:54:33 +0000 (00:54 -0700)
marc_export_custom/marc_export_custom

index f15dd16..e153acc 100755 (executable)
@@ -256,15 +256,29 @@ sub export_record {
             );
         }
 
+        my $recordstr = undef;
+
         if ($format eq 'XML') {
             my $xml = $r->as_xml_record;
             $xml =~ s/^<\?.+?\?>$//mo;
-            print $outfh $xml;
+            $recordstr = $xml;
         } elsif ($format eq 'UNIMARC') {
-            print $outfh $r->as_usmarc;
+            $recordstr = $r->as_usmarc;
         } elsif ($format eq 'USMARC') {
-            print $outfh $r->as_usmarc;
+            $recordstr = $r->as_usmarc;
         }
+        eval {
+            if($format eq  'UNIMARC' or $format eq 'USMARC') {
+                my $rec = MARC::File::USMARC->decode($recordstr);
+                #throw Error::Simple('Reparsed MARC is not identical') if($recordstr ne $rec->as_usmarc);
+            } elsif($format eq 'XML') {
+                my $rec = MARC::Record->new_from_xml($recordstr, 'utf8', 'UNIMARC');
+                #my $tmp = $rec->as_xml_record;
+                #$tmp =~ s/^<\?.+?\?>$//mo;
+                #throw Error::Simple('Reparsed XML is not identical') if($tmp ne $recordstr);
+            }
+        } or throw Error::Simple("Failed to parse MARC record back: $!");
+        print $outfh $recordstr;
 
         $count{did}++;