From 013a3042b8cc657d78c7ccd3b2c3921f90d0e59a Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 4 Dec 2017 17:59:51 +0100 Subject: [PATCH] MARCXML=1 enviroment variable will create marcxml --- Makefile.PL | 1 + bin/install-debian.sh | 2 +- lib/WebPAC/Output/MARC.pm | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile.PL b/Makefile.PL index c6499cb..50e9895 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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 diff --git a/bin/install-debian.sh b/bin/install-debian.sh index 7eb1033..d549227 100755 --- a/bin/install-debian.sh +++ b/bin/install-debian.sh @@ -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 diff --git a/lib/WebPAC/Output/MARC.pm b/lib/WebPAC/Output/MARC.pm index 89e38fe..00de7cf 100644 --- a/lib/WebPAC/Output/MARC.pm +++ b/lib/WebPAC/Output/MARC.pm @@ -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{\n\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\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{\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", -- 2.20.1