App/lcpan/Cmd/contents.pm

filter: Statementstmt 23.5% 16 / 68 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 16.6% 20 / 120 CC 24 SCAR 62.8
CC
24
Cov
14%
handle_cmd
600.0
BEGIN
1.0
BEGIN
1.0
CRAP 533.4
« App/lcpan/Cmd/subs.pm ↑ Summary App/lcpan/Cmd/doc.pm »
1 package App::lcpan::Cmd::contents;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 require App::lcpan;
8  
9 3 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 3 our $DATE = '2023-09-26'; # DATE
11 3 our $DIST = 'App-lcpan'; # DIST
12 3 our $VERSION = '1.074'; # VERSION
13  
14 3 our %SPEC;
15  
16 3 $SPEC{'handle_cmd'} = {
17 v => 1.1,
18 summary => 'List contents inside releases',
19 description => <<'_',
20  
21 This subcommand lists files inside release archives.
22  
23 _
24 args => {
25 %App::lcpan::common_args,
26 %App::lcpan::fauthor_args,
27 %App::lcpan::fdist_args,
28 %App::lcpan::file_id_args,
29 "package" => {
30 schema => 'str*',
31 tags => ['category:filtering'],
32 },
33 %App::lcpan::query_multi_args,
34 query_type => {
35 schema => ['str*', in=>[qw/any path exact-path package
36 exact-package/]],
37 default => 'any',
38 },
39 #%App::lcpan::dist_args,
40 # all=>1
41 },
42 };
43 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=24 SCAR=64.0
Pod documented
44 0 my %args = @_;
45  
46 0 my $state = App::lcpan::_init(\%args, 'ro');
47 0 my $dbh = $state->{dbh};
48  
49 0 my $detail = $args{detail};
50 0 ▶ my $author = uc($args{author} // '');
Condition0%0/2
$args{"author"} // ""
l!l
00
MC/DC0%0/1
$args{"author"} // ""
$args{"author"}
Truth table0%0/2
A
A= $args{"author"}
Aresult
11
00
51 0 my $dist = $args{dist};
52 0 my $file_id = $args{file_id};
53 0 my $package = $args{package};
54 0 ▶ my $qt = $args{query_type} // 'any';
Condition0%0/2
$args{"query_type"} // "any"
l!l
00
MC/DC0%0/1
$args{"query_type"} // "any"
$args{"query_type"}
Truth table0%0/2
A
A= $args{"query_type"}
Aresult
11
00
55  
56 0 my @bind;
57 my @where;
58 {
59 0 my @q_where;
60 0 ▶ for my $q0 (@{ $args{query} // [] }) {
Condition0%0/2
$args{"query"} // []
l!l
00
MC/DC0%0/1
$args{"query"} // []
$args{"query"}
Truth table0%0/2
A
A= $args{"query"}
Aresult
11
00
61 0 ▶ if ($qt eq 'any') {
Branch: 5 branches
BranchTrueFalseTotal
if ($qt eq 'any') { } 0 0 0
elsif ($qt eq 'path') { } 0 0 0
elsif ($qt eq 'exact-path') { } 0 0 0
elsif ($qt eq 'package') { } 0 0 0
elsif ($qt eq 'exact-package') { } 0 0 0
62 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
63 0 push @q_where, "(content.path LIKE ? OR package LIKE ?)";
64 0 push @bind, $q, $q;
65 } elsif ($qt eq 'path') {
66 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
67 0 push @q_where, "(content.path LIKE ?)";
68 0 push @bind, $q;
69 } elsif ($qt eq 'exact-path') {
70 0 push @q_where, "(content.path=?)";
71 0 push @bind, $q0;
72 } elsif ($qt eq 'package') {
73 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
74 0 push @q_where, "(content.package LIKE ?)";
75 0 push @bind, $q;
76 } elsif ($qt eq 'exact-package') {
77 0 push @q_where, "(content.package=?)";
78 0 push @bind, $q0;
79 }
80 }
81 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
82 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
83 } elsif (@q_where == 1) {
84 0 push @where, @q_where;
85 }
86 }
87 0 ▶ if ($author) {
Branch: 1 branch
BranchTrueFalseTotal
if ($author) 0 0 0
88 0 push @where, "(file.cpanid=?)";
89 0 push @bind, $author;
90 }
91 0 ▶ if ($dist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist) 0 0 0
92 0 push @where, "file.dist_name=?";
93 0 push @bind, $dist;
94 }
95 0 ▶ if ($package) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package) 0 0 0
96 0 push @where, "content.package=?";
97 0 push @bind, $package;
98 }
99 0 ▶ if ($file_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file_id) 0 0 0
100 0 push @where, "file.id=?";
101 0 push @bind, $file_id;
102 }
103  
104 0 ▶ my $sql = "SELECT
Branch: 1 branch
BranchTrueFalseTotal
@where ? : 0 0 0
105 file.cpanid cpanid,
106 file.name release,
107 content.path path,
108 content.mtime mtime,
109 content.size size,
110 content.package AS package
111 FROM content
112 LEFT JOIN file ON content.file_id=file.id
113 ".
114 (@where ? " WHERE ".join(" AND ", @where) : "");
115  
116 0 my @res;
117 0 my $sth = $dbh->prepare($sql);
118 0 $sth->execute(@bind);
119 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
120 0 ▶ push @res, $detail ? $row : $row->{path};
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 0 0 0
121 }
122 0 my $resmeta = {};
123 0 ▶ $resmeta->{'table.fields'} = [qw/path release cpanid mtime size package/]
Branch: 1 branch
BranchTrueFalseTotal
if $detail 0 0 0
124 if $detail;
125 0 [200, "OK", \@res, $resmeta];
126 }
127  
128 3 1;
129 # ABSTRACT: List contents inside releases
130  
131 __END__
« App/lcpan/Cmd/subs.pm ↑ Summary App/lcpan/Cmd/doc.pm »