| 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"} // ""
MC/DC0%0/1
$args{"author"} // ""
$args{"author"}
Truth table0%0/2
A
A= $args{"author"}
| |||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$args{"query_type"} // "any"
$args{"query_type"}
Truth table0%0/2
A
A= $args{"query_type"}
| |||||||||||||||||||||||||||
| 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"} // []
MC/DC0%0/1
$args{"query"} // []
$args{"query"}
Truth table0%0/2
A
A= $args{"query"}
| |||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($qt eq 'any') { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 82 | 0 | ▶ | push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 83 | } elsif (@q_where == 1) { | ||||||||||||||||||||||||||
| 84 | 0 | push @where, @q_where; | |||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($author) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 88 | 0 | push @where, "(file.cpanid=?)"; | |||||||||||||||||||||||||
| 89 | 0 | push @bind, $author; | |||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($dist) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 92 | 0 | push @where, "file.dist_name=?"; | |||||||||||||||||||||||||
| 93 | 0 | push @bind, $dist; | |||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($package) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 96 | 0 | push @where, "content.package=?"; | |||||||||||||||||||||||||
| 97 | 0 | push @bind, $package; | |||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($file_id) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 100 | 0 | push @where, "file.id=?"; | |||||||||||||||||||||||||
| 101 | 0 | push @bind, $file_id; | |||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $sql = "SELECT | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 120 | 0 | ▶ | push @res, $detail ? $row : $row->{path}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||
| 122 | 0 | my $resmeta = {}; | |||||||||||||||||||||||||
| 123 | 0 | ▶ | $resmeta->{'table.fields'} = [qw/path release cpanid mtime size package/] | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 124 | if $detail; | ||||||||||||||||||||||||||
| 125 | 0 | [200, "OK", \@res, $resmeta]; | |||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||
| 128 | 3 | 1; | |||||||||||||||||||||||||
| 129 | # ABSTRACT: List contents inside releases | ||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||