App/lcpan/Cmd/mods_by_mention_count.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 36.3% 20 / 55 CC 7 SCAR 36.8
CC
7
Cov
33%
handle_cmd
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 39.5
« App/lcpan/Cmd/extract_script.pm ↑ Summary App/lcpan/Cmd/scripts_by_mention_count.pm »
1 package App::lcpan::Cmd::mods_by_mention_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 require App::lcpan;
8  
9 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 2 our $DATE = '2023-09-26'; # DATE
11 2 our $DIST = 'App-lcpan'; # DIST
12 2 our $VERSION = '1.074'; # VERSION
13  
14 2 our %SPEC;
15  
16 2 $SPEC{'handle_cmd'} = {
17 v => 1.1,
18 summary => 'List modules ranked by number of mentions',
19 description => <<'_',
20  
21 This shows the list of most mentioned modules, that is, modules who are
22 linked/referred to the most in PODs.
23  
24 Unknown modules (modules not indexed) are not included. Note that mentions can
25 refer to unknown modules.
26  
27 By default, each source module/script that mentions a module is counted as one
28 mention (`--count-per content`). Use `--count-per dist` to only count mentions
29 by modules/scripts from the same dist as one mention (so a module only gets a
30 maximum of 1 vote per dist). Use `--count-per author` to only count mentions by
31 modules/scripts from the same author as one mention (so a module only gets a
32 maximum of 1 vote per mentioning author).
33  
34 By default, only mentions from other authors are included. Use
35 `--include-self-mentions` to also include mentions from the same author.
36  
37 _
38 args => {
39 %App::lcpan::common_args,
40 include_self_mentions => {
41 schema => 'bool',
42 default => 0,
43 },
44 count_per => {
45 schema => ['str*', in=>['content', 'dist', 'author']],
46 default => 'content',
47 },
48 n => {
49 summary => 'Return at most this number of results',
50 schema => 'posint*',
51 },
52 },
53 };
54 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=7 SCAR=40.3
Pod documented
55 0 my %args = @_;
56  
57 0 my $state = App::lcpan::_init(\%args, 'ro');
58 0 my $dbh = $state->{dbh};
59  
60 0 ▶ my $count_per = $args{count_per} // 'content';
Condition0%0/2
$args{"count_per"} // "content"
l!l
00
MC/DC0%0/1
$args{"count_per"} // "content"
$args{"count_per"}
Truth table0%0/2
A
A= $args{"count_per"}
Aresult
11
00
61  
62 0 my @where = ("mention.module_id IS NOT NULL");
63  
64 push @where, "targetfile.cpanid <> srcfile.cpanid"
65 0 ▶ unless $args{include_self_mentions};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"include_self_mentions"} 0 0 0
66  
67 0 my $count = '*';
68 0 ▶ if ($count_per eq 'dist') {
Branch: 2 branches
BranchTrueFalseTotal
if ($count_per eq 'dist') { } 0 0 0
elsif ($count_per eq 'author') { } 0 0 0
69 0 $count = 'DISTINCT srcfile.id';
70 } elsif ($count_per eq 'author') {
71 0 $count = 'DISTINCT srcfile.cpanid';
72 }
73  
74 my $sql = "SELECT
75 module.name module,
76 COUNT($count) AS mention_count,
77 module.cpanid author,
78 module.abstract abstract
79 FROM mention
80 LEFT JOIN file srcfile ON mention.source_file_id=srcfile.id
81 LEFT JOIN module ON mention.module_id=module.id
82 LEFT JOIN file targetfile ON module.file_id=targetfile.id
83 WHERE ".join(" AND ", @where)."
84 GROUP BY module.name
85 ORDER BY mention_count DESC
86 0 ▶".($args{n} ? "LIMIT ".(0+$args{n}) : "");
Branch: 1 branch
BranchTrueFalseTotal
$args{'n'} ? : 0 0 0
87  
88 0 my @res;
89 0 my $sth = $dbh->prepare($sql);
90 0 $sth->execute();
91 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
92 0 push @res, $row;
93 }
94  
95 0 require Data::TableData::Rank;
96 0 Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => ['mention_count']);
97  
98 0 my $resmeta = {};
99 0 $resmeta->{'table.fields'} = [qw/rank module author mention_count abstract/];
100 0 [200, "OK", \@res, $resmeta];
101 }
102  
103 2 1;
104 # ABSTRACT: List modules ranked by number of mentions
105  
106 __END__
« App/lcpan/Cmd/extract_script.pm ↑ Summary App/lcpan/Cmd/scripts_by_mention_count.pm »