[librecat-dev] Error when processing the same file twice

Mayr-Duffner, Georg georg.mayr-duffner at wu.ac.at
Tue Nov 27 21:39:10 CET 2018


Hello,

I‘m trying to set up a web service (with dancer2) that does some Catmandu transformations and I‘m hopelessly stuck. I try to first do a MARC to JSON conversion to get some data out of a MARC input file (which in the end will go into a MongoDB) and then the same input file should be processed again in order to output an enriched MARC file. I can run one or the other but when I try to process both I get an error 

Can't locate object method "new" via package "Catmandu::Exporter::MARC" at /Users/gduffner/perl5/perlbrew/perls/perl-5.26.2/lib/site_perl/5.26.2/Catmandu/Env.pm line 219, <GEN2> line 12.

Could you please help me track that down?

Here’s the code of the subroutine:

post '/cleanupMarc' => sub {
    my $sigel = param('paketSigel');
    my $type  = param('inputFileType');
    my $packagemonth = param('packageMonth');

    my $input = request->upload('inputFile');
    my $uploaddir   = path(config->{appdir}, 'uploads');
    mkdir $uploaddir if not -e $uploaddir;
    my $inputpath  = path($uploaddir, $input->basename);
    $input->copy_to($inputpath);

    my $dldir = path(config->{public_dir}, 'downloads');
    mkdir $dldir if not -e $dldir;

    # marc2json
    my $jsonOutput = "$dldir/output1.json";
 
    my $jsonImporter = Catmandu->importer('MARC', file => $inputpath);#, type => $type);
    
    my $jsonFixer = Catmandu::Fix->new(
        variables => { sigel => $sigel, },
        fixes => ['fixfiles/IDs2json.fix'],
    );
    my $jsonExporter = Catmandu->exporter('JSON', file => $jsonOutput);
    my $fixed_jsonImporter = $jsonFixer->fix($jsonImporter);
    $jsonExporter->add_many($fixed_jsonImporter->benchmark);
    $jsonExporter->commit;
    undef($jsonExporter);
    
    # marc2marc
    my $marcOutput = "$dldir/output.mrc";
    my $marcImporter  = Catmandu->importer('MARC', file => $inputpath);#, type => $type);
    my $marcFixer = Catmandu::Fix->new(
        variables => { sigel => $sigel,
                       MARC2ISO => 'fixfiles/marc2iso3166H.csv',
                       ISO2MARC => 'fixfiles/iso3166H2marc.csv',
                       today => '20181122',},
        fixes => ['fixfiles/ebook.fix'],
    );
    my $marcExporter = Catmandu->exporter('MARC', file => $marcOutput);
    my $fixed_marcImporter = $marcFixer->fix($marcImporter);
    $marcExporter->add_many($fixed_marcImporter->benchmark);
    $marcExporter->commit;
    undef($marcExporter);
    
    redirect('/');
};

Thank you very much!

Best regards
Georg





More information about the librecat-dev mailing list