| 1 | package App::lcpan::Cmd::rdeps_scripts; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||
|
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 scripts that depend on specified modules', | ||||||||||
| 19 | description => <<'_', | ||||||||||
| 20 | |||||||||||
| 21 | This is currently implemented as rdeps + dist_scripts (find distributions that | ||||||||||
| 22 | depend on specified modules, and list all scripts in those distributions): | ||||||||||
| 23 | |||||||||||
| 24 | % lcpan rdeps Some::Module | td select dist | xargs lcpan dist-scripts Some::Module | ||||||||||
| 25 | |||||||||||
| 26 | so not really accurate. | ||||||||||
| 27 | |||||||||||
| 28 | _ | ||||||||||
| 29 | args => { | ||||||||||
| 30 | %App::lcpan::common_args, | ||||||||||
| 31 | %App::lcpan::mods_args, | ||||||||||
| 32 | %App::lcpan::rdeps_rel_args, | ||||||||||
| 33 | %App::lcpan::rdeps_phase_args, | ||||||||||
| 34 | %App::lcpan::rdeps_level_args, | ||||||||||
| 35 | %App::lcpan::fauthor_args, | ||||||||||
| 36 | }, | ||||||||||
| 37 | }; | ||||||||||
| 38 | 0 | ▶ | sub handle_cmd { | ||||||||
|
Subroutine
handle_cmd: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 39 | 0 | require App::lcpan::Cmd::mod2dist; | |||||||||
| 40 | |||||||||||
| 41 | 0 | my %args = @_; | |||||||||
| 42 | |||||||||||
| 43 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||
| 44 | 0 | my $dbh = $state->{dbh}; | |||||||||
| 45 | |||||||||||
| 46 | 0 | my $res; | |||||||||
| 47 | |||||||||||
| 48 | my @dists; | ||||||||||
| 49 | 0 | $res = App::lcpan::Cmd::mod2dist::handle_cmd(%args); # XXX subset | |||||||||
| 50 | 0 | ▶ | return [500, "Can't mod2dist: $res->[0] - $res->[1]"] | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | unless $res->[0] == 200; | ||||||||||
| 52 | 0 | ▶ | if (ref $res->[2] eq 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | push @dists, values %{ $res->[2] }; | |||||||||
| 54 | } else { | ||||||||||
| 55 | 0 | ▶ | push @dists, $res->[2] if defined $res->[2]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | 0 | ▶ | return [404, "No dists found for the module(s) specified"] unless @dists; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 0 | $res = App::lcpan::rdeps(%args, flatten=>1); | |||||||||
| 60 | 0 | ▶ | return [500, "Can't mod2dist: $res->[0] - $res->[1]"] | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | unless $res->[0] == 200; | ||||||||||
| 62 | 0 | push @dists, $_->{dist} for @{ $res->[2] }; | |||||||||
| 63 | |||||||||||
| 64 | 0 | my @where; | |||||||||
| 65 | push @where, "file.dist_name IN (". | ||||||||||
| 66 | 0 | join(",", map { $dbh->quote($_) } @dists).")"; | |||||||||
| 67 | push @where, "file.cpanid=".$dbh->quote($args{author}) | ||||||||||
| 68 | 0 | ▶ | if defined $args{author}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | my $sql = "SELECT | |||||||||
| 70 | script.name name, | ||||||||||
| 71 | file.dist_name dist, | ||||||||||
| 72 | script.cpanid author, | ||||||||||
| 73 | script.abstract abstract | ||||||||||
| 74 | FROM script | ||||||||||
| 75 | LEFT JOIN file ON script.file_id=file.id | ||||||||||
| 76 | WHERE ".join(" AND ", @where)." | ||||||||||
| 77 | "; | ||||||||||
| 78 | |||||||||||
| 79 | 0 | my @res; | |||||||||
| 80 | 0 | my $sth = $dbh->prepare($sql); | |||||||||
| 81 | 0 | $sth->execute(); | |||||||||
| 82 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | push @res, $row; | |||||||||
| 84 | } | ||||||||||
| 85 | 0 | my $resmeta = {}; | |||||||||
| 86 | 0 | $resmeta->{'table.fields'} = [qw/name dist author abstract/]; | |||||||||
| 87 | 0 | [200, "OK", \@res, $resmeta]; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | 1; | |||||||||
| 91 | # ABSTRACT: List scripts that depend on specified modules | ||||||||||
| 92 | |||||||||||
| 93 | __END__ | ||||||||||