App/lcpan/Cmd/script2author.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 37.0% 20 / 54 CC 7 SCAR 36.8
CC
7
Cov
33%
handle_cmd
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 39.5
« App/lcpan/Cmd/scripts_by_mention_count.pm ↑ Summary App/lcpan/Cmd/script2dist.pm »
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
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
47 0 ▶ unless ($args{all}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"all"}) 0 0 0
48 0 ▶ next if $mem{$row->{script}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $mem{$row->{"script"}}++ 0 0 0
49 }
50 0 push @res, $row;
51 }
52  
53 0 ▶ if (@$scripts == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$scripts == 1) 0 0 0
54 0 @res = map { $_->{author} } @res;
55 0 ▶ if (!@res) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @res) { } 0 0 0
elsif (@res == 1) { } 0 0 0
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__
« App/lcpan/Cmd/scripts_by_mention_count.pm ↑ Summary App/lcpan/Cmd/script2dist.pm »