App-lcpan
view release on metacpan or search on metacpan
lib/App/lcpan/Cmd/dist2author.pm view on Meta::CPAN
package App::lcpan::Cmd::dist2author;
use 5.010001;
use strict;
use warnings;
require App::lcpan;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-09-26'; # DATE
our $DIST = 'App-lcpan'; # DIST
our $VERSION = '1.074'; # VERSION
our %SPEC;
$SPEC{'handle_cmd'} = {
v => 1.1,
summary => 'Get author of distribution(s)',
args => {
%App::lcpan::common_args,
%App::lcpan::dists_args,
},
};
sub handle_cmd {
my %args = @_;
my $state = App::lcpan::_init(\%args, 'ro');
my $dbh = $state->{dbh};
my $dists = $args{dists};
my $dists_s = join(",", map {
my $d=$_; $d =~ s/::/-/g; $dbh->quote($d);
} @$dists);
my $sth = $dbh->prepare("SELECT
f.dist_name dist,
f.cpanid author
FROM file f
WHERE f.dist_name IN ($dists_s)");
my @res;
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
push @res, $row;
}
if (@$dists == 1) {
@res = map { $_->{author} } @res;
if (!@res) {
return [404, "No such dist"];
} elsif (@res == 1) {
return [200, "OK", $res[0]];
} else {
return [200, "OK", \@res];
}
}
[200, "OK", \@res, {'table.fields'=>[qw/dist author/]}];
}
1;
# ABSTRACT: Get author of distribution(s)
__END__
=pod
=encoding UTF-8
=head1 NAME
App::lcpan::Cmd::dist2author - Get author of distribution(s)
=head1 VERSION
This document describes version 1.074 of App::lcpan::Cmd::dist2author (from Perl distribution App-lcpan), released on 2023-09-26.
=head1 FUNCTIONS
=head2 handle_cmd
Usage:
handle_cmd(%args) -> [$status_code, $reason, $payload, \%result_meta]
Get author of distribution(s).
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<cpan> => I<dirname>
Location of your local CPAN mirror, e.g. E<sol>pathE<sol>toE<sol>cpan.
Defaults to C<~/cpan>.
=item * B<dists>* => I<array[perl::distname]>
Distribution names (e.g. Foo-Bar).
=item * B<index_name> => I<filename> (default: "index.db")
Filename of index.
If C<index_name> is a filename without any path, e.g. C<index.db> then index will
be located in the top-level of C<cpan>. If C<index_name> contains a path, e.g.
( run in 2.026 seconds using v1.01-cache-2.11-cpan-fe3c2283af0 )