App-Lastmsg

 view release on metacpan or  search on metacpan

lib/App/Lastmsg.pm  view on Meta::CPAN

use strict;
use warnings;

use Config::Auto;
$Config::Auto::DisablePerl = 1;
use Date::Parse;
use Email::Folder;
use List::Util qw/max/;
use POSIX qw/strftime/;

our $OUTPUT_FILEHANDLE = \*STDOUT;
our $VERSION = '0.002001';

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;

lib/App/Lastmsg.pm  view on Meta::CPAN

			}
			$process_message->($msg, @people);
		}
	}

	my $idlen   = max map { length } keys %track;
	my $addrlen = max map { length } values %lastaddr;

	for (sort { $lastmsg{$b} <=> $lastmsg{$a} } keys %lastmsg) {
		my $time = format_time $lastmsg{$_};
		printf $OUTPUT_FILEHANDLE "%-${idlen}s %-${addrlen}s %s\n", $_, $lastaddr{$_}, $time;
	}

	for (grep { !exists $lastmsg{$_} } sort keys %track) {
		printf $OUTPUT_FILEHANDLE "%-${idlen}s %-${addrlen}s NOT FOUND\n", $_, ''
	}
}

1;
__END__

=encoding utf-8

=head1 NAME

t/App-Lastmsg.t  view on Meta::CPAN

BEGIN { use_ok('App::Lastmsg') };

{
	no warnings 'redefine';
	*App::Lastmsg::format_time = sub { shift };
}

chdir 't';
my $out = '';
open my $fh, '>', \$out or die "$!";
$App::Lastmsg::OUTPUT_FILEHANDLE = $fh;
$0 = 'lastmsg';
App::Lastmsg::run;

is $out, <<'EOF', 'output is correct';
user2 user2@example.org 1483182600
user1 user1@example.com 1483105440
user3                   NOT FOUND
EOF

$ENV{LASTMSG_DEBUG} = 1;



( run in 0.406 second using v1.01-cache-2.11-cpan-c6e0e5ac2a7 )