| 1 | package App::lcpan::Cmd::mods_by_rdep_count; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Function::Fallback::CoreOrPP qw(clone_list); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | require App::lcpan; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 12 | 4 | our $DATE = '2023-09-26'; # DATE | |||||||||||||||||||||||||||
| 13 | 4 | our $DIST = 'App-lcpan'; # DIST | |||||||||||||||||||||||||||
| 14 | 4 | our $VERSION = '1.074'; # VERSION | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | our %SPEC; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | $SPEC{'handle_cmd'} = { | |||||||||||||||||||||||||||
| 19 | v => 1.1, | ||||||||||||||||||||||||||||
| 20 | summary => 'List "most depended modules" (modules ranked by number of reverse dependencies)', | ||||||||||||||||||||||||||||
| 21 | args => { | ||||||||||||||||||||||||||||
| 22 | %App::lcpan::common_args, | ||||||||||||||||||||||||||||
| 23 | clone_list(%App::lcpan::deps_phase_args), | ||||||||||||||||||||||||||||
| 24 | clone_list(%App::lcpan::deps_rel_args), | ||||||||||||||||||||||||||||
| 25 | n => { | ||||||||||||||||||||||||||||
| 26 | summary => 'Return at most this number of results', | ||||||||||||||||||||||||||||
| 27 | schema => 'posint*', | ||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | %App::lcpan::argspecsopt_module_authors, | ||||||||||||||||||||||||||||
| 30 | %App::lcpan::argspecsopt_dist_authors, | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||
| 33 | 4 | delete $SPEC{'handle_cmd'}{args}{phase}{default}; | |||||||||||||||||||||||||||
| 34 | 4 | delete $SPEC{'handle_cmd'}{args}{rel}{default}; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub handle_cmd { | ||||||||||||||||||||||||||
|
Subroutine
handle_cmd: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||||||||||||||||||||
| 39 | 0 | my $dbh = $state->{dbh}; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my @where; | |||||||||||||||||||||||||||
| 42 | my @binds; | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($args{module_authors} && @{ $args{module_authors} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"module_authors"} and @{$args{"module_authors"};}
MC/DC0%0/2
$args{"module_authors"} and @{$args{"module_authors"};}
$args{"module_authors"}
@{$args{"module_authors"};}
Truth table0%0/3
A and B
A= $args{"module_authors"}B= @{$args{"module_authors"};}
| |||||||||||||||||||||||||||||
| 44 | 0 | push @where, "(author IN (".join(", ", map {$dbh->quote($_)} @{ $args{module_authors} })."))"; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($args{module_authors_arent} && @{ $args{module_authors_arent} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"module_authors_arent"} and @{$args{"module_authors_arent"};}
MC/DC0%0/2
$args{"module_authors_arent"} and @{$args{"module_authors_arent"};}
$args{"module_authors_arent"}
@{$args{"module_authors_arent"};}
Truth table0%0/3
A and B
A= $args{"module_authors_arent"}B= @{$args{"module_authors_arent"};}
| |||||||||||||||||||||||||||||
| 47 | 0 | push @where, "(author NOT IN (".join(", ", map {$dbh->quote($_)} @{ $args{module_authors_arent} })."))"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ($args{dist_authors} && @{ $args{dist_authors} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"dist_authors"} and @{$args{"dist_authors"};}
MC/DC0%0/2
$args{"dist_authors"} and @{$args{"dist_authors"};}
$args{"dist_authors"}
@{$args{"dist_authors"};}
Truth table0%0/3
A and B
A= $args{"dist_authors"}B= @{$args{"dist_authors"};}
| |||||||||||||||||||||||||||||
| 50 | 0 | push @where, "(f.cpanid IN (".join(", ", map {$dbh->quote($_)} @{ $args{dist_authors} })."))"; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($args{dist_authors_arent} && @{ $args{dist_authors_arent} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"dist_authors_arent"} and @{$args{"dist_authors_arent"};}
MC/DC0%0/2
$args{"dist_authors_arent"} and @{$args{"dist_authors_arent"};}
$args{"dist_authors_arent"}
@{$args{"dist_authors_arent"};}
Truth table0%0/3
A and B
A= $args{"dist_authors_arent"}B= @{$args{"dist_authors_arent"};}
| |||||||||||||||||||||||||||||
| 53 | 0 | push @where, "(f.cpanid NOT IN (".join(", ", map {$dbh->quote($_)} @{ $args{dist_authors_arent} })."))"; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($args{phase} && $args{phase} ne 'ALL') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"phase"} and $args{"phase"} ne "ALL"
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"
| |||||||||||||||||||||||||||||
| 56 | 0 | push @where, "(phase=?)"; | |||||||||||||||||||||||||||
| 57 | 0 | push @binds, $args{phase}; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($args{rel} && $args{rel} ne 'ALL') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"rel"} and $args{"rel"} ne "ALL"
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"
| |||||||||||||||||||||||||||||
| 60 | 0 | push @where, "(rel=?)"; | |||||||||||||||||||||||||||
| 61 | 0 | push @binds, $args{rel}; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | @where = (1) if !@where; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | my $sql = "SELECT | ||||||||||||||||||||||||||||
| 66 | m.name module, | ||||||||||||||||||||||||||||
| 67 | m.cpanid author, | ||||||||||||||||||||||||||||
| 68 | COUNT(*) AS rdep_count | ||||||||||||||||||||||||||||
| 69 | FROM module m | ||||||||||||||||||||||||||||
| 70 | JOIN dep dp ON m.id=dp.module_id | ||||||||||||||||||||||||||||
| 71 | LEFT JOIN file f ON dp.file_id=f.id | ||||||||||||||||||||||||||||
| 72 | WHERE ".join(" AND ", @where)." | ||||||||||||||||||||||||||||
| 73 | GROUP BY m.name | ||||||||||||||||||||||||||||
| 74 | ORDER BY rdep_count DESC | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | ".($args{n} ? " LIMIT ".(0+$args{n}) : ""); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my @res; | |||||||||||||||||||||||||||
| 78 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||||||||||
| 79 | 0 | $sth->execute(@binds); | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | push @res, $row; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | require Data::TableData::Rank; | |||||||||||||||||||||||||||
| 85 | 0 | Data::TableData::Rank::add_rank_column_to_table(table => \@res, data_columns => ['rdep_count']); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $resmeta = {}; | |||||||||||||||||||||||||||
| 88 | 0 | $resmeta->{'table.fields'} = [qw/rank module author rdep_count/]; | |||||||||||||||||||||||||||
| 89 | 0 | [200, "OK", \@res, $resmeta]; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | 1; | |||||||||||||||||||||||||||
| 93 | # ABSTRACT: List "most depended modules" (modules ranked by number of reverse dependencies) | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||