App/lcpan/Cmd/authors_by_script_count.pm

filter: Statementstmt 53.3% 16 / 30 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 54.0% 20 / 37 CC 2 SCAR 11.0
CC
2
Cov
50%
handle_cmd
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« App/lcpan/Cmd/authors_by_rel_count.pm ↑ Summary App/lcpan/Cmd/subnames_by_count.pm »
1 package App::lcpan::Cmd::authors_by_script_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 authors ranked by number of scripts',
19 args => {
20 %App::lcpan::common_args,
21 },
22 };
23 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=2 SCAR=17.9
Pod documented
24 0 my %args = @_;
25  
26 0 my $state = App::lcpan::_init(\%args, 'ro');
27 0 my $dbh = $state->{dbh};
28  
29 0 my $sql = "SELECT
30 file.cpanid id,
31 -- author.fullname name, -- too slow
32 COUNT(*) AS script_count,
33 ROUND(100.0 * COUNT(*) / (SELECT COUNT(*) FROM script), 4) script_count_pct
34 FROM script
35 -- LEFT JOIN author ON author.cpanid=file.cpanid
36 LEFT JOIN file ON script.file_id=file.id
37 GROUP BY file.cpanid
38 ORDER BY script_count DESC
39 ";
40  
41 0 my @res;
42 0 my $sth = $dbh->prepare($sql);
43 0 $sth->execute();
44 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
45 0 push @res, $row;
46 }
47  
48 0 require Data::TableData::Rank;
49 0 Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => [qw/script_count/]);
50  
51 0 my $resmeta = {};
52 #$resmeta->{'table.fields'} = [qw/id name script_count script_count_pct/];
53 0 $resmeta->{'table.fields'} = [qw/rank id script_count script_count_pct/];
54 0 [200, "OK", \@res, $resmeta];
55 }
56  
57 1 1;
58 # ABSTRACT: List authors ranked by number of scripts
59  
60 __END__
« App/lcpan/Cmd/authors_by_rel_count.pm ↑ Summary App/lcpan/Cmd/subnames_by_count.pm »