From 40186ccfe3cc08aaacc5ce9f1cac0f55658e97bc Mon Sep 17 00:00:00 2001 From: Jens Steidl <Jens.Steidl@slub-dresden.de> Date: Thu, 15 Oct 2020 16:39:34 +0200 Subject: [PATCH] - refactor: encapsulated title check --- bin/slubsipbuilderbagit.pl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/slubsipbuilderbagit.pl b/bin/slubsipbuilderbagit.pl index 8122a79..366a3a1 100644 --- a/bin/slubsipbuilderbagit.pl +++ b/bin/slubsipbuilderbagit.pl @@ -47,6 +47,7 @@ package SLUB::LZA::SIPBuilderBagIt; use File::Copy::Recursive qw(dircopy dirmove); use File::Basename; use File::Find; + use List::Util qw(none); use LWP::UserAgent; # to get MARC data use MARC::Record; use Path::Tiny; @@ -568,6 +569,18 @@ PATCH SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($bagPath, \@addBagInfo); } + sub checkForTitle($){ + my $key_hash_list_aref = shift; + # collect all bag-info keys for easy check + my @keys; + for my $hash (@{$key_hash_list_aref}) { + push @keys, keys %{$hash}; + } + # check for title + print_scalar_data("", "WARNING: No Title given. Please consider adding a human-readable title with '--add_key_value=Title:YOUR-TITLE'", "", "yellow") + if none { $_ =~ m/^[Tt][Ii][Tt][Ll][Ee]/ } @keys; + } + # end package package main; @@ -587,7 +600,6 @@ use Getopt::Long; use Path::Tiny; use Carp; # confess() use Pod::Usage; # pod2usage() -use List::Util qw(none); my $save; my $ieDirectory; @@ -768,12 +780,7 @@ sub main{ my $bagNameDir = SLUB::LZA::SIPBuilderBagIt::generateBagName($exportToArchiveDate, $ppn, $noppn); # user hints - my @keys; - for my $hash (@addBagInfo) { - push @keys, keys %{$hash}; - } - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "WARNING: No Title given. Please consider adding a human-readable title with '--add_key_value=Title:YOUR-TITLE'", "", "yellow") - if none { $_ =~ m/^[Tt][Ii][Tt][Ll][Ee]/ } @keys; + SLUB::LZA::SIPBuilderBagIt::checkForTitle(\@addBagInfo); # save options if($save eq "copy") { -- GitLab