App/lcpan/Cmd/dists_by_dep_count.pm

filter: Statementstmt 44.6% 21 / 47 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 34.6% 26 / 75 CC 9 SCAR 41.4
CC
9
Cov
32%
handle_cmd
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 62.6
« App/lcpan/Cmd/related_authors.pm ↑ Summary App/lcpan/Cmd/script2rel.pm »
1 package App::lcpan::Cmd::dists_by_dep_count;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Function::Fallback::CoreOrPP qw(clone_list);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 require App::lcpan;
10  
11 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 2 our $DATE = '2023-09-26'; # DATE
13 2 our $DIST = 'App-lcpan'; # DIST
14 2 our $VERSION = '1.074'; # VERSION
15  
16 2 our %SPEC;
17  
18 2 $SPEC{'handle_cmd'} = {
19 v => 1.1,
20 summary => 'List "heavy" distributions (ranked by number of dependencies)',
21 args => {
22 %App::lcpan::common_args,
23 %App::lcpan::fauthor_args,
24 clone_list(%App::lcpan::deps_phase_args),
25 clone_list(%App::lcpan::deps_rel_args),
26 n => {
27 summary => 'Return at most this number of results',
28 schema => 'posint*',
29 },
30 },
31 };
32 2 delete $SPEC{'handle_cmd'}{args}{phase}{default};
33 2 delete $SPEC{'handle_cmd'}{args}{rel}{default};
34 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=9 SCAR=45.0
Pod documented
35 0 my %args = @_;
36  
37 0 my $state = App::lcpan::_init(\%args, 'ro');
38 0 my $dbh = $state->{dbh};
39  
40 0 my @where;
41 my @binds;
42 0 ▶ if ($args{author}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"author"}) 0 0 0
43 0 push @where, "(file.author=?)";
44 0 push @binds, $args{author};
45 }
46 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
47 0 push @where, "(dep.phase=?)";
48 0 push @binds, $args{phase};
49 }
50 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
51 0 push @where, "(dep.rel=?)";
52 0 push @binds, $args{rel};
53 }
54 0 push @where, "file.is_latest_dist";
55 0 ▶ @where = (1) if !@where;
Branch: 1 branch
BranchTrueFalseTotal
unless @where 0 0 0
56  
57 my $sql = "SELECT
58 file.dist_name dist,
59 file.cpanid author,
60 COUNT(DISTINCT dep.module_id) AS dep_count
61 FROM dep
62 LEFT JOIN file ON dep.file_id=file.id
63 WHERE ".join(" AND ", @where)."
64 GROUP BY dep.file_id
65 ORDER BY dep_count DESC
66 0 ▶".($args{n} ? "LIMIT ".(0+$args{n}) : "");
Branch: 1 branch
BranchTrueFalseTotal
$args{'n'} ? : 0 0 0
67  
68 0 my @res;
69 0 my $sth = $dbh->prepare($sql);
70 0 $sth->execute(@binds);
71 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
72 0 push @res, $row;
73 }
74  
75 0 require Data::TableData::Rank;
76 0 Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => ['dep_count']);
77  
78 0 my $resmeta = {};
79 0 $resmeta->{'table.fields'} = [qw/rank dist author dep_count/];
80 0 [200, "OK", \@res, $resmeta];
81 }
82  
83 2 1;
84 # ABSTRACT: List "heavy" distributions (ranked by number of dependencies)
85  
86 __END__
« App/lcpan/Cmd/related_authors.pm ↑ Summary App/lcpan/Cmd/script2rel.pm »