| 1 | package App::lcpan::Cmd::dist_scripts; | ||||||||||
| 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 scripts in a distribution', | ||||||||||
| 19 | args => { | ||||||||||
| 20 | %App::lcpan::common_args, | ||||||||||
| 21 | %App::lcpan::dists_args, | ||||||||||
| 22 | %App::lcpan::detail_args, | ||||||||||
| 23 | }, | ||||||||||
| 24 | }; | ||||||||||
| 25 | 0 | ▶ | sub handle_cmd { | ||||||||
|
Subroutine
handle_cmd: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 26 | 0 | my %args = @_; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||
| 29 | 0 | my $dbh = $state->{dbh}; | |||||||||
| 30 | |||||||||||
| 31 | 0 | my @wheres; | |||||||||
| 32 | 0 | push @wheres, "file.dist_name IN (".join(",", map {$dbh->quote($_)} @{ $args{dists} }).")"; | |||||||||
| 33 | 0 | my $detail = $args{detail}; | |||||||||
| 34 | |||||||||||
| 35 | 0 | my $sth = $dbh->prepare("SELECT | |||||||||
| 36 | script.name name, | ||||||||||
| 37 | file.dist_name dist, | ||||||||||
| 38 | script.abstract abstract | ||||||||||
| 39 | FROM script | ||||||||||
| 40 | LEFT JOIN file ON script.file_id=file.id | ||||||||||
| 41 | WHERE ".join(" AND ", @wheres)." | ||||||||||
| 42 | ORDER BY name DESC"); | ||||||||||
| 43 | 0 | $sth->execute(); | |||||||||
| 44 | 0 | my @res; | |||||||||
| 45 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | delete $row->{dist} unless @{ $args{dists} } > 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | ▶ | push @res, $detail ? $row : $row->{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | 0 | my $resmeta = {}; | |||||||||
| 50 | 0 | ▶ | $resmeta->{'table.fields'} = [qw/name dist abstract/] | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | if $detail; | ||||||||||
| 52 | 0 | [200, "OK", \@res, $resmeta]; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 1 | 1; | |||||||||
| 56 | # ABSTRACT: List scripts in a distribution | ||||||||||
| 57 | |||||||||||
| 58 | __END__ | ||||||||||