sbotools2

Maintenance fork of the original sbotools version 2
Log | Files | Refs | README

commit 223ad71044440c87257d8dfa5d43d1ade78bc764
parent d44ddf7b6cf98d3bfc1e65ec9600061c8407cc91
Author: Andreas Guldstrand <andreas.guldstrand@gmail.com>
Date:   Mon, 29 Aug 2016 00:05:25 +0200

SBO::Lib::Util: read_config can use slurp()

Diffstat:
MSBO-Lib/lib/SBO/Lib/Util.pm | 23++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)

diff --git 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'; }