| 1 | package App::lcpan::Cmd::script2author; | ||||||||||||||
| 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 => 'Get author name of script(s)', | ||||||||||||||
| 19 | args => { | ||||||||||||||
| 20 | %App::lcpan::common_args, | ||||||||||||||
| 21 | %App::lcpan::scripts_args, | ||||||||||||||
| 22 | %App::lcpan::all_args, | ||||||||||||||
| 23 | }, | ||||||||||||||
| 24 | }; | ||||||||||||||
| 25 | 0 | ▶ | sub handle_cmd { | ||||||||||||
|
Subroutine
handle_cmd: not called CC=7 SCAR=40.3
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 $scripts = $args{scripts}; | |||||||||||||
| 32 | |||||||||||||||
| 33 | 0 | my $scripts_s = join(",", map {$dbh->quote($_)} @$scripts); | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | my $sth = $dbh->prepare(" | |||||||||||||
| 36 | SELECT | ||||||||||||||
| 37 | script.name script, | ||||||||||||||
| 38 | file.cpanid author | ||||||||||||||
| 39 | FROM script | ||||||||||||||
| 40 | LEFT JOIN file ON script.file_id=file.id | ||||||||||||||
| 41 | WHERE script.name IN ($scripts_s)"); | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | my @res; | |||||||||||||
| 44 | my %mem; | ||||||||||||||
| 45 | 0 | $sth->execute; | |||||||||||||
| 46 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | 0 | ▶ | unless ($args{all}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | 0 | ▶ | next if $mem{$row->{script}}++; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | } | ||||||||||||||
| 50 | 0 | push @res, $row; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | ▶ | if (@$scripts == 1) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 0 | @res = map { $_->{author} } @res; | |||||||||||||
| 55 | 0 | ▶ | if (!@res) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | 0 | return [404, "No such script"]; | |||||||||||||
| 57 | } elsif (@res == 1) { | ||||||||||||||
| 58 | 0 | return [200, "OK", $res[0]]; | |||||||||||||
| 59 | } else { | ||||||||||||||
| 60 | 0 | return [200, "OK", \@res]; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 0 | [200, "OK", \@res, {'table.fields'=>[qw/script author/]}]; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 1 | 1; | |||||||||||||
| 68 | # ABSTRACT: Get author name of script(s) | ||||||||||||||
| 69 | |||||||||||||||
| 70 | __END__ | ||||||||||||||