summaryrefslogtreecommitdiff
path: root/lib/Loadbars/Utils.pm
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2012-04-19 23:30:51 +0200
committerPaul Buetow <paul@buetow.org>2012-04-19 23:30:51 +0200
commit63ffb317c65863f3ba1258bd6ed9278cf4ef0d58 (patch)
tree556ca2a9861c6a2936407f011bff3be8e037aca2 /lib/Loadbars/Utils.pm
parent86c242f505280ee56f8c995bd8099bd4f026b6d3 (diff)
Add module Config and Utils
Diffstat (limited to 'lib/Loadbars/Utils.pm')
-rw-r--r--lib/Loadbars/Utils.pm41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Loadbars/Utils.pm b/lib/Loadbars/Utils.pm
new file mode 100644
index 0000000..bfb8027
--- /dev/null
+++ b/lib/Loadbars/Utils.pm
@@ -0,0 +1,41 @@
+package Loadbars::Utils;
+
+use strict;
+use warnings;
+
+use Exporter;
+
+use base 'Exporter';
+
+our @EXPORT = qw (
+ debugsay
+ display_info
+ display_info_no_nl
+ display_warn
+ newline
+ notnull
+ null
+ say
+ sum
+ trim
+);
+
+sub say (@) { print "$_\n" for @_; return undef }
+sub newline () { say ''; return undef }
+sub debugsay (@) { say "Loadbars::DEBUG: $_" for @_; return undef }
+sub sum (@) { my $sum = 0; $sum += $_ for @_; return $sum }
+sub null ($) { defined $_[0] ? $_[0] : 0 }
+sub notnull ($) { $_[0] != 0 ? $_[0] : 1 }
+sub error ($) { die shift, "\n" }
+
+sub trim (\$) {
+ my $str = shift;
+ $$str =~ s/^[\s\t]+//;
+ $$str =~ s/[\s\t]+$//;
+ return undef;
+}
+sub display_info_no_nl ($) { print "==> " . (shift) . ' ' }
+sub display_info ($) { say "==> " . shift }
+sub display_warn ($) { say "!!! " . shift }
+
+1;