App/lcpan/Cmd/script2rel.pm

filter: Statementstmt 39.0% 16 / 41 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 33.3% 20 / 60 CC 8 SCAR 39.6
CC
8
Cov
29%
handle_cmd
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 52.6
« App/lcpan/Cmd/dists_by_dep_count.pm ↑ Summary App/lcpan/Cmd/authors_by_rdep_count.pm »
1 package App::lcpan::Cmd::script2rel;
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 release(s) of script(s)',
19 args => {
20 %App::lcpan::common_args,
21 %App::lcpan::scripts_args,
22 %App::lcpan::full_path_args,
23 %App::lcpan::all_args,
24 },
25 };
26 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=8 SCAR=42.8
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 $scripts = $args{scripts};
33 0 my $scripts_s = join(",", map {$dbh->quote($_)} @$scripts);
34  
35 0 my $sth = $dbh->prepare("SELECT
36 script.name script,
37 file.cpanid author,
38 file.name release
39 FROM script
40 LEFT JOIN file ON script.file_id=file.id
41 WHERE script.name IN ($scripts_s)
42 ORDER BY file.id DESC");
43 0 $sth->execute;
44  
45 0 my @res;
46 my %mem;
47 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
48 0 ▶ unless ($args{all}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"all"}) 0 0 0
49 0 ▶ next if $mem{$row->{script}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $mem{$row->{"script"}}++ 0 0 0
50 }
51 0 ▶ if ($args{full_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'full_path'}) { } 0 0 0
52 $row->{release} = App::lcpan::_fullpath(
53 0 $row->{release}, $state->{cpan}, $row->{author});
54 } else {
55 $row->{release} = App::lcpan::_relpath(
56 0 $row->{release}, $row->{author});
57 }
58 0 delete $row->{author};
59 0 push @res, $row;
60 }
61  
62 0 ▶ if (@$scripts == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$scripts == 1) 0 0 0
63 0 @res = map { $_->{release} } @res;
64 0 ▶ if (!@res) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @res) { } 0 0 0
elsif (@res == 1) { } 0 0 0
65 0 return [404, "No such script"];
66 } elsif (@res == 1) {
67 0 return [200, "OK", $res[0]];
68 } else {
69 0 return [200, "OK", \@res];
70 }
71 }
72  
73 0 [200, "OK", \@res, {'table.fields' => [qw/script release/]}];
74 }
75  
76 1 1;
77 # ABSTRACT: Get release(s) of script(s)
78  
79 __END__
« App/lcpan/Cmd/dists_by_dep_count.pm ↑ Summary App/lcpan/Cmd/authors_by_rdep_count.pm »