MARCXML=1 enviroment variable will create marcxml
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 4 Dec 2017 16:59:51 +0000 (17:59 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 4 Dec 2017 16:59:51 +0000 (17:59 +0100)
Makefile.PL
bin/install-debian.sh
lib/WebPAC/Output/MARC.pm

index c6499cb..50e9895 100644 (file)
@@ -25,6 +25,7 @@ requires      'Biblio::Isis' => '0.24';
 requires       'MARC::Fast' => '0.12';
 requires       'List::Util';
 requires       'MARC::Record' => '2.0';
+requires       'MARC::File::XML';
 requires       'Data::Dump';
 requires       'MARC::Lint' => '1.43';
 requires       'Business::ISBN' => '2.02';     # WebPAC::Normalize::ISBN
index 7eb1033..d549227 100755 (executable)
@@ -2,5 +2,5 @@
 
 sudo apt-get install liblog-log4perl-perl libclass-accessor-perl libyaml-perl libtest-exception-perl \
        libbiblio-isis-perl libmarc-lint-perl libppi-perl libspreadsheet-parseexcel-perl libtext-csv-perl \
-       swish-e libhttp-oai-perl libbusiness-isbn-perl
+       swish-e libhttp-oai-perl libbusiness-isbn-perl libmarc-charset-perl libtest-warn-perl
 
index 89e38fe..00de7cf 100644 (file)
@@ -6,6 +6,7 @@ use strict;
 use base qw/WebPAC::Common/;
 
 use MARC::Record;
+use MARC::File::XML;
 use MARC::Lint;
 use Data::Dump qw/dump/;
 
@@ -60,6 +61,10 @@ sub new {
                binmode($self->{fh}, ':utf8');
 
                $log->info("Creating MARC export file $path", $self->{lint} ? ' (with lint)' : '', " encoding ", $self->{marc_encoding}, "\n");
+               if ( $ENV{MARCXML} ) {
+                       open($self->{fh_marcxml}, '>:utf8', "$path.marcxml");
+                       print {$self->{fh_marcxml}} qq{<?xml version="1.0" encoding="UTF-8"?>\n<collection>\n};
+               }
        } else {
                $log->logconfess("new called without path");
        }
@@ -152,6 +157,11 @@ sub add {
 
        print {$self->{fh}} $marc->as_usmarc;
 
+       if ( $self->{fh_marcxml} ) {
+               my $xml = $marc->as_xml_record;
+               $xml =~ s/\Q<?xml version="1.0" encoding="UTF-8"?>\E//;
+               print {$self->{fh_marcxml}} $xml;
+       }
 }
 
 =head2 finish
@@ -171,6 +181,11 @@ sub finish {
 
        close( $self->{fh} ) or $log->logdie("can't close ", $self->{path}, ": $!");
 
+       if ( $self->{fh_marcxml} ) {
+               print {$self->{fh_marcxml}} qq{</collection>\n};
+               $log->info("MARCXML file size ", -s $self->{fh_marcxml}, " bytes");
+               close( $self->{fh_marcxml} );
+       }
        if (my $w = $self->{_marc_lint_warnings}) {
                $log->error("MARC lint warnings summary:\n",
                        join ("\n",