| 1 | package App::lcpan::Cmd::authors_by_mod_mention_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 module mentions', | ||||||||||||||
| 19 | description => <<'_', | ||||||||||||||
| 20 | |||||||||||||||
| 21 | This shows the list of most mentioned authors, that is, authors whose modules | ||||||||||||||
| 22 | are linked/referred to the most in PODs. | ||||||||||||||
| 23 | |||||||||||||||
| 24 | By default, each source module/script that mentions a module from author is | ||||||||||||||
| 25 | counted as one mention (`--count-per content`). Use `--count-per dist` to only | ||||||||||||||
| 26 | count mentions by modules/scripts from the same dist as one mention (so an | ||||||||||||||
| 27 | author only gets a maximum of 1 vote per dist). Use `--count-per author` to only | ||||||||||||||
| 28 | count mentions by modules/scripts from the same author as one mention (so an | ||||||||||||||
| 29 | author only gets a maximum of 1 vote per mentioning author). | ||||||||||||||
| 30 | |||||||||||||||
| 31 | By default, only mentions from other authors are included. Use | ||||||||||||||
| 32 | `--include-self-mentions` to also include mentions from the same author. | ||||||||||||||
| 33 | |||||||||||||||
| 34 | _ | ||||||||||||||
| 35 | args => { | ||||||||||||||
| 36 | %App::lcpan::common_args, | ||||||||||||||
| 37 | include_self_mentions => { | ||||||||||||||
| 38 | schema => 'bool', | ||||||||||||||
| 39 | default => 0, | ||||||||||||||
| 40 | }, | ||||||||||||||
| 41 | count_per => { | ||||||||||||||
| 42 | schema => ['str*', in=>['content', 'dist', 'author']], | ||||||||||||||
| 43 | default => 'content', | ||||||||||||||
| 44 | }, | ||||||||||||||
| 45 | }, | ||||||||||||||
| 46 | }; | ||||||||||||||
| 47 | 0 | ▶ | sub handle_cmd { | ||||||||||||
|
Subroutine
handle_cmd: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||
| 48 | 0 | my %args = @_; | |||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||||||
| 51 | 0 | my $dbh = $state->{dbh}; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | ▶ | my $count_per = $args{count_per} // 'content'; | ||||||||||||
|
Condition0%0/2
$args{"count_per"} // "content"
MC/DC0%0/1
$args{"count_per"} // "content"
$args{"count_per"}
Truth table0%0/2
A
A= $args{"count_per"}
| |||||||||||||||
| 54 | |||||||||||||||
| 55 | 0 | my @where = ("author IS NOT NULL"); | |||||||||||||
| 56 | |||||||||||||||
| 57 | push @where, "file.cpanid <> author" | ||||||||||||||
| 58 | 0 | ▶ | unless $args{include_self_mentions}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | my $count = '*'; | |||||||||||||
| 61 | 0 | ▶ | if ($count_per eq 'dist') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 62 | 0 | $count = 'DISTINCT file.id'; | |||||||||||||
| 63 | } elsif ($count_per eq 'author') { | ||||||||||||||
| 64 | 0 | $count = 'DISTINCT file.cpanid'; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | my $sql = "SELECT | |||||||||||||
| 68 | module.cpanid author, | ||||||||||||||
| 69 | COUNT($count) AS mod_mention_count | ||||||||||||||
| 70 | FROM mention | ||||||||||||||
| 71 | LEFT JOIN file ON mention.source_file_id=file.id | ||||||||||||||
| 72 | LEFT JOIN module ON module.id=mention.module_id | ||||||||||||||
| 73 | WHERE ".join(" AND ", @where)." | ||||||||||||||
| 74 | GROUP BY module.cpanid | ||||||||||||||
| 75 | ORDER BY mod_mention_count DESC | ||||||||||||||
| 76 | "; | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | my @res; | |||||||||||||
| 79 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||
| 80 | 0 | $sth->execute(); | |||||||||||||
| 81 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | 0 | push @res, $row; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | require Data::TableData::Rank; | |||||||||||||
| 86 | 0 | Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => ['mod_mention_count']); | |||||||||||||
| 87 | |||||||||||||||
| 88 | 0 | my $resmeta = {}; | |||||||||||||
| 89 | 0 | $resmeta->{'table.fields'} = [qw/rank author mod_mention_count/]; | |||||||||||||
| 90 | 0 | [200, "OK", \@res, $resmeta]; | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 1 | 1; | |||||||||||||
| 94 | # ABSTRACT: List authors ranked by number of module mentions | ||||||||||||||
| 95 | |||||||||||||||
| 96 | __END__ | ||||||||||||||