App/lcpan/Cmd/dists_by_mod_count.pm

filter: Statementstmt 44.4% 16 / 36 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 40.8% 20 / 49 CC 5 SCAR 29.5
CC
5
Cov
36%
handle_cmd
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 19.1
« App/lcpan/Cmd/dist2author.pm ↑ Summary App/lcpan/Cmd/dists_by_script_count.pm »
1 package App::lcpan::Cmd::dists_by_mod_count;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require App::lcpan;
8  
9 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 1 our $DATE = '2023-09-26'; # DATE
11 1 our $DIST = 'App-lcpan'; # DIST
12 1 our $VERSION = '1.074'; # VERSION
13  
14 1 our %SPEC;
15  
16 1 $SPEC{'handle_cmd'} = {
17 v => 1.1,
18 summary => 'List distributions ranked by number of included modules',
19 args => {
20 %App::lcpan::common_args,
21 %App::lcpan::fauthor_args,
22 n => {
23 summary => 'Return at most this number of results',
24 schema => 'posint*',
25 },
26 },
27 };
28 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=5 SCAR=34.0
Pod documented
29 0 my %args = @_;
30  
31 0 my $state = App::lcpan::_init(\%args, 'ro');
32 0 my $dbh = $state->{dbh};
33  
34 0 my @where;
35 my @binds;
36 0 ▶ if ($args{author}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"author"}) 0 0 0
37 0 push @where, "(file.author=?)";
38 0 push @binds, $args{author};
39 }
40 0 push @where, "file.is_latest_dist";
41 0 ▶ @where = (1) if !@where;
Branch: 1 branch
BranchTrueFalseTotal
unless @where 0 0 0
42  
43 my $sql = "SELECT
44 file.dist_name dist,
45 file.cpanid author,
46 COUNT(DISTINCT module.id) AS mod_count
47 FROM file
48 LEFT JOIN module ON file.id=module.file_id
49 WHERE ".join(" AND ", @where)."
50 GROUP BY file.id
51 ORDER BY mod_count DESC
52 0 ▶".($args{n} ? "LIMIT ".(0+$args{n}) : "");
Branch: 1 branch
BranchTrueFalseTotal
$args{'n'} ? : 0 0 0
53  
54 0 my @res;
55 0 my $sth = $dbh->prepare($sql);
56 0 $sth->execute(@binds);
57 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
58 0 push @res, $row;
59 }
60  
61 0 require Data::TableData::Rank;
62 0 Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => ['mod_count']);
63  
64 0 my $resmeta = {};
65 0 $resmeta->{'table.fields'} = [qw/rank dist author mod_count/];
66 0 [200, "OK", \@res, $resmeta];
67 }
68  
69 1 1;
70 # ABSTRACT: List distributions ranked by number of included modules
71  
72 __END__
« App/lcpan/Cmd/dist2author.pm ↑ Summary App/lcpan/Cmd/dists_by_script_count.pm »