App/lcpan/Cmd/authors_by_rdep_count.pm

filter: Statementstmt 46.6% 21 / 45 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 36.6% 26 / 71 CC 8 SCAR 38.8
CC
8
Cov
34%
handle_cmd
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 48.3
« App/lcpan/Cmd/script2rel.pm ↑ Summary App/lcpan/Cmd/mods_by_rdep_author_count.pm »
1 package App::lcpan::Cmd::authors_by_rdep_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 ▶use Function::Fallback::CoreOrPP qw(clone_list);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require App::lcpan;
10  
11 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 1 our $DATE = '2023-09-26'; # DATE
13 1 our $DIST = 'App-lcpan'; # DIST
14 1 our $VERSION = '1.074'; # VERSION
15  
16 1 our %SPEC;
17  
18 1 $SPEC{'handle_cmd'} = {
19 v => 1.1,
20 summary => 'List authors ranked by number of distributions using one of his/her modules',
21 args => {
22 %App::lcpan::common_args,
23 clone_list(%App::lcpan::deps_phase_args),
24 clone_list(%App::lcpan::deps_rel_args),
25 exclude_same_author => {
26 schema => 'bool',
27 },
28 },
29 };
30 1 delete $SPEC{'handle_cmd'}{args}{phase}{default};
31 1 delete $SPEC{'handle_cmd'}{args}{rel}{default};
32 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=8 SCAR=42.8
Pod documented
33 0 my %args = @_;
34  
35 0 my $state = App::lcpan::_init(\%args, 'ro');
36 0 my $dbh = $state->{dbh};
37  
38 0 my @where;
39 my @binds;
40 0 ▶ if ($args{phase} && $args{phase} ne 'ALL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"phase"} and $args{"phase"} ne "ALL") 0 0 0
Condition0%0/3
$args{"phase"} and $args{"phase"} ne "ALL"
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"phase"} and $args{"phase"} ne "ALL"
$args{"phase"} $args{"phase"} ne "ALL"
Truth table0%0/3
A and B
A= $args{"phase"}B= $args{"phase"} ne "ALL"
ABresult
0X0
100
111
41 0 push @where, "(phase=?)";
42 0 push @binds, $args{phase};
43 }
44 0 ▶ if ($args{rel} && $args{rel} ne 'ALL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"rel"} and $args{"rel"} ne "ALL") 0 0 0
Condition0%0/3
$args{"rel"} and $args{"rel"} ne "ALL"
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"rel"} and $args{"rel"} ne "ALL"
$args{"rel"} $args{"rel"} ne "ALL"
Truth table0%0/3
A and B
A= $args{"rel"}B= $args{"rel"} ne "ALL"
ABresult
0X0
100
111
45 0 push @where, "(rel=?)";
46 0 push @binds, $args{rel};
47 }
48 0 push @where, "f.is_latest_dist";
49 0 ▶ push @where, "f.cpanid <> m.cpanid" if $args{exclude_same_author};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"exclude_same_author"} 0 0 0
50 0 ▶ @where = (1) if !@where;
Branch: 1 branch
BranchTrueFalseTotal
unless @where 0 0 0
51  
52 0 my $sql = "SELECT
53 m.cpanid author,
54 COUNT(DISTINCT f.id) AS rdep_count
55 FROM module m
56 JOIN dep dp ON dp.module_id=m.id
57 LEFT JOIN author a ON a.cpanid=m.cpanid
58 LEFT JOIN file f ON f.id=dp.file_id
59 WHERE ".join(" AND ", @where)."
60 GROUP BY m.cpanid
61 ORDER BY rdep_count DESC
62 ";
63  
64 0 my @res;
65 0 my $sth = $dbh->prepare($sql);
66 0 $sth->execute(@binds);
67 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
68 0 push @res, $row;
69 }
70  
71 0 require Data::TableData::Rank;
72 0 Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => ['rdep_count']);
73  
74 0 my $resmeta = {};
75 0 $resmeta->{'table.fields'} = [qw/rank author rdep_count/];
76 0 [200, "OK", \@res, $resmeta];
77 }
78  
79 1 1;
80 # ABSTRACT: List authors ranked by number of distributions using one of his/her modules
81  
82 __END__
« App/lcpan/Cmd/script2rel.pm ↑ Summary App/lcpan/Cmd/mods_by_rdep_author_count.pm »