#!/usr/local/bin/perl
use strict;
use warnings;
use PAUSE::Users;
use Text::Table::Tiny qw/ generate_table /;

die "usage: $0 <user-id>\n" unless @ARGV > 0;

my %requested = map { (uc($_) => 1) } @ARGV;
my $users     = PAUSE::Users->new(max_age => '1 day');
my $iterator  = $users->user_iterator();
my @rows;

binmode(STDOUT, ':utf8');

while (defined(my $user = $iterator->next_user)) {
    if ($requested{ $user->id }) {
        push(@rows, [$user->id.":",
                     $user->asciiname // $user->fullname,
                     "<".($user->email // 'no-email-address').">"]);
        delete $requested{ $user->id };
    }
    if (keys %requested == 0) {
        print generate_table(rows => \@rows, style => 'norule',
                             top_and_tail => 1, align => [qw/ r l l /]), "\n";
        exit 0;
    }
}

my $missing = join ", ", keys %requested;

die sprintf("User%s not found: %s\n",
            keys %requested > 1 ? "s" : "",
            $missing);

=encoding utf8

=head1 NAME

cpan-whois - display details of one or more CPAN authors

=head1 SYNOPSIS

 cpan-whois <pause-id> [id2 .. idN]

=head1 DESCRIPTION

B<cpan-whois> takes one or more PAUSE usernames and displays the public
information known for the account(s).
By default just the name and email address are displayed:

 % cpan-whois manwar
 MANWAR:   Mohammad Sajid Anwar   <mohammad.anwar@yahoo.com>

If the user's name includes non-ASCII characters,
then PAUSE has an ASCII Name field as well.
If that is set for the user, then it will be displayed as well:

 % cpan-whois kxj
 KXJ: Jing Kang - 康 小靖 (Jing Kang - Kang Xiao Jing) <kxj@cpan.org>

In a future version, I'll add a B<-a> option, to display other information.
Feel free to submit a pull request for that :-)

=head1 REPOSITORY

L<https://github.com/neilb/Pause-Users>

=head1 AUTHOR

Neil Bowers E<lt>neil@bowers.com<gt>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Neil Bowers <neil@bowers.com>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
