From 7f898c439eb139537545eda6eb3ccc580ac8460b Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 12 Nov 2008 12:41:37 +0100 Subject: Created VNDB::Func for a few small and often used functions, split CommonHTML in LayoutHTML, and abstracted the browser generation I was planning to commit often, but I still end up doing everything in one commit >.> --- lib/VNDB/Func.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/VNDB/Func.pm (limited to 'lib/VNDB/Func.pm') diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm new file mode 100644 index 00000000..9e948e0d --- /dev/null +++ b/lib/VNDB/Func.pm @@ -0,0 +1,26 @@ + +package VNDB::Func; + +use strict; +use warnings; +use Exporter 'import'; +use POSIX 'strftime'; +our @EXPORT = qw| shorten date |; + + +# I would've done this as a #define if this was C... +sub shorten { + my($str, $len) = @_; + return length($str) > $len ? substr($str, 0, $len-3).'...' : $str; +} + + +# argument: unix timestamp +# return value: yyyy-mm-dd +# (maybe an idea to use cgit-style ages for recent timestamps) +sub date { + return strftime '%Y-%m-%d', gmtime shift; +} + + +1; -- cgit v1.2.3