]> iEval git - app-lastmsg.git/blobdiff - lib/App/Lastmsg.pm
Make tests pass on systems without %s strftime specifier
[app-lastmsg.git] / lib / App / Lastmsg.pm
index 0addd51d779a3643630b7c1cc24dd5b70436b425..8d2cce57eb09d247c336dcd61711c9ed32a58d0d 100644 (file)
@@ -14,10 +14,11 @@ use POSIX qw/strftime/;
 our $OUTPUT_FILEHANDLE = \*STDOUT;
 our $VERSION = '0.001002';
 
-our @DEFAULT_INBOX = (
-       "/var/mail/$ENV{USER}",
-       "$ENV{HOME}/Maildir/",
-);
+our @DEFAULT_INBOX;
+push @DEFAULT_INBOX, "/var/mail/$ENV{USER}" if exists $ENV{USER};
+push @DEFAULT_INBOX, "$ENV{HOME}/Maildir"   if exists $ENV{HOME};
+
+sub format_time { strftime '%c', localtime shift }
 
 sub run {
        my $config = Config::Auto->new(format => 'yaml')->parse;
@@ -95,7 +96,7 @@ sub run {
        my $addrlen = max map { length } values %lastaddr;
 
        for (sort { $lastmsg{$b} <=> $lastmsg{$a} } keys %lastmsg) {
-               my $time = strftime '%c', localtime $lastmsg{$_};
+               my $time = format_time $lastmsg{$_};
                printf $OUTPUT_FILEHANDLE "%-${idlen}s %-${addrlen}s %s\n", $_, $lastaddr{$_}, $time;
        }
 
This page took 0.020468 seconds and 4 git commands to generate.