From 223ad71044440c87257d8dfa5d43d1ade78bc764 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Mon, 29 Aug 2016 00:05:25 +0200 Subject: SBO::Lib::Util: read_config can use slurp() --- SBO-Lib/lib/SBO/Lib/Util.pm | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'SBO-Lib/lib/SBO/Lib/Util.pm') diff --git a/SBO-Lib/lib/SBO/Lib/Util.pm b/SBO-Lib/lib/SBO/Lib/Util.pm index 52b1a9d..efc40b6 100644 --- a/SBO-Lib/lib/SBO/Lib/Util.pm +++ b/SBO-Lib/lib/SBO/Lib/Util.pm @@ -354,23 +354,16 @@ There is no useful return value. # subroutine to suck in config in order to facilitate unit testing sub read_config { - my %conf_values; - if (-f $conf_file) { - _race::cond('$conf_file might not exist after -f'); - my ($fh, $exit) = open_read($conf_file); - if ($exit) { - warn $fh; - $config{SBO_HOME} = '/usr/sbo'; - return; + my $text = slurp($conf_file); + if (defined $text) { + my %conf_values = $text =~ /^(\w+)=(.*)$/mg; + for my $key (keys %config) { + $config{$key} = $conf_values{$key} if exists $conf_values{$key}; } - my $text = do {local $/; <$fh>}; - %conf_values = $text =~ /^(\w+)=(.*)$/mg; - close $fh; - } - for my $key (keys %config) { - $config{$key} = $conf_values{$key} if exists $conf_values{$key}; + $config{JOBS} = 'FALSE' unless $config{JOBS} =~ /^\d+$/; + } else { + warn "Unable to open $conf_file.\n"; } - $config{JOBS} = 'FALSE' unless $config{JOBS} =~ /^\d+$/; $config{SBO_HOME} = '/usr/sbo' if $config{SBO_HOME} eq 'FALSE'; } -- cgit v1.2.3