App-lcpan-CmdBundle-namespace
view release on metacpan or search on metacpan
lib/App/lcpan/Cmd/namespace_authors.pm view on Meta::CPAN
package App::lcpan::Cmd::namespace_authors;
use 5.010001;
use strict;
use warnings;
require App::lcpan;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2024-01-09'; # DATE
our $DIST = 'App-lcpan-CmdBundle-namespace'; # DIST
our $VERSION = '0.001'; # VERSION
our %SPEC;
$SPEC{handle_cmd} = {
v => 1.1,
summary => "Given a namespace, list authors in that namespace sorted by module count",
args => {
%App::lcpan::common_args,
namespace => {
schema => ['perl::modname*'],
req => 1,
pos => 0,
completion => \&App::lcpan::_complete_ns,
},
},
};
sub handle_cmd {
my %args = @_;
my $state = App::lcpan::_init(\%args, 'ro');
my $dbh = $state->{dbh};
my $sth = $dbh->prepare("SELECT num_modules FROM namespace WHERE name=?");
$sth->execute($args{namespace});
my $row = $sth->fetchrow_arrayref or return [404, "No such namespace"];
my $num_modules = $row->[0];
return [200, "OK", []] unless $num_modules;
$sth = $dbh->prepare("SELECT cpanid AS author,COUNT(*) AS num_modules, 100.0*COUNT(*)/$num_modules AS pct_modules FROM module WHERE name LIKE '$args{namespace}\::%' GROUP BY cpanid ORDER BY num_modules DESC");
$sth->execute;
my @rows;
while (my $row = $sth->fetchrow_hashref) { $row->{pct_modules} = sprintf "%.2f", $row->{pct_modules}; push @rows, $row }
[200, "OK", \@rows];
}
1;
# ABSTRACT: Given a namespace, list authors in that namespace sorted by module count
__END__
=pod
=encoding UTF-8
=head1 NAME
App::lcpan::Cmd::namespace_authors - Given a namespace, list authors in that namespace sorted by module count
=head1 VERSION
This document describes version 0.001 of App::lcpan::Cmd::namespace_authors (from Perl distribution App-lcpan-CmdBundle-namespace), released on 2024-01-09.
=head1 DESCRIPTION
This module handles the L<lcpan> subcommand C<namespace-authors>.
=head1 FUNCTIONS
=head2 handle_cmd
Usage:
handle_cmd(%args) -> [$status_code, $reason, $payload, \%result_meta]
Given a namespace, list authors in that namespace sorted by module count.
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<index_name> => I<filename> (default: "index.db")
Filename of index.
( run in 2.025 seconds using v1.01-cache-2.11-cpan-788537b7465 )