summaryrefslogtreecommitdiff
path: root/lib/PINGDOMFETCH/Utils.pm
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2015-01-02 13:27:02 +0100
committerPaul Buetow <paul@buetow.org>2015-01-02 13:27:02 +0100
commit336c6c8a415603c772f97ccd63912d05209f3795 (patch)
tree1a0febb81031d77fa8bec857333cce0a6d87436e /lib/PINGDOMFETCH/Utils.pm
initial1.0.0
Diffstat (limited to 'lib/PINGDOMFETCH/Utils.pm')
-rw-r--r--lib/PINGDOMFETCH/Utils.pm72
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/PINGDOMFETCH/Utils.pm b/lib/PINGDOMFETCH/Utils.pm
new file mode 100644
index 0000000..f66792f
--- /dev/null
+++ b/lib/PINGDOMFETCH/Utils.pm
@@ -0,0 +1,72 @@
+package PINGDOMFETCH::Utils;
+
+use strict;
+use warnings;
+
+use Data::Dumper;
+use Exporter;
+
+use base 'Exporter';
+
+our @EXPORT = qw (
+ d
+ dumper
+ get_version
+ get_version_full
+ newline
+ notnull
+ null
+ remove_spaces
+ say
+ sum
+ trim
+);
+
+sub say (@) { print "$_\n" for @_; return undef }
+sub newline () { say ''; return undef }
+sub sum (@) { my $sum = 0; $sum += $_ for @_; return $sum }
+sub null ($) { defined $_[0] ? $_[0] : 0 }
+sub notnull ($) { $_[0] != 0 ? $_[0] : 1 }
+sub dumper (@) { die Dumper @_ }
+sub d (@) { dumper @_ }
+
+sub trim ($) {
+ my $trimit = shift;
+
+ $trimit =~ s/^[\s\t]+//;
+ $trimit =~ s/[\s\t]+$//;
+
+ return $trimit;
+}
+
+sub remove_spaces ($) {
+ my $str = shift;
+
+ $str =~ s/[\s\t]//g;
+
+ return $str;
+}
+
+sub get_version () {
+ my $versionfile = do {
+ if ( -f '.version' ) {
+ '.version';
+ }
+ else {
+ '/usr/share/pingdomfetch/version';
+ }
+ };
+
+ open my $fh, $versionfile or error("$!: $versionfile");
+ my $version = <$fh>;
+ close $fh;
+
+ chomp $version;
+ return $version;
+}
+
+sub get_version_full () {
+ return "This is Pingdomfetch Version " . get_version() . "\n";
+}
+
+1;