| 1 | package App::lcpan::Cmd::scripts_from_same_dist; | ||||||||||||||
| 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 => 'Given a script, list all scripts in the same distribution', | ||||||||||||||
| 19 | args => { | ||||||||||||||
| 20 | %App::lcpan::common_args, | ||||||||||||||
| 21 | %App::lcpan::scripts_args, | ||||||||||||||
| 22 | %App::lcpan::flatest_args, | ||||||||||||||
| 23 | %App::lcpan::detail_args, | ||||||||||||||
| 24 | }, | ||||||||||||||
| 25 | }; | ||||||||||||||
| 26 | 0 | ▶ | sub handle_cmd { | ||||||||||||
|
Subroutine
handle_cmd: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||
| 27 | 0 | my %args = @_; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||||||
| 30 | 0 | my $dbh = $state->{dbh}; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | my $detail = $args{detail}; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | my $escripts = join(",", map {$dbh->quote($_)} @{ $args{scripts} }); | |||||||||||||
| 35 | 0 | my @where; | |||||||||||||
| 36 | 0 | push @where, "f1.dist_name IN (SELECT dist_name FROM file f2 WHERE id IN (SELECT file_id FROM script WHERE name IN ($escripts)))"; | |||||||||||||
| 37 | 0 | ▶ | if ($args{latest}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 38 | 0 | push @where, "f1.is_latest_dist"; | |||||||||||||
| 39 | } elsif (defined $args{latest}) { | ||||||||||||||
| 40 | 0 | push @where, "NOT(f1.is_latest_dist)"; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | 0 | my $sth = $dbh->prepare("SELECT | |||||||||||||
| 43 | script.name name, | ||||||||||||||
| 44 | f1.dist_name dist, | ||||||||||||||
| 45 | f1.dist_version dist_version | ||||||||||||||
| 46 | FROM script | ||||||||||||||
| 47 | JOIN file f1 ON script.file_id=f1.id | ||||||||||||||
| 48 | WHERE ".join(" AND ", @where)." | ||||||||||||||
| 49 | ORDER BY name DESC"); | ||||||||||||||
| 50 | 0 | $sth->execute; | |||||||||||||
| 51 | 0 | my @res; | |||||||||||||
| 52 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | ▶ | push @res, $detail ? $row : $row->{name}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | } | ||||||||||||||
| 55 | 0 | my $resmeta = {}; | |||||||||||||
| 56 | 0 | ▶ | $resmeta->{'table.fields'} = [qw/name dist dist_version/] | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | if $detail; | ||||||||||||||
| 58 | 0 | [200, "OK", \@res, $resmeta]; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 1 | 1; | |||||||||||||
| 62 | # ABSTRACT: Given a script, list all scripts in the same distribution | ||||||||||||||
| 63 | |||||||||||||||
| 64 | __END__ | ||||||||||||||