diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl index cd6c5f13e8aa5c7ce98986e0310fc7e203b7df04..7b1519db7e9240c1adcbccb31e317bca2acf59ba 100644 --- a/perl/exit_strategy.pl +++ b/perl/exit_strategy.pl @@ -41,7 +41,9 @@ use strict; use warnings; -use feature "say"; +use feature qw( say signatures ); +no warnings "experimental::signatures"; +use utf8; # for debugging output use Carp; use Path::Tiny; use File::Find; @@ -67,8 +69,7 @@ my $sourcetype="hdd"; #default value # if IE.xml file found, read its metadata, create SQL add entry # write SQL add entry ############################################################################### -sub write_database_creation ($) { - my $fh = shift; +sub write_database_creation ($fh) { # non standard conform SQL keywords #say $fh "CREATE DATABASE $db_name;"; #say $fh "CREATE SCHEMA $schema_name;"; @@ -77,8 +78,7 @@ sub write_database_creation ($) { } # write tables creation;: -sub write_tables_creation ($) { - my $fh = shift; +sub write_tables_creation ($fh) { # Transactions for tables creation say $fh "BEGIN;"; @@ -131,8 +131,7 @@ sub write_tables_creation ($) { ############################################################################### # Prepare SQL INSERT Statements for AIPs ############################################################################### -sub write_prepare_insert ($) { - my $fh = shift; +sub write_prepare_insert ($fh) { say $fh "BEGIN;"; say $fh "PREPARE aip_plan (varchar) AS"; say $fh " INSERT INTO aip (ie_id) VALUES (\$1);"; @@ -180,9 +179,7 @@ sub write_prepare_insert ($) { # $ret{"files"} = \@files; # $ret{"dcrecords"} = \@dcrecords; ############################################################################### -sub write_addsql ($$) { - my $fh = shift; - my $refhash = shift; +sub write_addsql ($fh, $refhash) { my $ieid = path($refhash->{"filename"})->basename(qw/.xml/); say $fh "BEGIN;"; say $fh "EXECUTE aip_plan ('$ieid');"; @@ -210,8 +207,7 @@ sub write_addsql ($$) { ############################################################################### # add INDEX and other TRICKs to increase performance ############################################################################### -sub write_index_creation($) { - my $fh = shift; +sub write_index_creation($fh) { say $fh "-- BEGIN;"; say $fh "-- CREATE UNIQUE INDEX aip_index on aip (ie_id);"; say $fh "-- COMMIT;"; @@ -222,9 +218,7 @@ sub write_index_creation($) { # checks if a given string from from a given file contains only utf-8 chars # which are compatible to common used databases ############################################################################### -sub check_if_db_conform ($$) { - my $string = "$_[0]"; - my $filename = $_[1]; +sub check_if_db_conform ($string, $filename) { if ($string ne '') { if ( not utf8::is_utf8($string)) { croak "no utf8: '$string' in file '$filename'\n"; @@ -276,41 +270,31 @@ sub check_if_db_conform ($$) { my $str_repid_old = "/mets:mets/mets:amdSec[starts-with(\@ID, \'REP\') and $str_local_reps]/\@ID"; my $compiled_xpath_repid_old = XML::LibXML::XPathExpression->new($str_repid_old); ############################################################ - sub get_title { - my $xp = shift; - my $filename = shift; + sub get_title ($xp, $filename){ # get title my $title = $xp->findvalue($compiled_xpath_titles); check_if_db_conform($title, $filename); return $title; } - sub get_dcrecords_ref { - my $xp = shift; - my $filename = shift; - my @dcrecords; + sub get_dcrecords_ref ($xp, $filename){ my @dcnodes = $xp->findnodes($compiled_xpath_dcrecords); - foreach my $dcnode (@dcnodes) { - #my $ref = ref $dcnode; use Data::Printer; p( $ref); - my $key = $dcnode->getName(); - #my $value = $dcnode->findvalue($compiled_xpath_dot); - my $value = $dcnode->nodeValue; - if (defined $value) { - $value =~ s/\n/ /g; - $value =~ s/'/\\'/g; - check_if_db_conform($value, $filename); - my @pair; - push @pair, $key; - push @pair, $value; - push @dcrecords, \@pair; - } - } - return \@dcrecords; + my @dcrecords = map { + $_->[1]=~ s/\n/ /g; + $_->[1] =~ s/'/\\'/g; + check_if_db_conform($_->[1], $filename); + $_; + } grep { + defined $_->[0] && + defined $_->[1]; + } map { + # array ref + [$_->getName, $_->textContent]; + } @dcnodes; + return \@dcrecords; } - sub get_repid { - my $xp = shift; - my $filename = shift; + sub get_repid ($xp, $filename){ my $repid; my @repnodes = $xp->findnodes($compiled_xpath_repid); #/mets:mets/mets:amdSec/@ID my $found = scalar @repnodes; @@ -324,18 +308,13 @@ sub check_if_db_conform ($$) { return $repid; } - sub get_files_ref { - my $xp = shift; - my $filename = shift; - my $repid = shift; + sub get_files_ref ($xp, $filename, $repid){ my @files_nodes = $xp->findnodes("mets:mets/mets:fileSec/mets:fileGrp[\@ADMID='$repid']/mets:file/mets:FLocat/\@xlin:href"); my @files = map {s#//#/#g; $_} map { $_->nodeValue } @files_nodes; return \@files; } - sub parse_iexml($$) { - my $filename = shift; - my $recovery_flag = shift; + sub parse_iexml($filename, $recovery_flag) { if ($recovery_flag) { $recovery_flag = 2; # avoid warnings, see XML::LibXML::Parser POD about 'recovery' } @@ -392,10 +371,7 @@ sub check_if_db_conform ($$) { # and returns an array reference with reduced files using only highest V-value # HINT, it only operates on sorted file list with fake versions (with zero-filled prefixes) ################################################################################ -sub find_newest_iefile_version ($$$) { - my $files_sorted = shift; - my $files_truncated = shift; - my $cnt_files = shift; +sub find_newest_iefile_version ($files_sorted, $files_truncated, $cnt_files) { my $cnt_truncated = 0; my $fh = $files_sorted->filehandle("<"); my $last_entry; @@ -425,9 +401,7 @@ sub find_newest_iefile_version ($$$) { return $cnt_truncated; } -sub searching_ie_files ($$) { - my $dir = shift; - my $tmp_ies_unsorted_file = shift; +sub searching_ie_files ($dir, $tmp_ies_unsorted_file) { my $cnt_unsorted_files = 0; my $first_two_levels_of_dirs = 0; ###