aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Guldstrand <andreas.guldstrand@gmail.com>2016-08-28 21:45:11 +0200
committerAndreas Guldstrand <andreas.guldstrand@gmail.com>2016-08-28 21:45:11 +0200
commitd44ddf7b6cf98d3bfc1e65ec9600061c8407cc91 (patch)
treed51fc2a6ed9bc42adaa3032218cca997bc4d4ba2
parent0cbd912240fcfacfae6609d5b3aedc35630dfea2 (diff)
downloadsbotools2-d44ddf7b6cf98d3bfc1e65ec9600061c8407cc91.tar.xz
sboconfig: move slurp() to SBO::Lib::Util, and document it
-rw-r--r--SBO-Lib/lib/SBO/Lib/Util.pm19
-rwxr-xr-xsboconfig11
2 files changed, 20 insertions, 10 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Util.pm b/SBO-Lib/lib/SBO/Lib/Util.pm
index 39bdf65..52b1a9d 100644
--- a/SBO-Lib/lib/SBO/Lib/Util.pm
+++ b/SBO-Lib/lib/SBO/Lib/Util.pm
@@ -48,6 +48,7 @@ our @EXPORT_OK = (
print_failures
script_error
show_version
+ slurp
uniq
usage_error
version_cmp
@@ -419,6 +420,24 @@ sub show_version {
say '<http://sam.zoy.org/wtfpl/COPYING>';
}
+=head2 slurp
+
+ my $data = slurp($fn);
+
+C<slurp()> takes a filename in C<$fn>, opens it, and reads in the entire file,
+the contents of which is then returned. On error, it returns C<undef>.
+
+=cut
+
+sub slurp {
+ my $fn = shift;
+ return undef unless -f $fn;
+ my ($fh, $exit) = open_read($fn);
+ return undef if $exit;
+ local $/;
+ return scalar readline($fh);
+}
+
=head2 uniq
my @uniq = uniq(@duplicates);
diff --git a/sboconfig b/sboconfig
index ca6d1fa..604a816 100755
--- a/sboconfig
+++ b/sboconfig
@@ -13,7 +13,7 @@
use 5.16.0;
use strict;
use warnings FATAL => 'all';
-use SBO::Lib qw/ usage_error script_error $tempdir open_read open_fh %config $conf_dir $conf_file show_version /;
+use SBO::Lib qw/ slurp usage_error script_error $tempdir open_fh %config $conf_dir $conf_file show_version /;
use File::Basename;
use Getopt::Long qw(:config no_ignore_case_always);
use File::Copy;
@@ -158,15 +158,6 @@ sub config_write {
print {$conffh} $conf;
}
-sub slurp {
- my $fn = shift;
- return undef unless -f $fn;
- my ($fh, $exit) = open_read($fn);
- return undef if $exit;
- local $/;
- return scalar readline($fh);
-}
-
# make sure there are no duplicate keys in the config
sub _fixup_conf {
my @lines = split /\n/, $_[0];