App/lcpan/Cmd/subs.pm

filter: Statementstmt 30.1% 19 / 63 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 20.3% 24 / 118 CC 25 SCAR 63.3
CC
25
Cov
18%
handle_cmd
650.0
BEGIN
1.0
BEGIN
1.0
CRAP 560.5
« App/lcpan/Cmd/mentions.pm ↑ Summary App/lcpan/Cmd/contents.pm »
1 package App::lcpan::Cmd::subs;
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 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 require App::lcpan;
9  
10 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11 1 our $DATE = '2023-09-26'; # DATE
12 1 our $DIST = 'App-lcpan'; # DIST
13 1 our $VERSION = '1.074'; # VERSION
14  
15 1 our %SPEC;
16  
17 1 $SPEC{'handle_cmd'} = {
18 v => 1.1,
19 summary => 'List subroutines',
20 description => <<'_',
21  
22 This subcommand lists subroutines/methods/static methods.
23  
24 _
25 args => {
26 %App::lcpan::common_args,
27 %App::lcpan::query_multi_args,
28 query_type => {
29 schema => ['str*', in=>[qw/any name exact-name/]],
30 default => 'any',
31 },
32 # XXX include_method
33 # XXX include_static_method
34 # XXX include_function
35 packages => {
36 'x.name.is_plural' => 1,
37 summary => 'Filter by package name(s)',
38 schema => ['array*', of=>'str*', min_len=>1],
39 element_completion => \&App::lcpan::_complete_mod,
40 tags => ['category:filtering'],
41 },
42 authors => {
43 'x.name.is_plural' => 1,
44 summary => 'Filter by author(s) of module',
45 schema => ['array*', of=>'str*', min_len=>1],
46 element_completion => \&App::lcpan::_complete_cpanid,
47 tags => ['category:filtering'],
48 },
49 %App::lcpan::sort_args_for_subs,
50 },
51 };
52 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=25 SCAR=64.8
Pod documented
53 0 my %args = @_;
54  
55 0 my $state = App::lcpan::_init(\%args, 'ro');
56 0 my $dbh = $state->{dbh};
57  
58 0 my @bind;
59 my @where;
60 #my @having;
61  
62 0 ▶ my $packages = $args{packages} // [];
Condition0%0/2
$args{"packages"} // []
l!l
00
MC/DC0%0/1
$args{"packages"} // []
$args{"packages"}
Truth table0%0/2
A
A= $args{"packages"}
Aresult
11
00
63 0 ▶ my $authors = $args{authors} // [];
Condition0%0/2
$args{"authors"} // []
l!l
00
MC/DC0%0/1
$args{"authors"} // []
$args{"authors"}
Truth table0%0/2
A
A= $args{"authors"}
Aresult
11
00
64 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
65 0 ▶ my $sort = $args{sort} // ['sub'];
Condition0%0/2
$args{"sort"} // ["sub"]
l!l
00
MC/DC0%0/1
$args{"sort"} // ["sub"]
$args{"sort"}
Truth table0%0/2
A
A= $args{"sort"}
Aresult
11
00
66  
67 {
68 0 my @q_where;
69 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
70 0 ▶ if ($qt eq 'any') {
Branch: 3 branches
BranchTrueFalseTotal
if ($qt eq 'any') { } 0 0 0
elsif ($qt eq 'name') { } 0 0 0
elsif ($qt eq 'exact-name') { } 0 0 0
71 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
72 0 push @q_where, "(sub.name LIKE ? OR content.package LIKE ?)";
73 0 push @bind, $q, $q;
74 } elsif ($qt eq 'name') {
75 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
76 0 push @q_where, "(sub.name LIKE ?)";
77 0 push @bind, $q;
78 } elsif ($qt eq 'exact-name') {
79 0 push @q_where, "(sub.name=?)";
80 0 push @bind, $q0;
81 }
82 }
83 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
84 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
85 } elsif (@q_where == 1) {
86 0 push @where, @q_where;
87 }
88 }
89 0 ▶ if (@$packages) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$packages) 0 0 0
90 0 my $packages_s = join(",", map {$dbh->quote($_)} @$packages);
91 0 push @where, "(content.package IN ($packages_s))";
92 }
93 0 ▶ if (@$authors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$authors) 0 0 0
94 0 my $authors_s = join(",", map {$dbh->quote($_)} @$authors);
95 0 push @where, "(file.cpanid IN ($authors_s))";
96 }
97  
98 0 my @order;
99 0 ▶ for (@$sort) { /\A(-?)(\w+)/ and push @order, $2 . ($1 ? " DESC" : "") }
Branch: 2 branches
BranchTrueFalseTotal
/\A(-?)(\w+)/ and push @order, $2 . ($1 ? " DESC" : "") 0 0 0
$1 ? : 0 0 0
100  
101 0 ▶ my $sql = "SELECT
Branch: 2 branches
BranchTrueFalseTotal
@where ? : 0 0 0
@order ? : 0 0 0
102 sub.name sub,
103 content.package package,
104 sub.linum linum,
105 content.path content_path,
106 file.name release,
107 file.cpanid author
108 FROM sub
109 LEFT JOIN file ON sub.file_id=file.id
110 LEFT JOIN content ON sub.content_id=content.id
111 ".
112 (@where ? " WHERE ".join(" AND ", @where) : "").
113 #(@having ? " HAVING ".join(" AND ", @having) : "");
114 (@order ? " ORDER BY ".join(", ", @order) : "");
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, $args{detail} ? $row : $row->{sub};
Branch: 1 branch
BranchTrueFalseTotal
$args{'detail'} ? : 0 0 0
121 }
122 0 my $resmeta = {};
123 $resmeta->{'table.fields'} = [qw/sub package linum content_path release author/]
124 0 ▶ if $args{detail};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"detail"} 0 0 0
125  
126 0 [200, "OK", \@res, $resmeta];
127 }
128  
129 1 1;
130 # ABSTRACT: List subroutines
131  
132 __END__
« App/lcpan/Cmd/mentions.pm ↑ Summary App/lcpan/Cmd/contents.pm »