App/lcpan/Cmd/mentions.pm

filter: Statementstmt 20.0% 19 / 95 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 12.3% 24 / 195 CC 35 SCAR 70.3
CC
35
Cov
11%
handle_cmd
1260.0
BEGIN
1.0
BEGIN
1.0
CRAP 1130.9
« App/lcpan.pm ↑ Summary App/lcpan/Cmd/subs.pm »
1 package App::lcpan::Cmd::mentions;
2  
3 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 require App::lcpan;
9  
10 6 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11 6 our $DATE = '2023-09-26'; # DATE
12 6 our $DIST = 'App-lcpan'; # DIST
13 6 our $VERSION = '1.074'; # VERSION
14  
15 6 our %SPEC;
16  
17 6 $SPEC{'handle_cmd'} = {
18 v => 1.1,
19 summary => 'List mentions',
20 description => <<'_',
21  
22 This subcommand lists mentions (references to modules/scripts in POD files
23 inside releases).
24  
25 Only mentions to modules/scripts in another release are indexed (i.e. mentions
26 to modules/scripts in the same dist/release are not indexed). Only mentions to
27 known scripts are indexed, but mentions to unknown modules are also indexed.
28  
29 _
30 args => {
31 %App::lcpan::common_args,
32 type => {
33 summary => 'Filter by type of things being mentioned',
34 schema => ['str*', in=>['any', 'script', 'module', 'unknown-module', 'known-module']],
35 default => 'any',
36 tags => ['category:filtering'],
37 },
38  
39 mentioned_modules => {
40 'x.name.is_plural' => 1,
41 summary => 'Filter by module name(s) being mentioned',
42 schema => ['array*', of=>'str*', min_len=>1],
43 element_completion => \&App::lcpan::_complete_mod,
44 tags => ['category:filtering'],
45 },
46 mentioned_scripts => {
47 'x.name.is_plural' => 1,
48 summary => 'Filter by script name(s) being mentioned',
49 schema => ['array*', of=>'str*', min_len=>1],
50 element_completion => \&App::lcpan::_complete_script,
51 tags => ['category:filtering'],
52 },
53 mentioned_authors => {
54 'x.name.is_plural' => 1,
55 summary => 'Filter by author(s) of module/script being mentioned',
56 schema => ['array*', of=>'str*', min_len=>1],
57 tags => ['category:filtering'],
58 completion => \&App::lcpan::_complete_cpanid,
59 },
60  
61 mentioner_modules => {
62 'x.name.is_plural' => 1,
63 summary => 'Filter by module(s) that do the mentioning',
64 schema => ['array*', of=>'str*', min_len=>1],
65 element_completion => \&App::lcpan::_complete_mod,
66 tags => ['category:filtering'],
67 },
68 mentioner_scripts => {
69 'x.name.is_plural' => 1,
70 summary => 'Filter by script(s) that do the mentioning',
71 schema => ['array*', of=>'str*', min_len=>1],
72 element_completion => \&App::lcpan::_complete_script,
73 tags => ['category:filtering'],
74 },
75 mentioner_authors => {
76 'x.name.is_plural' => 1,
77 summary => 'Filter by author(s) of POD that does the mentioning',
78 schema => ['array*', of=>'str*', min_len=>1],
79 tags => ['category:filtering'],
80 completion => \&App::lcpan::_complete_cpanid,
81 },
82 mentioner_authors_arent => {
83 'x.name.is_plural' => 1,
84 'x.name.singular' => 'mentioner_author_isnt',
85 schema => ['array*', of=>'str*'],
86 tags => ['category:filtering'],
87 element_completion => \&App::lcpan::_complete_cpanid,
88 },
89 #%App::lcpan::fauthor_args,
90 %App::lcpan::fctime_args,
91 %App::lcpan::fmtime_args,
92 %App::lcpan::fctime_or_mtime_args,
93 },
94 };
95 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=35 SCAR=71.4
Pod documented
96 0 my %args = @_;
97  
98 0 my $state = App::lcpan::_init(\%args, 'ro');
99 0 my $dbh = $state->{dbh};
100  
101 0 ▶ my $type = $args{type} // 'any';
Condition0%0/2
$args{"type"} // "any"
l!l
00
MC/DC0%0/1
$args{"type"} // "any"
$args{"type"}
Truth table0%0/2
A
A= $args{"type"}
Aresult
11
00
102  
103 0 ▶ my $mentioned_modules = $args{mentioned_modules} // [];
Condition0%0/2
$args{"mentioned_modules"} // []
l!l
00
MC/DC0%0/1
$args{"mentioned_modules"} // []
$args{"mentioned_modules"}
Truth table0%0/2
A
A= $args{"mentioned_modules"}
Aresult
11
00
104 0 ▶ my $mentioned_scripts = $args{mentioned_scripts} // [];
Condition0%0/2
$args{"mentioned_scripts"} // []
l!l
00
MC/DC0%0/1
$args{"mentioned_scripts"} // []
$args{"mentioned_scripts"}
Truth table0%0/2
A
A= $args{"mentioned_scripts"}
Aresult
11
00
105 0 ▶ my $mentioned_authors = $args{mentioned_authors} // [];
Condition0%0/2
$args{"mentioned_authors"} // []
l!l
00
MC/DC0%0/1
$args{"mentioned_authors"} // []
$args{"mentioned_authors"}
Truth table0%0/2
A
A= $args{"mentioned_authors"}
Aresult
11
00
106  
107 0 ▶ my $mentioner_modules = $args{mentioner_modules} // [];
Condition0%0/2
$args{"mentioner_modules"} // []
l!l
00
MC/DC0%0/1
$args{"mentioner_modules"} // []
$args{"mentioner_modules"}
Truth table0%0/2
A
A= $args{"mentioner_modules"}
Aresult
11
00
108 0 ▶ my $mentioner_scripts = $args{mentioner_scripts} // [];
Condition0%0/2
$args{"mentioner_scripts"} // []
l!l
00
MC/DC0%0/1
$args{"mentioner_scripts"} // []
$args{"mentioner_scripts"}
Truth table0%0/2
A
A= $args{"mentioner_scripts"}
Aresult
11
00
109 0 ▶ my $mentioner_authors = $args{mentioner_authors} // [];
Condition0%0/2
$args{"mentioner_authors"} // []
l!l
00
MC/DC0%0/1
$args{"mentioner_authors"} // []
$args{"mentioner_authors"}
Truth table0%0/2
A
A= $args{"mentioner_authors"}
Aresult
11
00
110 0 ▶ my $mentioner_authors_arent = $args{mentioner_authors_arent} // [];
Condition0%0/2
$args{"mentioner_authors_arent"} // []
l!l
00
MC/DC0%0/1
$args{"mentioner_authors_arent"} // []
$args{"mentioner_authors_arent"}
Truth table0%0/2
A
A= $args{"mentioner_authors_arent"}
Aresult
11
00
111  
112 0 my @extra_join;
113 my @bind;
114 0 my @where;
115 #my @having;
116  
117 0 App::lcpan::_set_since(\%args, $dbh);
118 0 App::lcpan::_add_since_where_clause(\%args, \@where, "mention");
119  
120 0 ▶ if ($type eq 'script') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'script') { } 0 0 0
elsif ($type eq 'module') { } 0 0 0
elsif ($type eq 'known-module') { } 0 0 0
elsif ($type eq 'unknown-module') { } 0 0 0
121 0 push @where, "mention.script_name IS NOT NULL";
122 } elsif ($type eq 'module') {
123 0 push @where, "(mention.module_id IS NOT NULL OR mention.module_name IS NOT NULL)";
124 } elsif ($type eq 'known-module') {
125 0 push @where, "mention.module_id IS NOT NULL";
126 } elsif ($type eq 'unknown-module') {
127 0 push @where, "mention.module_name IS NOT NULL";
128 }
129  
130 0 ▶ if (@$mentioned_modules) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_modules) 0 0 0
131 0 my $mods_s = join(",", map { $dbh->quote($_) } @$mentioned_modules);
132 0 ▶ if ($type eq 'known-module') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'known-module') { } 0 0 0
elsif ($type eq 'unknown-module') { } 0 0 0
133 0 push @where, "m1.name IN ($mods_s)";
134 } elsif ($type eq 'unknown-module') {
135 0 push @where, "mention.module_name IN ($mods_s)";
136 } else {
137 0 push @where, "(m1.name IN ($mods_s) OR mention.module_name IN ($mods_s))";
138 }
139 }
140  
141 0 ▶ if (@$mentioned_scripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_scripts) 0 0 0
142 0 my $scripts_s = join(",", map { $dbh->quote($_) } @$mentioned_scripts);
143 0 push @where, "mention.script_name IN ($scripts_s)";
144 }
145  
146 0 ▶ if (@$mentioned_authors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_authors) 0 0 0
147 0 my $authors_s = join(",", map { $dbh->quote(uc $_) } @$mentioned_authors);
148 0 push @where, "(module_author IN ($authors_s) OR script_author IN ($authors_s))";
149 }
150  
151 0 ▶ if (@$mentioner_modules) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioner_modules) 0 0 0
152 0 my $mods_s = join(",", map { $dbh->quote($_) } @$mentioner_modules);
153 0 push @where, "content.package IN ($mods_s)";
154 }
155  
156 0 ▶ if (@$mentioner_scripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioner_scripts) 0 0 0
157 0 my $scripts_s = join(",", map { $dbh->quote($_) } @$mentioner_scripts);
158 0 push @extra_join, "LEFT JOIN script s2 ON content.id=s2.content_id -- mentioner script";
159 0 push @where, "s2.name IN ($scripts_s)";
160 }
161  
162 0 ▶ if (@$mentioner_authors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioner_authors) 0 0 0
163 0 my $authors_s = join(",", map { $dbh->quote(uc $_) } @$mentioner_authors);
164 0 push @where, "mentioner_author IN ($authors_s)";
165 }
166  
167 0 ▶ if (@$mentioner_authors_arent) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioner_authors_arent) 0 0 0
168 0 my $authors_s = join(",", map { $dbh->quote(uc $_) } @$mentioner_authors_arent);
169 0 push @where, "mentioner_author NOT IN ($authors_s)";
170 }
171  
172 my $sql = "SELECT
173 file.name release,
174 content.path content_path,
175 CASE WHEN m1.name IS NOT NULL THEN m1.name ELSE mention.module_name END AS module,
176 m1.cpanid module_author,
177 mention.script_name script,
178 s1.cpanid script_author,
179 file.cpanid mentioner_author
180 FROM mention
181 LEFT JOIN file ON file.id=mention.source_file_id
182 LEFT JOIN content ON content.id=mention.source_content_id
183 LEFT JOIN module m1 ON mention.module_id=m1.id -- mentioned script
184 LEFT JOIN script s1 ON mention.script_name=s1.name -- mentioned script
185 ".
186 0 ▶ (@extra_join ? join("", map {"$_\n"} @extra_join) : "").
Branch: 2 branches
BranchTrueFalseTotal
@extra_join ? : 0 0 0
@where ? : 0 0 0
187 (@where ? "\nWHERE ".join(" AND ", @where) : "");#.
188 #(@having ? "\nHAVING ".join(" AND ", @having) : "");
189  
190 0 my @res;
191 0 my $sth = $dbh->prepare($sql);
192 0 $sth->execute(@bind);
193 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
194 0 ▶ if (@$mentioned_modules || $type =~ /module/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_modules or $type =~ /module/) 0 0 0
Condition0%0/3
@$mentioned_modules or $type =~ /module/
l!l&&r!l&&!r
000
MC/DC0%0/2
@$mentioned_modules or $type =~ /module/
@$mentioned_modules $type =~ /module/
Truth table0%0/3
A or B
A= @$mentioned_modulesB= $type =~ /module/
ABresult
1X1
011
000
195 0 delete $row->{script};
196 0 delete $row->{script_author};
197 }
198 0 ▶ if (@$mentioned_scripts || $type eq 'script') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_scripts or $type eq "script") 0 0 0
Condition0%0/3
@$mentioned_scripts or $type eq "script"
l!l&&r!l&&!r
000
MC/DC0%0/2
@$mentioned_scripts or $type eq "script"
@$mentioned_scripts $type eq "script"
Truth table0%0/3
A or B
A= @$mentioned_scriptsB= $type eq "script"
ABresult
1X1
011
000
199 0 delete $row->{module};
200 0 delete $row->{module_author};
201 }
202 0 push @res, $row;
203 }
204 0 my $resmeta = {};
205 0 $resmeta->{'table.fields'} = [qw/module module_author script script_author release mentioner_author content_path/];
206  
207 0 ▶ if (@$mentioned_modules || $type =~ /module/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_modules or $type =~ /module/) 0 0 0
Condition0%0/3
@$mentioned_modules or $type =~ /module/
l!l&&r!l&&!r
000
MC/DC0%0/2
@$mentioned_modules or $type =~ /module/
@$mentioned_modules $type =~ /module/
Truth table0%0/3
A or B
A= @$mentioned_modulesB= $type =~ /module/
ABresult
1X1
011
000
208 $resmeta->{'table.fields'} =
209 0 ▶ [grep {$_ ne 'script' && $_ ne 'script_author'} @{$resmeta->{'table.fields'}}];
Condition0%0/3
$_ ne 'script' && $_ ne 'script_author'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne 'script' && $_ ne 'script_author'
$_ ne 'script' $_ ne 'script_author'
Truth table0%0/3
A && B
A= $_ ne 'script'B= $_ ne 'script_author'
ABresult
0X0
100
111
210 }
211 0 ▶ if (@$mentioned_scripts || $type eq 'script') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$mentioned_scripts or $type eq "script") 0 0 0
Condition0%0/3
@$mentioned_scripts or $type eq "script"
l!l&&r!l&&!r
000
MC/DC0%0/2
@$mentioned_scripts or $type eq "script"
@$mentioned_scripts $type eq "script"
Truth table0%0/3
A or B
A= @$mentioned_scriptsB= $type eq "script"
ABresult
1X1
011
000
212 $resmeta->{'table.fields'} =
213 0 ▶ [grep {$_ ne 'module' && $_ ne 'module_author'} @{$resmeta->{'table.fields'}}];
Condition0%0/3
$_ ne 'module' && $_ ne 'module_author'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne 'module' && $_ ne 'module_author'
$_ ne 'module' $_ ne 'module_author'
Truth table0%0/3
A && B
A= $_ ne 'module'B= $_ ne 'module_author'
ABresult
0X0
100
111
214 }
215  
216 0 [200, "OK", \@res, $resmeta];
217 }
218  
219 6 1;
220 # ABSTRACT: List mentions
221  
222 __END__
« App/lcpan.pm ↑ Summary App/lcpan/Cmd/subs.pm »