summaryrefslogtreecommitdiff
path: root/search/lib/Common.pm
diff options
context:
space:
mode:
Diffstat (limited to 'search/lib/Common.pm')
-rw-r--r--search/lib/Common.pm46
1 files changed, 0 insertions, 46 deletions
diff --git a/search/lib/Common.pm b/search/lib/Common.pm
deleted file mode 100644
index 0797943..0000000
--- a/search/lib/Common.pm
+++ /dev/null
@@ -1,46 +0,0 @@
-## utility functions
-package Common;
-use base 'Exporter';
-our @EXPORT = qw[is_number is_string show_date get_age trim strip_html];
-
-# promiscuous namespace
-sub is_number
- { my ($self, $s) = @_; return $s && $s !~ /\D/; }
-sub is_string
- { my ($self, $s) = @_; return length $s && ! length ref $s; }
-sub show_date
- { my ($self, $date) = @_; return scalar localtime($date); }
-sub get_age
- {
- my ($self, $time) = @_;
- if ($time < 0)
- { return "old"; }
- my $age = time - $time;
- if ($age < 60)
- { return int($age)."s"; }
- $age /= 60;
- if ($age < 60)
- { return int($age)."m"; }
- my $mins = $age % 60;
- $age /= 60;
- if ($age < 2)
- { return int($age)."h".int($mins)."m"; }
- elsif ($age < 24)
- { return int($age)."h"; }
- $age /= 24;
- if ($age < 10000)
- { return int($age)."d"; }
- my $powers = qw[k m g t p e z y];
- foreach my $prefix (@$powers)
- {
- $age /= 1000;
- if ($age < 10000)
- { return int($age).$prefix."d"; }
- }
- }
-sub trim
- { my ($self, $s) = @_; $s =~ s/^\s+//; $s =~ s/\s+$//; return $s; }
-sub strip_html
- { my ($self, $s) = @_; $s =~ s/[<>]+/ /g; return $s; }
-
-1;