App/lcpan.pm

filter: Statementstmt 6.7% 128 / 1905 Branchbran 0.0% 0 / 1036 Conditioncond 0.0% 0 / 346 MC/DCmcdc 0.0% 0 / 198 Subroutinesub 12.5% 14 / 112 Podpod 100% 12 / 12 totaltotal 4.2% 154 / 3609 CC 699 SCAR 79.1
CC
699
Cov
4%
_update_index
13893.2
_get_prereqs
2756.0
modules
2352.0
CRAP 2733.6
↑ Summary App/lcpan/Cmd/mentions.pm »
1 ## no critic: Subroutines::ProhibitExplicitReturnUndef
2 package App::lcpan;
3  
4 98 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 98 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 98 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 98 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 98 ▶use Clone::Util qw(clone modclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 98 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 98 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 98 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
14 98 our $DATE = '2023-09-26'; # DATE
15 98 our $DIST = 'App-lcpan'; # DIST
16 98 our $VERSION = '1.074'; # VERSION
17  
18 98 our @ISA = qw(Exporter);
19 98 our @EXPORT_OK = qw(
20 update
21 modules
22 dists
23 releases
24 authors
25 deps
26 rdeps
27 );
28  
29 # XXX also add author instead of just release name, since PAUSE allows 2
30 # different authors to have the same filename.
31  
32 98 my %builtin_file_skip_list = (
33 'Perl-ToPerl6-0.031.tar.gz' => 'too big, causes Archive::Tar to go out of mem', # 2016-02-10
34 );
35  
36 98 my %builtin_file_skip_list_sub = (
37 'CharsetDetector-2.0.2.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-02-17
38 'Crypt-GeneratePassword-0.05.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-02-17
39 'Encode-Detect-CJK-2.0.2.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-02-17
40 'Shipment-0.13.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-02-17
41 'Shipment-2.00.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-02-17
42 'Shipment-2.01.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-06-23
43 'Shipment-2.02.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-06-29
44 'Shipment-2.03.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2016-09-06
45 'Shipment-3.01.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2018-02-08
46 'Shipment-3.02.tar.gz' => 'segfaults Compiler::Lexer 0.22', # 2019-07-23
47 'App-IndonesianBankingUtils-0.07.tar.gz' => 'segfaults at phase 3/3', # 2016-08-18
48 'Bencher-Scenarios-HashSlicing-0.003.tar.gz' => 'eats memory', # 2020-03-04
49 );
50  
51 98 our %SPEC;
52  
53 # BEGIN argument specifications.
54  
55 # %argspecFOO is the new naming scheme and we will eventually switch to this.
56 # %FOO_args is the old naming scheme.
57  
58 our %common_args = (
59 cpan => {
60 schema => 'dirname*',
61 summary => 'Location of your local CPAN mirror, e.g. /path/to/cpan',
62 description => <<'_',
63  
64 Defaults to C<~/cpan>.
65  
66 _
67 # default will be set in _set_args_default
68 tags => ['common'],
69 },
70 index_name => {
71 summary => 'Filename of index',
72 schema => 'filename*',
73 default => 'index.db', # will also be checked/set in _set_args_default
74 tags => ['common'],
75 description => <<'_',
76  
77 If `index_name` is a filename without any path, e.g. `index.db` then index will
78 be located in the top-level of `cpan`. If `index_name` contains a path, e.g.
79 `./index.db` or `/home/ujang/lcpan.db` then the index will be located solely
80 using the `index_name`.
81  
82 _
83 0 ▶ completion => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
84 0 my %args = @_;
85 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
86 0 my $cmdline = $args{cmdline};
87 0 my $r = $args{r};
88  
89 0 ▶ return undef unless $cmdline;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmdline 0 0 0
90  
91 # force reading config file
92 0 $r->{read_config} = 1;
93 0 my $res = $cmdline->parse_argv($r);
94  
95 0 my $args = $res->[2];
96 0 _set_args_default($args);
97  
98 0 require Complete::File;
99 0 require Complete::Util;
100 Complete::Util::hashify_answer(
101 Complete::File::complete_file(
102 word => $word,
103 starting_path => $args->{cpan},
104 0 ▶ filter => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
105 # dir (to dig down deeper) or index.db*
106 0 ▶ (-d $_[0]) || $_[0] =~ /index\.db/;
Branch: 1 branch
BranchTrueFalseTotal
-d $_[0] or $_[0] =~ /index\.db/ 0 0 0
107 },
108 0 ),
109 {path_sep=>'/'},
110 );
111 },
112 },
113 98 use_bootstrap => {
114 summary => 'Whether to use bootstrap database from App-lcpan-Bootstrap',
115 schema => 'bool*',
116 default => 1, # will also be checked/set in _set_args_default
117 description => <<'_',
118  
119 If you are indexing your private CPAN-like repository, you want to turn this
120 off.
121  
122 _
123 tags => ['common'],
124 },
125 update_db_schema => {
126 summary => 'Whether to update database schema to the latest',
127 'summary.alt.bool.not' => 'Do not update database schema to the latest',
128 schema => 'bool*',
129 default => 1, # will also be checked/set in _set_args_default
130 description => <<'_',
131  
132 By default, when the application starts and reads the index database, it updates
133 the database schema to the latest if the database happens to be last updated by
134 an older version of the application and has the old database schema (since
135 database schema is updated from time to time, for example at 1.070 the database
136 schema is at version 15).
137  
138 When you disable this option, the application will not update the database
139 schema. This option is for testing only, because it will probably cause the
140 application to run abnormally and then die with a SQL error when reading/writing
141 to the database.
142  
143 Note that in certain modes e.g. doing tab completion, the application also will
144 not update the database schema.
145  
146 _
147 tags => ['common'],
148 },
149 );
150  
151 98 our %all_args = (
152 all => {
153 schema => 'bool',
154 cmdline_aliases => {a=>{}},
155 },
156 );
157  
158 98 our %detail_args = (
159 detail => {
160 schema => 'bool',
161 cmdline_aliases => {l=>{}},
162 },
163 );
164  
165 98 our %query_args = (
166 query => {
167 summary => 'Search query',
168 schema => 'str*',
169 cmdline_aliases => {q=>{}},
170 pos => 0,
171 tags => ['category:filtering'],
172 },
173 %detail_args,
174 );
175  
176 98 our %query_multi_args = (
177 query => {
178 summary => 'Search query',
179 schema => ['array*', of=>'str*'],
180 cmdline_aliases => {q=>{}},
181 pos => 0,
182 slurpy => 1,
183 tags => ['category:filtering'],
184 },
185 detail => {
186 schema => 'bool',
187 cmdline_aliases => {l=>{}},
188 },
189 or => {
190 summary => 'When there are more than one query, perform OR instead of AND logic',
191 schema => ['bool', is=>1],
192 tags => ['category:filtering'],
193 },
194 );
195  
196 98 our %fauthor_args = (
197 author => {
198 summary => 'Filter by author',
199 schema => 'str*',
200 cmdline_aliases => {a=>{}},
201 completion => \&_complete_cpanid,
202 tags => ['category:filtering'],
203 },
204 );
205  
206 98 our %fdist_args = (
207 dist => {
208 summary => 'Filter by distribution',
209 schema => 'perl::distname*',
210 cmdline_aliases => {d=>{}},
211 completion => \&_complete_dist,
212 tags => ['category:filtering'],
213 },
214 );
215  
216 98 our %flatest_args = (
217 latest => {
218 schema => ['bool*'],
219 tags => ['category:filtering'],
220 },
221 );
222  
223 98 our %file_id_args = (
224 file_id => {
225 summary => 'Filter by file ID',
226 schema => 'posint*',
227 #completion => \&_complete_file_id,
228 tags => ['category:filtering'],
229 },
230 );
231  
232 98 our %finclude_core_args = (
233 include_core => {
234 summary => 'Include core modules',
235 'summary.alt.bool.not' => 'Exclude core modules',
236 schema => 'bool',
237 default => 1,
238 tags => ['category:filtering'],
239 },
240 );
241  
242 98 our %finclude_noncore_args = (
243 include_noncore => {
244 summary => 'Include non-core modules',
245 'summary.alt.bool.not' => 'Exclude non-core modules',
246 schema => 'bool',
247 default => 1,
248 tags => ['category:filtering'],
249 },
250 );
251  
252 98 our %finclude_indexed_args = (
253 include_indexed => {
254 summary => 'Include modules that are indexed (listed in 02packages.details.txt.gz)',
255 'summary.alt.bool.not' => 'Exclude modules that are indexed (listed in 02packages.details.txt.gz)',
256 schema => 'bool',
257 default => 1,
258 tags => ['category:filtering'],
259 },
260 );
261  
262 our %finclude_unindexed_args = (
263 include_unindexed => {
264 summary => 'Include modules that are not indexed (not listed in 02packages.details.txt.gz)',
265 'summary.alt.bool.not' => 'Exclude modules that are not indexed (not listed in 02packages.details.txt.gz)',
266 schema => 'bool',
267 default => 1,
268 cmdline_aliases => {
269 0 ▶ broken => {is_flag=>1, summary => 'Alias for --exclude-indexed --include-unindexed', code => sub { $_[0]{include_unindexed}=1; $_[0]{include_indexed}=0 }},
Subroutine __ANON__: not called CC=1 SCAR=6.9
270 },
271 98 tags => ['category:filtering'],
272 },
273 );
274  
275 98 our %fctime_args = (
276 added_since => {
277 summary => 'Include only records that are added since a certain date',
278 schema => ['date*', 'x.perl.coerce_rules' => ['From_str::natural']],
279 tags => ['category:filtering'],
280 },
281 added_since_last_index_update => {
282 summary => 'Include only records that are added since the last index update',
283 schema => 'true*',
284 tags => ['category:filtering'],
285 },
286 added_since_last_n_index_updates => {
287 summary => 'Include only records that are added since the last N index updates',
288 schema => 'posint*',
289 tags => ['category:filtering'],
290 },
291 );
292  
293 98 our %fmtime_args = (
294 updated_since => {
295 summary => 'Include only records that are updated since certain date',
296 schema => ['date*', 'x.perl.coerce_rules' => ['From_str::natural']],
297 tags => ['category:filtering'],
298 },
299 updated_since_last_index_update => {
300 summary => 'Include only records that are updated since the last index update',
301 schema => 'true*',
302 tags => ['category:filtering'],
303 },
304 updated_since_last_n_index_updates => {
305 summary => 'Include only records that are updated since the last N index updates',
306 schema => 'posint*',
307 tags => ['category:filtering'],
308 },
309 );
310  
311 98 our %fctime_or_mtime_args = (
312 added_or_updated_since => {
313 summary => 'Include only records that are added/updated since a certain date',
314 schema => ['date*', 'x.perl.coerce_rules' => ['From_str::natural']],
315 cmdline_aliases => {since=>{}},
316 tags => ['category:filtering'],
317 },
318 added_or_updated_since_last_index_update => {
319 summary => 'Include only records that are added/updated since the last index update',
320 schema => 'true*',
321 cmdline_aliases => {since_last_index_update=>{}},
322 tags => ['category:filtering'],
323 },
324 added_or_updated_since_last_n_index_updates => {
325 summary => 'Include only records that are added/updated since the last N index updates',
326 schema => 'posint*',
327 cmdline_aliases => {since_last_n_index_updates=>{}},
328 tags => ['category:filtering'],
329 },
330 );
331  
332 98 our %perl_version_args = (
333 perl_version => {
334 summary => 'Set base Perl version for determining core modules',
335 schema => 'str*',
336 default => "$^V",
337 cmdline_aliases => {V=>{}},
338 },
339 );
340  
341 98 our %random_args = (
342 random => {
343 summary => 'Random sort',
344 schema => 'true*',
345 tags => ['category:ordering'],
346 },
347 );
348  
349 our %sort_args_for_authors = (
350 sort => {
351 summary => 'Sort the result',
352 98 schema => ['array*', of=>['str*', in=>[map {($_,"-$_")} qw/id name email rec_mtime/]]],
353 default => ['id'],
354 tags => ['category:ordering'],
355 },
356 %random_args,
357 );
358  
359 our %sort_args_for_mods = (
360 sort => {
361 summary => 'Sort the result',
362 98 schema => ['array*', of=>['str*', in=>[map {($_,"-$_")} qw/module author rdeps rel_mtime/]]],
363 default => ['module'],
364 tags => ['category:ordering'],
365 },
366 %random_args,
367 );
368  
369 our %sort_args_for_dists = (
370 sort => {
371 summary => 'Sort the result',
372 98 schema => ['array*', of=>['str*', in=>[map {($_,"-$_")} qw/dist author release rel_size rel_mtime abstract/]]],
373 default => ['dist'],
374 tags => ['category:ordering'],
375 },
376 %random_args,
377 );
378  
379 # XXX should it be put in App/lcpan/Cmd/subs.pm?
380 our %sort_args_for_subs = (
381 sort => {
382 summary => 'Sort the result',
383 98 schema => ['array*', of=>['str*', in=>[map {($_,"-$_")} qw/sub package linum author/]]],
384 default => ['sub'],
385 tags => ['category:ordering'],
386 },
387 %random_args,
388 );
389  
390 98 our %paging_args = (
391 result_limit => {
392 summary => 'Only return a certain number of records',
393 schema => 'uint*',
394 tags => ['category:paging'],
395 },
396 result_start => {
397 summary => 'Only return starting from the n\'th record',
398 schema => 'posint*',
399 default => 1,
400 tags => ['category:paging'],
401 },
402 );
403  
404 98 our %full_path_args = (
405 full_path => {
406 schema => ['bool*' => is=>1],
407 tags => ['expose-fs-path'],
408 },
409 );
410  
411 98 our %no_path_args = (
412 no_path => {
413 schema => ['bool*' => is=>1],
414 },
415 );
416  
417 98 our %mod_args = (
418 module => {
419 schema => 'perl::modname*',
420 req => 1,
421 pos => 0,
422 completion => \&_complete_mod,
423 },
424 );
425  
426 98 our %mods_args = (
427 modules => {
428 schema => ['array*', of=>'perl::modname*', min_len=>1],
429 'x.name.is_plural' => 1,
430 req => 1,
431 pos => 0,
432 slurpy => 1,
433 cmdline_src => 'stdin_or_args',
434 element_completion => \&_complete_mod,
435 },
436 );
437  
438 98 our %argspec0opt_modules = (
439 modules => {
440 schema => ['array*', of=>'perl::modname*', min_len=>1],
441 'x.name.is_plural' => 1,
442 pos => 0,
443 slurpy => 1,
444 cmdline_src => 'stdin_or_args',
445 element_completion => \&_complete_mod,
446 },
447 );
448  
449 98 our %argspecopt_mods = (
450 modules => {
451 schema => ['array*', of=>'perl::modname*', min_len=>1],
452 'x.name.is_plural' => 1,
453 element_completion => \&_complete_mod,
454 },
455 );
456  
457 98 our %pods_args = (
458 pods => {
459 schema => ['array*', of=>'perl::modname*', min_len=>1],
460 'x.name.is_plural' => 1,
461 'x.name.singular' => 'pod',
462 req => 1,
463 pos => 0,
464 slurpy => 1,
465 cmdline_src => 'stdin_or_args',
466 #element_completion => \&_complete_pod, # will be too slow with the current schema
467 },
468 );
469  
470 98 our %mod_or_dist_args = (
471 module_or_dist => {
472 summary => 'Module or dist name',
473 schema => ['str*', # XXX perl::mod_or_distname
474 ],
475 req => 1,
476 pos => 0,
477 completion => \&App::lcpan::_complete_mod_or_dist,
478 },
479 );
480  
481 98 our %mods_or_dists_args = (
482 modules_or_dists => {
483 'x.name.is_plural' => 1,
484 'x.name.singular' => 'module_or_dist',
485 summary => 'Module or dist names',
486 schema => ['array*', of => ['str*']], # XXX perl::mod_or_distname
487 req => 1,
488 pos => 0,
489 slurpy => 1,
490 element_completion => \&App::lcpan::_complete_mod_or_dist,
491 },
492 );
493  
494 98 our %script_args = (
495 script => {
496 schema => 'filename::unix*',
497 req => 1,
498 pos => 0,
499 completion => \&_complete_script,
500 },
501 );
502  
503 98 our %scripts_args = (
504 scripts => {
505 schema => ['array*', of=>'filename::unix*', min_len=>1],
506 'x.name.is_plural' => 1,
507 req => 1,
508 pos => 0,
509 slurpy => 1,
510 cmdline_src => 'stdin_or_args',
511 element_completion => \&_complete_script,
512 },
513 );
514  
515 98 our %mod_or_dist_or_script_args = (
516 module_or_dist_or_script => {
517 # XXX coerce rule: from string: convert / to ::
518 summary => 'Module or dist or script name',
519 schema => ['str*',
520 ],
521 req => 1,
522 pos => 0,
523 completion => \&App::lcpan::_complete_mod_or_dist_or_script,
524 },
525 );
526  
527 98 our %author_args = (
528 author => {
529 schema => 'str*',
530 req => 1,
531 pos => 0,
532 completion => \&_complete_cpanid,
533 },
534 );
535  
536 98 our %authors_args = (
537 authors => {
538 schema => ['array*', of=>'str*', min_len=>1],
539 'x.name.is_plural' => 1,
540 req => 1,
541 pos => 0,
542 slurpy => 1,
543 cmdline_src => 'stdin_or_args',
544 element_completion => \&_complete_cpanid,
545 },
546 );
547  
548 98 our %argspecsopt_module_authors = (
549 module_authors => {
550 summary => 'Only list depended modules published by specified author(s)',
551 'x.name.is_plural' => 1,
552 schema => ['array*', of=>'str*'],
553 element_completion => \&App::lcpan::_complete_cpanid,
554 tags => ['category:filtering'],
555 },
556 module_authors_arent => {
557 summary => 'Do not list depended modules published by specified author(s)',
558 'x.name.is_plural' => 1,
559 'x.name.singular' => 'module_author_isnt',
560 schema => ['array*', of=>'str*'],
561 element_completion => \&App::lcpan::_complete_cpanid,
562 tags => ['category:filtering'],
563 },
564 );
565  
566 98 our %argspecsopt_dist_authors = (
567 dist_authors => {
568 summary => 'Only select dependent distributions published by specified author(s)',
569 'x.name.is_plural' => 1,
570 schema => ['array*', of=>'str*'],
571 element_completion => \&App::lcpan::_complete_cpanid,
572 tags => ['category:filtering'],
573 },
574 dist_authors_arent => {
575 summary => 'Do not select dependent distributions published by specified author(s)',
576 'x.name.is_plural' => 1,
577 'x.name.singular' => 'dist_author_isnt',
578 schema => ['array*', of=>'str*'],
579 element_completion => \&App::lcpan::_complete_cpanid,
580 tags => ['category:filtering'],
581 },
582 );
583  
584 98 our %dist_args = (
585 dist => {
586 schema => 'perl::distname*',
587 req => 1,
588 pos => 0,
589 completion => \&_complete_dist,
590 },
591 );
592  
593 98 our %dists_args = (
594 dists => {
595 summary => 'Distribution names (e.g. Foo-Bar)',
596 schema => ['array*', of=>'perl::distname*', min_len=>1],
597 'x.name.is_plural' => 1,
598 req => 1,
599 pos => 0,
600 slurpy => 1,
601 cmdline_src => 'stdin_or_args',
602 element_completion => \&_complete_dist,
603 },
604 );
605  
606 98 our %argspecopt_dists = (
607 dists => {
608 summary => 'Distribution names (e.g. Foo-Bar)',
609 schema => ['array*', of=>'perl::distname*', min_len=>1],
610 'x.name.is_plural' => 1,
611 element_completion => \&_complete_dist,
612 },
613 );
614  
615 98 our %dists_with_optional_vers_args = (
616 dists => {
617 summary => 'Distribution names (with optional version suffix, e.g. Foo-Bar@1.23)',
618 schema => ['array*', of=>'perl::distname_with_optional_ver*', min_len=>1],
619 'x.name.is_plural' => 1,
620 req => 1,
621 pos => 0,
622 slurpy => 1,
623 cmdline_src => 'stdin_or_args',
624 element_completion => \&_complete_dist,
625 },
626 );
627  
628 98 our %argspec0opt_dists_with_optional_vers = (
629 dists => {
630 summary => 'Distribution names (with optional version suffix, e.g. Foo-Bar@1.23)',
631 schema => ['array*', of=>'perl::distname_with_optional_ver*', min_len=>1],
632 'x.name.is_plural' => 1,
633 pos => 0,
634 slurpy => 1,
635 cmdline_src => 'stdin_or_args',
636 element_completion => \&_complete_dist,
637 },
638 );
639  
640 98 our %rel_args = (
641 release => {
642 schema => 'str*', # XXX perl::relname
643 req => 1,
644 pos => 0,
645 completion => \&_complete_rel,
646 },
647 );
648  
649 98 our %dist_or_rel_args = (
650 dist_or_release => {
651 schema => 'str*', # XXX [any, of=>[perl::relname, perl::distname]]
652 req => 1,
653 pos => 0,
654 completion => \&_complete_dist, # XXX dist/release
655 },
656 );
657  
658 98 our %sort_args_for_rels = (
659 sort => {
660 schema => ['array*', of=>['str*', in=>[qw/author -author size -size name -name mtime -mtime/]]],
661 default => ['name'],
662 tags => ['category:sorting'],
663 },
664 %random_args,
665 );
666  
667 98 our %overwrite_args = (
668 overwrite => {
669 summary => 'Whether to overwrite existing file',
670 schema => ['bool*', is=>1],
671 cmdline_aliases => {o=>{}},
672 },
673 );
674  
675 98 $SPEC{':package'} = {
676 v => 1.1,
677 summary => 'Manage local CPAN mirror',
678 };
679  
680 0 ▶sub _set_args_default {
Subroutine _set_args_default: not called CC=6 SCAR=37.4
681 0 my $args = shift;
682 0 ▶ if (!$args->{cpan}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"cpan"}) 0 0 0
683 0 require File::HomeDir;
684 0 $args->{cpan} = File::HomeDir->my_home . '/cpan';
685 }
686 0 ▶ $args->{index_name} //= 'index.db';
Condition0%0/2
$args->{"index_name"} //= "index.db"
l!l
00
MC/DC0%0/1
$args->{"index_name"} //= "index.db"
$args->{"index_name"}
Truth table0%0/2
A
A= $args->{"index_name"}
Aresult
11
00
687 0 ▶ if (!defined($args->{num_backups})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{"num_backups"}) 0 0 0
688 0 $args->{num_backups} = 7;
689 }
690 0 ▶ $args->{use_bootstrap} //= 1;
Condition0%0/2
$args->{"use_bootstrap"} //= 1
l!l
00
MC/DC0%0/1
$args->{"use_bootstrap"} //= 1
$args->{"use_bootstrap"}
Truth table0%0/2
A
A= $args->{"use_bootstrap"}
Aresult
11
00
691 0 ▶ $args->{update_db_schema} //= 1;
Condition0%0/2
$args->{"update_db_schema"} //= 1
l!l
00
MC/DC0%0/1
$args->{"update_db_schema"} //= 1
$args->{"update_db_schema"}
Truth table0%0/2
A
A= $args->{"update_db_schema"}
Aresult
11
00
692 }
693  
694 # set {added_,updated_,added_or_udpated_}since from
695 # {added_,updated_,added_or_updated_}since_last_{index_update,n_index_updates},
696 # set, since SQL query will usually use the former
697 0 ▶sub _set_since {
Subroutine _set_since: not called CC=30 SCAR=68.4
698 0 my ($args, $dbh) = @_;
699  
700 0 my $num_sinces = 0;
701 0 ▶ if (defined $args->{added_since}) { $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"added_since"}) 0 0 0
702 0 ▶ if (defined $args->{updated_since}) { $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"updated_since"}) 0 0 0
703 0 ▶ if (defined $args->{added_or_updated_since}) { $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"added_or_updated_since"}) 0 0 0
704 0 ▶ if (defined $args->{added_since_last_index_update} || defined $args->{updated_since_last_index_update} || defined $args->{added_or_updated_since_last_index_update}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"added_since_last_index_update"} or defined $args->{"updated_since_last_index_update"} or defined $args->{"added_or_updated_since_last_index_update"}) 0 0 0
Condition0%0/6
defined $args->{"added_since_last_index_update"} or defined $args->{"updated_since_last_index_update"} or defined $args->{"added_or_updated_since_last_index_update"}
l!l&&r!l&&!r
000
defined $args->{"added_since_last_index_update"} or defined $args->{"updated_since_last_index_update"}
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $args->{"added_since_last_index_update"} or defined $args->{"updated_since_last_index_update"} or defined $args->{"added_or_updated_since_last_index_update"}
defined $args->{"added_since_last_index_update"} defined $args->{"updated_since_last_index_update"} defined $args->{"added_or_updated_since_last_index_update"}
Truth table0%0/4
A or B or C
A= defined $args->{"added_since_last_index_update"}B= defined $args->{"updated_since_last_index_update"}C= defined $args->{"added_or_updated_since_last_index_update"}
ABCresult
1XX1
01X1
0011
0000
705 0 my ($time) = $dbh->selectrow_array("SELECT date FROM log WHERE category='update_index' AND summary LIKE 'Begin%' ORDER BY date DESC");
706 0 ▶ die "Index has not been updated at all, cannot use {added_,updated_,added_or_updated_}since_last_index_update option" unless $time;
Branch: 1 branch
BranchTrueFalseTotal
unless $time 0 0 0
707 0 ▶ if (delete $args->{added_since_last_index_update}) { $args->{added_since} //= $time; log_trace "Setting added_since=%s", $time; $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args->{"added_since_last_index_update"}) 0 0 0
Condition0%0/3
$args->{"added_since"} //= $time
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"added_since"} //= $time
$args->{"added_since"} $time
Truth table0%0/3
A //= B
A= $args->{"added_since"}B= $time
ABresult
1X1
011
000
708 0 ▶ if (delete $args->{updated_since_last_index_update}) { $args->{updated_since} //= $time; log_trace "Setting updated_since=%s", $time; $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args->{"updated_since_last_index_update"}) 0 0 0
Condition0%0/3
$args->{"updated_since"} //= $time
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"updated_since"} //= $time
$args->{"updated_since"} $time
Truth table0%0/3
A //= B
A= $args->{"updated_since"}B= $time
ABresult
1X1
011
000
709 0 ▶ if (delete $args->{added_or_updated_since_last_index_update}) { $args->{added_or_updated_since} //= $time; log_trace "Setting added_or_updated_since=%s", $time; $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args->{"added_or_updated_since_last_index_update"}) 0 0 0
Condition0%0/3
$args->{"added_or_updated_since"} //= $time
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"added_or_updated_since"} //= $time
$args->{"added_or_updated_since"} $time
Truth table0%0/3
A //= B
A= $args->{"added_or_updated_since"}B= $time
ABresult
1X1
011
000
710 }
711 0 ▶ if (defined $args->{added_since_last_n_index_updates} || defined $args->{updated_since_last_n_index_updates} || defined $args->{added_or_updated_since_last_n_index_updates}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"added_since_last_n_index_updates"} or defined $args->{"updated_since_last_n_index_updates"} or defined $args->{"added_or_updated_since_last_n_index_updates"}) 0 0 0
Condition0%0/6
defined $args->{"added_since_last_n_index_updates"} or defined $args->{"updated_since_last_n_index_updates"} or defined $args->{"added_or_updated_since_last_n_index_updates"}
l!l&&r!l&&!r
000
defined $args->{"added_since_last_n_index_updates"} or defined $args->{"updated_since_last_n_index_updates"}
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $args->{"added_since_last_n_index_updates"} or defined $args->{"updated_since_last_n_index_updates"} or defined $args->{"added_or_updated_since_last_n_index_updates"}
defined $args->{"added_since_last_n_index_updates"} defined $args->{"updated_since_last_n_index_updates"} defined $args->{"added_or_updated_since_last_n_index_updates"}
Truth table0%0/4
A or B or C
A= defined $args->{"added_since_last_n_index_updates"}B= defined $args->{"updated_since_last_n_index_updates"}C= defined $args->{"added_or_updated_since_last_n_index_updates"}
ABCresult
1XX1
01X1
0011
0000
712 0 ▶ my $n = int($args->{added_since_last_n_index_updates} // $args->{updated_since_last_n_index_updates} // $args->{added_or_updated_since_last_n_index_updates});
Condition0%0/6
($args->{"added_since_last_n_index_updates"} // $args->{"updated_since_last_n_index_updates"}) // $args->{"added_or_updated_since_last_n_index_updates"}
l!l&&r!l&&!r
000
$args->{"added_since_last_n_index_updates"} // $args->{"updated_since_last_n_index_updates"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($args->{"added_since_last_n_index_updates"} // $args->{"updated_since_last_n_index_updates"}) // $args->{"added_or_updated_since_last_n_index_updates"}
$args->{"added_since_last_n_index_updates"} $args->{"updated_since_last_n_index_updates"} $args->{"added_or_updated_since_last_n_index_updates"}
Truth table0%0/4
A // B // C
A= $args->{"added_since_last_n_index_updates"}B= $args->{"updated_since_last_n_index_updates"}C= $args->{"added_or_updated_since_last_n_index_updates"}
ABCresult
1XX1
01X1
0011
0000
713 0 ▶ $n = 1 if $n < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 1 0 0 0
714 0 my $sth = $dbh->prepare("SELECT date FROM log WHERE category='update_index' AND summary LIKE 'Begin%' ORDER BY date DESC");
715 0 $sth->execute;
716 0 my $i = 0;
717 0 my $time;
718 0 ▶ 1 while ++$i <= $n && (($time) = $sth->fetchrow_array);
Branch: 1 branch
BranchTrueFalseTotal
++$i <= $n and ($time) = $sth->fetchrow_array and do { '???' } 0 0 0
Condition0%0/3
++$i <= $n and ($time) = $sth->fetchrow_array
!ll&&!rl&&r
000
MC/DC0%0/2
++$i <= $n and ($time) = $sth->fetchrow_array
++$i <= $n ($time) = $sth->fetchrow_array
Truth table0%0/3
A and B
A= ++$i <= $nB= ($time) = $sth->fetchrow_array
ABresult
0X0
100
111
719 0 ▶ die "Index has not been updated that many times, please set a lower number for {,added_,updated_}since_last_n_index_updates option" if $i < $n;
Branch: 1 branch
BranchTrueFalseTotal
if $i < $n 0 0 0
720 0 ▶ if (delete $args->{added_since_last_n_index_updates}) { $args->{added_since} //= $time; log_trace "Setting added_since=%s", $time; $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args->{"added_since_last_n_index_updates"}) 0 0 0
Condition0%0/3
$args->{"added_since"} //= $time
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"added_since"} //= $time
$args->{"added_since"} $time
Truth table0%0/3
A //= B
A= $args->{"added_since"}B= $time
ABresult
1X1
011
000
721 0 ▶ if (delete $args->{updated_since_last_n_index_updates}) { $args->{updated_since} //= $time; log_trace "Setting updated_since=%s", $time; $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args->{"updated_since_last_n_index_updates"}) 0 0 0
Condition0%0/3
$args->{"updated_since"} //= $time
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"updated_since"} //= $time
$args->{"updated_since"} $time
Truth table0%0/3
A //= B
A= $args->{"updated_since"}B= $time
ABresult
1X1
011
000
722 0 ▶ if (delete $args->{added_or_updated_since_last_n_index_updates}) { $args->{added_or_updated_since} //= $time; log_trace "Setting added_or_updated_since=%s", $time; $num_sinces++ }
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args->{"added_or_updated_since_last_n_index_updates"}) 0 0 0
Condition0%0/3
$args->{"added_or_updated_since"} //= $time
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"added_or_updated_since"} //= $time
$args->{"added_or_updated_since"} $time
Truth table0%0/3
A //= B
A= $args->{"added_or_updated_since"}B= $time
ABresult
1X1
011
000
723 }
724  
725 0 ▶ die "Multiple {added_,updated_,added_or_updated_}since options set, please set only one to avoid confusion" if $num_sinces > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $num_sinces > 1 0 0 0
726 }
727  
728 0 ▶sub _add_since_where_clause {
Subroutine _add_since_where_clause: not called CC=4 SCAR=30.0
729 0 my ($args, $where, $table) = @_;
730 0 ▶ if (defined $args->{added_since} ) { push @$where, "$table.rec_ctime >= ". (0+$args->{added_since}) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"added_since"}) 0 0 0
731 0 ▶ if (defined $args->{updated_since}) { push @$where, "($table.rec_mtime >= ". (0+$args->{updated_since}). " AND $table.rec_ctime < ".(0+$args->{updated_since}). ")" }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"updated_since"}) 0 0 0
732 0 ▶ if (defined $args->{added_or_updated_since}) { push @$where, "($table.rec_ctime >= ". (0+$args->{added_or_updated_since}). " OR $table.rec_mtime >= ". (0+$args->{added_or_updated_since}). ")" }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"added_or_updated_since"}) 0 0 0
733 }
734  
735 0 ▶sub _fmt_time {
Subroutine _fmt_time: not called CC=2 SCAR=17.9
736 0 require POSIX;
737  
738 0 my $epoch = shift;
739 0 ▶ return '' unless defined($epoch);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $epoch 0 0 0
740 0 POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($epoch));
741 }
742  
743 0 ▶sub _numify_ver {
Subroutine _numify_ver: not called CC=2 SCAR=17.9
744 0 my $v;
745 0 eval { $v = version->parse($_[0]) };
746 0 ▶ $v ? $v->numify : undef;
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
747 }
748  
749 0 ▶sub _dists_with_optional_vers2file_ids {
Subroutine _dists_with_optional_vers2file_ids: not called CC=7 SCAR=40.3
750 0 my ($dbh, $dists_with_optional_vers) = @_;
751  
752 0 ▶ return [] unless $dists_with_optional_vers;
Branch: 1 branch
BranchTrueFalseTotal
unless $dists_with_optional_vers 0 0 0
753 0 my $file_ids = [];
754 0 for my $dist_with_optional_ver (@$dists_with_optional_vers) {
755 0 my $dist = $dist_with_optional_ver;
756 0 my $file_id;
757 0 ▶ if ($dist =~ s/@(.+)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist =~ s/@(.+)$//) { } 0 0 0
758 0 my $ver = $1;
759 0 ($file_id) = $dbh->selectrow_array("SELECT id FROM file WHERE dist_name=? AND dist_version=?", {}, $dist, $ver);
760 0 ▶ do { warn "lcpan: No such dist '$dist' version '$ver'\n"; next } unless $file_id;
Branch: 1 branch
BranchTrueFalseTotal
unless ($file_id) 0 0 0
761 } else {
762 0 ($file_id) = $dbh->selectrow_array("SELECT id FROM file WHERE dist_name=? AND is_latest_dist=1", {}, $dist);
763 0 ▶ do { warn "lcpan: No such dist '$dist'\n"; next } unless $file_id;
Branch: 1 branch
BranchTrueFalseTotal
unless ($file_id) 0 0 0
764 }
765 0 ▶ push @$file_ids, $file_id unless grep { $file_id == $_ } @$file_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$file_id == $_;} @$file_ids 0 0 0
766 }
767  
768 0 $file_ids;
769 }
770  
771 0 ▶sub _modules2file_ids {
Subroutine _modules2file_ids: not called CC=6 SCAR=37.4
772 0 my ($dbh, $modules) = @_;
773  
774 0 ▶ return [] unless $modules && @$modules;
Branch: 1 branch
BranchTrueFalseTotal
unless $modules and @$modules 0 0 0
Condition0%0/3
$modules and @$modules
!ll&&!rl&&r
000
MC/DC0%0/2
$modules and @$modules
$modules @$modules
Truth table0%0/3
A and B
A= $modulesB= @$modules
ABresult
0X0
100
111
775 0 my $file_ids = [];
776 0 for my $module (@$modules) {
777 0 my ($file_id) = $dbh->selectrow_array("SELECT file_id FROM module WHERE name=?", {}, $module);
778 0 ▶ do { warn "lcpan: No such module '$module'\n"; next } unless $file_id;
Branch: 1 branch
BranchTrueFalseTotal
unless ($file_id) 0 0 0
779 0 ▶ push @$file_ids, $file_id unless grep { $file_id == $_ } @$file_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$file_id == $_;} @$file_ids 0 0 0
780 }
781  
782 0 $file_ids;
783 }
784  
785 0 ▶sub _dists2theirmods {
Subroutine _dists2theirmods: not called CC=7 SCAR=40.3
786 0 my ($dbh, $dists) = @_;
787  
788 0 ▶ return [] unless $dists;
Branch: 1 branch
BranchTrueFalseTotal
unless $dists 0 0 0
789 0 my $mods = [];
790 0 for my $dist (@$dists) {
791 0 my $sth = $dbh->prepare("SELECT name FROM module WHERE file_id IN (SELECT id FROM file WHERE dist_name=? AND is_latest_dist=1)");
792 0 $sth->execute($dist);
793 0 my @dist_mods;
794 0 ▶ while (my ($dist_mod) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($dist_mod) = $sth->fetchrow_array) 0 0 0
795 0 push @dist_mods, $dist_mod;
796 }
797 0 ▶ do { warn "lcpan: No such distribution or distribution does not contain any module: '$dist'\n"; next } unless @dist_mods;
Branch: 1 branch
BranchTrueFalseTotal
unless (@dist_mods) 0 0 0
798 0 ▶ for my $dist_mod (@dist_mods) { push @$mods, $dist_mod unless grep { $dist_mod eq $_ } @$mods }
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$dist_mod eq $_;} @$mods 0 0 0
799 }
800  
801 0 $mods;
802 }
803  
804 0 ▶sub _fullpath {
Subroutine _fullpath: not called CC=1 SCAR=6.9
805 0 my ($filename, $cpan, $cpanid) = @_;
806 0 $cpanid = uc($cpanid); # just to be safe
807 0 "$cpan/authors/id/".substr($cpanid, 0, 1)."/".
808 substr($cpanid, 0, 2)."/$cpanid/$filename";
809 }
810  
811 0 ▶sub _relpath {
Subroutine _relpath: not called CC=1 SCAR=6.9
812 0 my ($filename, $cpanid) = @_;
813 0 $cpanid = uc($cpanid); # just to be safe
814 0 substr($cpanid, 0, 1)."/".
815 substr($cpanid, 0, 2)."/$cpanid/$filename";
816 }
817  
818 0 ▶sub _dblog {
Subroutine _dblog: not called CC=1 SCAR=1.2
819 98 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
820  
821 0 my ($dbh, $level, $category, $summary) = @_;
822 $dbh->do("INSERT INTO log (date,lcpan_version,pid, level,category,summary) VALUES (?,?,?, ?,?,?)", {},
823 0 time(), ${__PACKAGE__ . "::VERSION"}, $$,
824 $level, $category, $summary);
825 }
826  
827 0 ▶sub _fill_namespace {
Subroutine _fill_namespace: not called CC=9 SCAR=45.0
828 0 require DBIx::Util::Schema;
829 0 my $dbh = shift;
830  
831 0 my $has_rec_ctime = DBIx::Util::Schema::has_column($dbh, "namespace", "rec_ctime");
832 0 my $has_rec_mtime = DBIx::Util::Schema::has_column($dbh, "namespace", "rec_mtime");
833 0 my $sth_sel_mod = $dbh->prepare("SELECT name FROM module");
834 0 ▶ my $sth_ins_ns = $has_rec_ctime ?
Branch: 1 branch
BranchTrueFalseTotal
$has_rec_ctime ? : 0 0 0
835 $dbh->prepare("INSERT INTO namespace (name, rec_ctime, rec_mtime, num_sep, has_child, num_modules) VALUES (?,?,?,?,?,1)") :
836 $dbh->prepare("INSERT INTO namespace (name, num_sep, has_child, num_modules) VALUES (?,?,?,1)");
837 0 ▶ my $sth_upd_ns_inc_num_mod = $has_rec_mtime ?
Branch: 1 branch
BranchTrueFalseTotal
$has_rec_mtime ? : 0 0 0
838 $dbh->prepare("UPDATE namespace SET num_modules=num_modules+1, has_child=1, rec_mtime=? WHERE name=?") :
839 $dbh->prepare("UPDATE namespace SET num_modules=num_modules+1, has_child=1 WHERE name=?");
840 0 $sth_sel_mod->execute;
841 0 my %cache;
842 0 my $now = time();
843 0 ▶ while (my ($mod) = $sth_sel_mod->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($mod) = $sth_sel_mod->fetchrow_array) 0 0 0
844 0 my $has_child = 0;
845 0 while (1) {
846 0 ▶ if ($cache{$mod}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache{$mod}++) { } 0 0 0
847 0 ▶ $sth_upd_ns_inc_num_mod->execute(($has_rec_mtime ? ($now) : ()), $mod);
Branch: 1 branch
BranchTrueFalseTotal
$has_rec_mtime ? : 0 0 0
848 } else {
849 0 my $num_sep = 0;
850 0 ▶ while ($mod =~ /::/g) { $num_sep++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /::/g) 0 0 0
851 0 ▶ $sth_ins_ns->execute($mod, ($has_rec_ctime ? ($now, $now) : ()), $num_sep, $has_child);
Branch: 1 branch
BranchTrueFalseTotal
$has_rec_ctime ? : 0 0 0
852 }
853 0 ▶ $mod =~ s/::\w+\z// or last;
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ s/::\w+\z// or last 0 0 0
854 0 $has_child = 1;
855 }
856 }
857 }
858  
859 0 ▶sub _set_namespace {
Subroutine _set_namespace: not called CC=4 SCAR=30.0
860 0 my ($dbh, $mod) = @_;
861 0 my $sth_sel_ns = $dbh->prepare("SELECT name FROM namespace WHERE name=?");
862 0 my $sth_ins_ns = $dbh->prepare("INSERT INTO namespace (name, rec_ctime, rec_mtime, num_sep, has_child, num_modules) VALUES (?,?,?,?,?,1)");
863 0 my $sth_upd_ns_inc_num_mod = $dbh->prepare("UPDATE namespace SET num_modules=num_modules+1, has_child=1, rec_mtime=? WHERE name=?");
864  
865 0 my $has_child = 0;
866 0 my $now = time();
867 0 while (1) {
868 0 $sth_sel_ns->execute($mod);
869 0 my $row = $sth_sel_ns->fetchrow_arrayref;
870 0 ▶ if ($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) { } 0 0 0
871 0 $sth_upd_ns_inc_num_mod->execute($now, $mod);
872 } else {
873 0 my $num_sep = 0;
874 0 ▶ while ($mod =~ /::/g) { $num_sep++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /::/g) 0 0 0
875 0 $sth_ins_ns->execute($mod, $now, $now, $num_sep, $has_child);
876 }
877 0 ▶ $mod =~ s/::\w+\z// or last;
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ s/::\w+\z// or last 0 0 0
878 0 $has_child = 1;
879 }
880 }
881  
882 our $db_schema_spec = {
883 latest_v => 16,
884  
885 install => [
886 'CREATE TABLE author (
887 cpanid VARCHAR(20) NOT NULL PRIMARY KEY,
888 fullname VARCHAR(255) NOT NULL,
889 email TEXT,
890 rec_ctime INT,
891 rec_mtime INT
892 )',
893 'CREATE INDEX ix_author__rec_ctime ON author(rec_ctime)',
894 'CREATE INDEX ix_author__rec_mtime ON author(rec_mtime)',
895  
896 'CREATE TABLE file ( -- remember to keep schema in-sync with old_file
897 id INTEGER NOT NULL PRIMARY KEY,
898 name TEXT NOT NULL,
899 cpanid VARCHAR(20) NOT NULL REFERENCES author(cpanid),
900  
901 mtime INT,
902 size INT,
903  
904 -- file status: ok (archive type is known, content can be listed,
905 -- and at least some files can be extracted), nofile (file does not
906 -- exist in mirror), unsupported (archive type is not supported,
907 -- e.g. rar, pm.gz), err (cannot be opened/extracted for some
908 -- reason)
909  
910 file_status TEXT,
911 file_error TEXT,
912  
913 -- META.* processing status: ok (meta has been extracted and
914 -- parsed), err (META.json/META.yml has some error), nometa (no
915 -- META.json/META.yml found).
916  
917 meta_status TEXT,
918 meta_error TEXT,
919  
920 dist_name TEXT,
921 dist_abstract TEXT,
922 dist_version VARCHAR(20),
923 dist_version_numified VARCHAR(20),
924 is_latest_dist BOOLEAN,
925  
926 -- POD processing status: ok (POD has been extracted and
927 -- parsed/indexed).
928  
929 pod_status TEXT,
930  
931 -- sub processing status: ok (sub names have been parsed/indexed)
932  
933 sub_status TEXT,
934  
935 has_metajson INTEGER,
936 has_metayml INTEGER,
937 has_makefilepl INTEGER,
938 has_buildpl INTEGER,
939  
940 rec_ctime INT,
941 rec_mtime INT
942 )',
943 'CREATE UNIQUE INDEX ix_file__id ON file(id)', # not created automatically when there is another unique index?
944 'CREATE UNIQUE INDEX ix_file__cpanid__name ON file(cpanid,name)',
945 'CREATE INDEX ix_file__rec_ctime ON file(rec_ctime)',
946 'CREATE INDEX ix_file__rec_mtime ON file(rec_mtime)',
947 'CREATE INDEX ix_file__dist_name ON file(dist_name)',
948  
949 'CREATE TABLE old_file ( -- remember to keep schema in-sync with file
950 id INTEGER NOT NULL PRIMARY KEY,
951 name TEXT NOT NULL,
952 cpanid VARCHAR(20) NOT NULL, -- REFERENCES author(cpanid),
953  
954 mtime INT,
955 size INT,
956  
957 file_status TEXT,
958 file_error TEXT,
959  
960 meta_status TEXT,
961 meta_error TEXT,
962  
963 dist_name TEXT,
964 dist_abstract TEXT,
965 dist_version VARCHAR(20),
966 dist_version_numified VARCHAR(20),
967 is_latest_dist BOOLEAN,
968  
969 pod_status TEXT,
970  
971 sub_status TEXT,
972  
973 has_metajson INTEGER,
974 has_metayml INTEGER,
975 has_makefilepl INTEGER,
976 has_buildpl INTEGER,
977  
978 rec_ctime INT,
979 rec_mtime INT
980 )',
981 'CREATE UNIQUE INDEX ix_old_file__id ON old_file(id)',
982 'CREATE UNIQUE INDEX ix_old_file__cpanid__name ON old_file(cpanid,name)',
983 'CREATE INDEX ix_old_file__rec_ctime ON old_file(rec_ctime)',
984 'CREATE INDEX ix_old_file__rec_mtime ON old_file(rec_mtime)',
985 'CREATE INDEX ix_old_file__dist_name ON old_file(dist_name)',
986  
987 # files inside the release archive file
988 'CREATE TABLE content (
989 id INTEGER NOT NULL PRIMARY KEY,
990 file_id INTEGER NOT NULL REFERENCES file(id),
991 path TEXT NOT NULL,
992 package TEXT, -- only the first package declaration will be recorded
993 mtime INT,
994 size INT, -- uncompressed size
995 rec_ctime INT,
996 rec_mtime INT
997 )',
998 'CREATE UNIQUE INDEX ix_content__id ON content(id)', # not created automatically when there is another unique index?
999 'CREATE UNIQUE INDEX ix_content__file_id__path ON content(file_id, path)',
1000 'CREATE INDEX ix_content__package ON content(package)',
1001 'CREATE INDEX ix_content__rec_ctime ON content(rec_ctime)',
1002 'CREATE INDEX ix_content__rec_mtime ON content(rec_mtime)',
1003  
1004 'CREATE TABLE module ( -- remember to keep schema in-sync with old_module
1005 id INTEGER NOT NULL PRIMARY KEY,
1006 name VARCHAR(255) NOT NULL,
1007 cpanid VARCHAR(20) NOT NULL REFERENCES author(cpanid), -- [cache]
1008 file_id INTEGER NOT NULL,
1009 version VARCHAR(20),
1010 version_numified DECIMAL,
1011 content_id INTEGER REFERENCES content(id),
1012 abstract TEXT,
1013 rec_ctime INT,
1014 rec_mtime INT
1015 )',
1016 'CREATE UNIQUE INDEX ix_module__id ON module(id)', # not created automatically when there is another unique index?
1017 'CREATE UNIQUE INDEX ix_module__name ON module(name)',
1018 'CREATE INDEX ix_module__file_id ON module(file_id)',
1019 'CREATE INDEX ix_module__cpanid ON module(cpanid)',
1020 'CREATE INDEX ix_module__rec_ctime ON module(rec_ctime)',
1021 'CREATE INDEX ix_module__rec_mtime ON module(rec_mtime)',
1022  
1023 'CREATE TABLE old_module ( -- remember to keep schema in-sync with module
1024 id INTEGER NOT NULL PRIMARY KEY,
1025 name VARCHAR(255) NOT NULL,
1026 cpanid VARCHAR(20) NOT NULL, -- REFERENCES author(cpanid), -- [cache]
1027 file_id INTEGER NOT NULL,
1028 version VARCHAR(20),
1029 version_numified DECIMAL,
1030 content_id INTEGER, -- REFERENCES content(id),
1031 abstract TEXT,
1032 rec_ctime INT,
1033 rec_mtime INT
1034 )',
1035 'CREATE INDEX ix_old_module__id ON old_module(id)',
1036 'CREATE INDEX ix_old_module__name ON old_module(name)',
1037 'CREATE INDEX ix_old_module__file_id ON old_module(file_id)',
1038 'CREATE INDEX ix_old_module__cpanid ON old_module(cpanid)',
1039 'CREATE INDEX ix_old_module__rec_ctime ON old_module(rec_ctime)',
1040 'CREATE INDEX ix_old_module__rec_mtime ON old_module(rec_mtime)',
1041  
1042 'CREATE TABLE script ( -- remember to keep schema in-sync with old_script
1043 id INTEGER NOT NULL PRIMARY KEY,
1044 file_id INTEGER NOT NULL REFERENCES file(id), -- [cache]
1045 cpanid VARCHAR(20) NOT NULL REFERENCES author(cpanid), -- [cache]
1046 name TEXT NOT NULL,
1047 content_id INT REFERENCES content(id),
1048 abstract TEXT,
1049 rec_ctime INT,
1050 rec_mtime INT
1051 )',
1052 'CREATE UNIQUE INDEX ix_script__id ON script(id)', # not created automatically when there is another unique index?
1053 'CREATE UNIQUE INDEX ix_script__file_id__name ON script(file_id, name)',
1054 'CREATE INDEX ix_script__name ON script(name)',
1055 'CREATE INDEX ix_script__rec_ctime ON script(rec_ctime)',
1056 'CREATE INDEX ix_script__rec_mtime ON script(rec_mtime)',
1057  
1058 'CREATE TABLE old_script ( -- remember to keep schema in-sync with script
1059 id INTEGER NOT NULL PRIMARY KEY,
1060 file_id INTEGER NOT NULL, -- REFERENCES file(id), -- [cache]
1061 cpanid VARCHAR(20) NOT NULL, -- REFERENCES author(cpanid), -- [cache]
1062 name TEXT NOT NULL,
1063 content_id INT, -- REFERENCES content(id),
1064 abstract TEXT,
1065 rec_ctime INT,
1066 rec_mtime INT
1067 )',
1068 'CREATE UNIQUE INDEX ix_old_script__id ON old_script(id)',
1069 'CREATE UNIQUE INDEX ix_old_script__file_id__name ON old_script(file_id, name)',
1070 'CREATE INDEX ix_old_script__name ON old_script(name)',
1071 'CREATE INDEX ix_old_script__rec_ctime ON old_script(rec_ctime)',
1072 'CREATE INDEX ix_old_script__rec_mtime ON old_script(rec_mtime)',
1073  
1074 'CREATE TABLE mention (
1075 id INTEGER NOT NULL PRIMARY KEY,
1076 source_file_id INT NOT NULL REFERENCES file(id), -- [cache]
1077 source_content_id INT NOT NULL REFERENCES content(id),
1078 module_id INTEGER, -- if mention module and module is known (listed in module table), only its id will be recorded here
1079 module_name TEXT, -- if mention module and module is unknown (unlisted in module table), only the name will be recorded here
1080 script_name TEXT, -- if mention script
1081 rec_ctime INT,
1082 rec_mtime INT
1083 )',
1084 'CREATE UNIQUE INDEX ix_mention__id ON mention(id)', # not created automatically when there is another unique index?
1085 'CREATE UNIQUE INDEX ix_mention__module_id__source_content_id ON mention(module_id, source_content_id)',
1086 'CREATE UNIQUE INDEX ix_mention__module_name__source_content_id ON mention(module_name, source_content_id)',
1087 'CREATE UNIQUE INDEX ix_mention__script_name__source_content_id ON mention(script_name, source_content_id)',
1088 'CREATE INDEX ix_mention__rec_ctime ON mention(rec_ctime)',
1089 'CREATE INDEX ix_mention__rec_mtime ON mention(rec_mtime)',
1090  
1091 'CREATE TABLE namespace (
1092 name VARCHAR(255) NOT NULL,
1093 num_sep INT NOT NULL,
1094 has_child BOOL NOT NULL,
1095 num_modules INT NOT NULL,
1096 rec_ctime INT,
1097 rec_mtime INT
1098 )',
1099 'CREATE UNIQUE INDEX ix_namespace__name ON namespace(name)',
1100 'CREATE INDEX ix_namespace__rec_ctime ON namespace(rec_ctime)',
1101 'CREATE INDEX ix_namespace__rec_mtime ON namespace(rec_mtime)',
1102  
1103 'CREATE TABLE dep (
1104 file_id INTEGER,
1105 module_id INTEGER, -- if module is known (listed in module table), only its id will be recorded here
1106 module_name TEXT, -- if module is unknown (unlisted in module table), only the name will be recorded here
1107 rel TEXT, -- relationship: requires, ...
1108 phase TEXT, -- runtime, ...
1109 version VARCHAR(20),
1110 version_numified DECIMAL,
1111 rec_ctime INT,
1112 rec_mtime INT,
1113 FOREIGN KEY (file_id) REFERENCES file(id),
1114 FOREIGN KEY (module_id) REFERENCES module(id)
1115 )',
1116 'CREATE INDEX ix_dep__module_name ON dep(module_name)',
1117 'CREATE INDEX ix_dep__file_id ON dep(file_id)',
1118 'CREATE INDEX ix_dep__module_id ON dep(module_id)',
1119 'CREATE INDEX ix_dep__rec_ctime ON dep(rec_ctime)',
1120 'CREATE INDEX ix_dep__rec_mtime ON dep(rec_mtime)',
1121  
1122 'CREATE TABLE sub (
1123 id INTEGER NOT NULL PRIMARY KEY,
1124 file_id INTEGER NOT NULL REFERENCES file(id), --[cache]
1125 content_id INTEGER NOT NULL REFERENCES content(id),
1126 name TEXT NOT NULL,
1127 linum INTEGER NOT NULL,
1128 rec_ctime INT,
1129 rec_mtime INT
1130 )',
1131 'CREATE UNIQUE INDEX ix_sub__id ON sub(id)', # not created automatically when there is another unique index?
1132 'CREATE UNIQUE INDEX ix_sub__name__content_id ON sub(name, content_id)',
1133 'CREATE INDEX ix_sub__rec_ctime ON sub(rec_ctime)',
1134 'CREATE INDEX ix_sub__rec_mtime ON sub(rec_mtime)',
1135  
1136 'CREATE TABLE log (
1137 id INTEGER NOT NULL PRIMARY KEY,
1138 date INTEGER NOT NULL,
1139 lcpan_version TEXT,
1140 pid INTEGER NOT NULL,
1141 level INTEGER NOT NULL, -- like in Log::ger: fatal=10, error=20, warn=30, info=40, debug=50, trace=60
1142 category TEXT NOT NULL,
1143 summary TEXT NOT NULL
1144 )',
1145 'CREATE UNIQUE INDEX ix_log__id ON log(id)',
1146 'CREATE INDEX ix_log__date ON log(date)',
1147 'CREATE INDEX ix_log__category ON log(category)',
1148 ], # install
1149  
1150 upgrade_to_v2 => [
1151 # actually we don't have any schema changes in v2, but we want to
1152 # reindex release files that haven't been successfully indexed
1153 # because aside from META.{json,yml}, we now can get information
1154 # from Makefile.PL or Build.PL.
1155 qq|DELETE FROM dep WHERE dist_id IN (SELECT id FROM dist WHERE file_id IN (SELECT id FROM file WHERE status<>'ok'))|, # shouldn't exist though
1156 qq|DELETE FROM dist WHERE file_id IN (SELECT id FROM file WHERE status<>'ok')|,
1157 qq|DELETE FROM file WHERE status<>'ok'|,
1158 ],
1159  
1160 upgrade_to_v3 => [
1161 # empty data, we'll reindex because we'll need to set has_* and
1162 # discard all info
1163 'DELETE FROM dist',
1164 'DELETE FROM module',
1165 'DELETE FROM file',
1166 'ALTER TABLE file ADD COLUMN has_metajson INTEGER',
1167 'ALTER TABLE file ADD COLUMN has_metayml INTEGER',
1168 'ALTER TABLE file ADD COLUMN has_makefilepl INTEGER',
1169 'ALTER TABLE file ADD COLUMN has_buildpl INTEGER',
1170 'ALTER TABLE dist ADD COLUMN version_numified DECIMAL',
1171 'ALTER TABLE module ADD COLUMN version_numified DECIMAL',
1172 'ALTER TABLE dep ADD COLUMN version_numified DECIMAL',
1173 ],
1174  
1175 upgrade_to_v4 => [
1176 # there is some changes to data structure: 1) add column 'cpanid' to
1177 # module & dist (for improving performance of some queries); 2) we
1178 # record deps per-file, not per-dist so we can delete old files'
1179 # data more easily. we also empty data to force reindexing.
1180  
1181 'DELETE FROM dist',
1182 'DELETE FROM module',
1183 'DELETE FROM file',
1184  
1185 'ALTER TABLE module ADD COLUMN cpanid VARCHAR(20) NOT NULL DEFAULT \'\' REFERENCES author(cpanid)',
1186 'CREATE INDEX ix_module__cpanid ON module(cpanid)',
1187 'ALTER TABLE dist ADD COLUMN cpanid VARCHAR(20) NOT NULL DEFAULT \'\' REFERENCES author(cpanid)',
1188 'CREATE INDEX ix_dist__cpanid ON dist(cpanid)',
1189  
1190 'DROP TABLE dep',
1191 'CREATE TABLE dep (
1192 file_id INTEGER,
1193 dist_id INTEGER, -- [cache]
1194 module_id INTEGER, -- if module is known (listed in module table), only its id will be recorded here
1195 module_name TEXT, -- if module is unknown (unlisted in module table), only the name will be recorded here
1196 rel TEXT, -- relationship: requires, ...
1197 phase TEXT, -- runtime, ...
1198 version VARCHAR(20),
1199 version_numified DECIMAL,
1200 FOREIGN KEY (file_id) REFERENCES file(id),
1201 FOREIGN KEY (dist_id) REFERENCES dist(id),
1202 FOREIGN KEY (module_id) REFERENCES module(id)
1203 )',
1204 'CREATE INDEX ix_dep__module_name ON dep(module_name)',
1205 ],
1206  
1207 upgrade_to_v5 => [
1208 'ALTER TABLE dist ADD COLUMN is_latest BOOLEAN',
1209 ],
1210  
1211 upgrade_to_v6 => [
1212 'CREATE TABLE namespace (
1213 name VARCHAR(255) NOT NULL,
1214 num_sep INT NOT NULL,
1215 has_child BOOL NOT NULL,
1216 num_modules INT NOT NULL
1217 )',
1218 'CREATE UNIQUE INDEX ix_namespace__name ON namespace(name)',
1219 \&_fill_namespace,
1220 ],
1221  
1222 upgrade_to_v7 => [
1223 # actually PAUSE allows two authors to have the same filename. although
1224 # directory is still ignored, so a single author still cannot have
1225 # dir1/File-1.0.tar.gz and dir2/File-1.0.tar.gz.
1226 'DROP INDEX ix_file__name',
1227 'CREATE UNIQUE INDEX ix_file__cpanid__name ON file(cpanid,name)',
1228 ],
1229  
1230 upgrade_to_v8 => [
1231 # empty all data, we're now indexing the contents of each release
1232 # because we want to index more (scripts, module mentions in POD, etc)
1233 \&_reset,
1234  
1235 # we are deleting a column
1236 'DROP TABLE file',
1237 'CREATE TABLE file (
1238 id INTEGER NOT NULL PRIMARY KEY,
1239 name TEXT NOT NULL,
1240 cpanid VARCHAR(20) NOT NULL REFERENCES author(cpanid),
1241  
1242 mtime INT,
1243 size INT,
1244  
1245 -- file status: ok (archive type is known, content can be listed,
1246 -- and at least some files can be extracted), nofile (file does not
1247 -- exist in mirror), unsupported (archive type is not supported,
1248 -- e.g. rar, pm.gz)
1249  
1250 file_status TEXT,
1251 file_error TEXT,
1252  
1253 -- META.* processing status: ok (meta has been extracted and
1254 -- parsed), metaerr (META.json/META.yml has some error), nometa (no
1255 -- META.json/META.yml found).
1256  
1257 meta_status TEXT,
1258 meta_error TEXT,
1259  
1260 -- POD processing status: ok (POD has been extracted and
1261 -- parsed/indexed), NULL (has not been processed yet).
1262  
1263 pod_status TEXT,
1264  
1265 has_metajson INTEGER,
1266 has_metayml INTEGER,
1267 has_makefilepl INTEGER,
1268 has_buildpl INTEGER
1269 )',
1270  
1271 'CREATE TABLE content (
1272 id INTEGER NOT NULL PRIMARY KEY,
1273 file_id INTEGER NOT NULL REFERENCES file(id),
1274 path TEXT NOT NULL,
1275 package TEXT, -- only the first package declaration will be recorded
1276 mtime INT,
1277 size INT -- uncompressed size
1278 )',
1279 'CREATE UNIQUE INDEX ix_content__file_id__path ON content(file_id, path)',
1280  
1281 'ALTER TABLE module ADD COLUMN content_id INTEGER REFERENCES content(id)',
1282 'ALTER TABLE module ADD COLUMN abstract TEXT',
1283  
1284 'CREATE TABLE script (
1285 id INTEGER NOT NULL PRIMARY KEY,
1286 file_id INTEGER NOT NULL REFERENCES file(id), -- [cache]
1287 cpanid VARCHAR(20) NOT NULL REFERENCES author(cpanid), -- [cache]
1288 name TEXT NOT NULL,
1289 content_id INT REFERENCES content(id),
1290 abstract TEXT
1291 )',
1292 'CREATE UNIQUE INDEX ix_script__file_id__name ON script(file_id, name)',
1293 'CREATE INDEX ix_script__name ON script(name)',
1294  
1295 'CREATE TABLE mention (
1296 id INTEGER NOT NULL PRIMARY KEY,
1297 source_file_id INT NOT NULL REFERENCES file(id), -- [cache]
1298 source_content_id INT NOT NULL REFERENCES content(id),
1299 module_id INTEGER, -- if mention module and module is known (listed in module table), only its id will be recorded here
1300 module_name TEXT, -- if mention module and module is unknown (unlisted in module table), only the name will be recorded here
1301 script_name TEXT -- if mention script
1302 )',
1303 'CREATE UNIQUE INDEX ix_mention__module_id__source_content_id ON mention(module_id, source_content_id)',
1304 'CREATE UNIQUE INDEX ix_mention__module_name__source_content_id ON mention(module_name, source_content_id)',
1305 'CREATE UNIQUE INDEX ix_mention__script_name__source_content_id ON mention(script_name, source_content_id)',
1306 ],
1307  
1308 upgrade_to_v9 => [
1309 'CREATE INDEX ix_content__package ON content(package)',
1310 ],
1311  
1312 upgrade_to_v10 => [
1313 # there was a bug which excludes content with mode > 777 which excludes
1314 # some (many?) content, so we reindex content/mention/script
1315 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1316 0 my $dbh = shift;
1317 0 $dbh->do("UPDATE file SET file_status=NULL, file_error=NULL, pod_status=NULL");
1318 0 $dbh->do("DELETE FROM mention");
1319 0 $dbh->do("DELETE FROM script");
1320 0 $dbh->do("DELETE FROM content");
1321 },
1322  
1323 'ALTER TABLE file ADD COLUMN sub_status TEXT',
1324  
1325 # experimental
1326 'CREATE TABLE sub (
1327 id INTEGER NOT NULL PRIMARY KEY,
1328 file_id INTEGER NOT NULL REFERENCES file(id), --[cache]
1329 content_id INTEGER NOT NULL REFERENCES content(id),
1330 name TEXT NOT NULL,
1331 linum INTEGER NOT NULL
1332 )',
1333 'CREATE UNIQUE INDEX ix_sub__name__content_id ON sub(name, content_id)',
1334  
1335 ],
1336  
1337 upgrade_to_v11 => [
1338 # forgot to add indices because FOREIGN KEY does not automatically
1339 # create indexes
1340 'CREATE INDEX ix_dep__file_id ON dep(file_id)',
1341 'CREATE INDEX ix_dep__dist_id ON dep(dist_id)',
1342 'CREATE INDEX ix_dep__module_id ON dep(module_id)',
1343 ],
1344  
1345 upgrade_to_v12 => [
1346 'CREATE UNIQUE INDEX ix_file__id ON file(id)', # not created automatically when there is another unique index?
1347 'CREATE UNIQUE INDEX ix_content__id ON content(id)', # not created automatically when there is another unique index?
1348 'CREATE UNIQUE INDEX ix_module__id ON module(id)', # not created automatically when there is another unique index?
1349 'CREATE UNIQUE INDEX ix_script__id ON script(id)', # not created automatically when there is another unique index?
1350 'CREATE UNIQUE INDEX ix_mention__id ON mention(id)', # not created automatically when there is another unique index?
1351 'CREATE UNIQUE INDEX ix_dist__id ON dist(id)', # not created automatically when there is another unique index?
1352 'CREATE UNIQUE INDEX ix_sub__id ON sub(id)', # not created automatically when there is another unique index?
1353 ],
1354  
1355 upgrade_to_v13 => [
1356 # add rec_ctime & rec_mtime column to all tables, so user can query
1357 # recently added/modified authors, modules, ...
1358  
1359 'ALTER TABLE author ADD COLUMN rec_ctime INT',
1360 'ALTER TABLE author ADD COLUMN rec_mtime INT',
1361 'CREATE INDEX ix_author__rec_ctime ON author(rec_ctime)',
1362 'CREATE INDEX ix_author__rec_mtime ON author(rec_mtime)',
1363 "UPDATE author SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1364 "UPDATE author SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1365  
1366 'ALTER TABLE file ADD COLUMN rec_ctime INT',
1367 'ALTER TABLE file ADD COLUMN rec_mtime INT',
1368 'CREATE INDEX ix_file__rec_ctime ON file(rec_ctime)',
1369 'CREATE INDEX ix_file__rec_mtime ON file(rec_mtime)',
1370 "UPDATE file SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1371 "UPDATE file SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1372  
1373 'ALTER TABLE content ADD COLUMN rec_ctime INT',
1374 'ALTER TABLE content ADD COLUMN rec_mtime INT',
1375 'CREATE INDEX ix_content__rec_ctime ON content(rec_ctime)',
1376 'CREATE INDEX ix_content__rec_mtime ON content(rec_mtime)',
1377 "UPDATE content SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1378 "UPDATE content SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1379  
1380 'ALTER TABLE module ADD COLUMN rec_ctime INT',
1381 'ALTER TABLE module ADD COLUMN rec_mtime INT',
1382 'CREATE INDEX ix_module__rec_ctime ON module(rec_ctime)',
1383 'CREATE INDEX ix_module__rec_mtime ON module(rec_mtime)',
1384 "UPDATE module SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1385 "UPDATE module SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1386  
1387 'ALTER TABLE script ADD COLUMN rec_ctime INT',
1388 'ALTER TABLE script ADD COLUMN rec_mtime INT',
1389 'CREATE INDEX ix_script__rec_ctime ON script(rec_ctime)',
1390 'CREATE INDEX ix_script__rec_mtime ON script(rec_mtime)',
1391 "UPDATE script SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1392 "UPDATE script SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1393  
1394 'ALTER TABLE mention ADD COLUMN rec_ctime INT',
1395 'ALTER TABLE mention ADD COLUMN rec_mtime INT',
1396 'CREATE INDEX ix_mention__rec_ctime ON mention(rec_ctime)',
1397 'CREATE INDEX ix_mention__rec_mtime ON mention(rec_mtime)',
1398 "UPDATE mention SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1399 "UPDATE mention SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1400  
1401 'ALTER TABLE namespace ADD COLUMN rec_ctime INT',
1402 'ALTER TABLE namespace ADD COLUMN rec_mtime INT',
1403 'CREATE INDEX ix_namespace__rec_ctime ON namespace(rec_ctime)',
1404 'CREATE INDEX ix_namespace__rec_mtime ON namespace(rec_mtime)',
1405 "UPDATE namespace SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1406 "UPDATE namespace SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1407  
1408 'ALTER TABLE dist ADD COLUMN rec_ctime INT',
1409 'ALTER TABLE dist ADD COLUMN rec_mtime INT',
1410 'CREATE INDEX ix_dist__rec_ctime ON dist(rec_ctime)',
1411 'CREATE INDEX ix_dist__rec_mtime ON dist(rec_mtime)',
1412 "UPDATE dist SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1413 "UPDATE dist SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1414  
1415 'ALTER TABLE dep ADD COLUMN rec_ctime INT',
1416 'ALTER TABLE dep ADD COLUMN rec_mtime INT',
1417 'CREATE INDEX ix_dep__rec_ctime ON dep(rec_ctime)',
1418 'CREATE INDEX ix_dep__rec_mtime ON dep(rec_mtime)',
1419 "UPDATE dep SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1420 "UPDATE dep SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1421  
1422 'ALTER TABLE sub ADD COLUMN rec_ctime INT',
1423 'ALTER TABLE sub ADD COLUMN rec_mtime INT',
1424 'CREATE INDEX ix_sub__rec_ctime ON sub(rec_ctime)',
1425 'CREATE INDEX ix_sub__rec_mtime ON sub(rec_mtime)',
1426 "UPDATE sub SET rec_ctime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_ctime IS NULL",
1427 "UPDATE sub SET rec_mtime=(SELECT value FROM meta WHERE name='last_index_time') WHERE rec_mtime IS NULL",
1428 ],
1429  
1430 upgrade_to_v14 => [
1431 # add log table
1432 'CREATE TABLE log (
1433 id INTEGER NOT NULL PRIMARY KEY,
1434 date INTEGER NOT NULL,
1435 lcpan_version TEXT,
1436 pid INTEGER NOT NULL,
1437 level INTEGER NOT NULL, -- like in Log::ger: fatal=10, error=20, warn=30, info=40, debug=50, trace=60
1438 category TEXT NOT NULL,
1439 summary TEXT NOT NULL
1440 )',
1441 'CREATE UNIQUE INDEX ix_log__id ON log(id)',
1442 'CREATE INDEX ix_log__date ON log(date)',
1443 'CREATE INDEX ix_log__category ON log(category)',
1444 ],
1445  
1446 upgrade_to_v15 => [
1447 # we merge 'dist' into 'file' table to make things simpler, because
1448 # 'dist' has a 1:1 relationship with 'file'
1449 'ALTER TABLE file ADD COLUMN dist_name TEXT',
1450 'ALTER TABLE file ADD COLUMN dist_abstract TEXT',
1451 'ALTER TABLE file ADD COLUMN dist_version VARCHAR(20)',
1452 'ALTER TABLE file ADD COLUMN dist_version_numified VARCHAR(20)',
1453 'ALTER TABLE file ADD COLUMN is_latest_dist BOOLEAN',
1454 'CREATE INDEX ix_file__dist_name ON file(dist_name)',
1455  
1456 'DROP TABLE dist',
1457  
1458 # recreate table dep to remove the dist_id column
1459 'DROP TABLE dep',
1460 'CREATE TABLE dep (
1461 file_id INTEGER,
1462 module_id INTEGER, -- if module is known (listed in module table), only its id will be recorded here
1463 module_name TEXT, -- if module is unknown (unlisted in module table), only the name will be recorded here
1464 rel TEXT, -- relationship: requires, ...
1465 phase TEXT, -- runtime, ...
1466 version VARCHAR(20),
1467 version_numified DECIMAL,
1468 rec_ctime INT,
1469 rec_mtime INT,
1470 FOREIGN KEY (file_id) REFERENCES file(id),
1471 FOREIGN KEY (module_id) REFERENCES module(id)
1472 )',
1473  
1474 # since there were misplaced placeholders when setting rec_mtime (fixed
1475 # in 3be9ae8), we will need to redo file indexing.
1476 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1477 0 my $dbh = shift;
1478 0 log_info("Will be reindexing for all files due to bug in lcpan <= 1.056");
1479 0 _reset($dbh, 'soft');
1480 },
1481 98 ],
1482  
1483 upgrade_to_v16 => [
1484 # add table old_file
1485 'CREATE TABLE old_file ( -- remember to keep schema in-sync with file
1486 id INTEGER NOT NULL PRIMARY KEY,
1487 name TEXT NOT NULL,
1488 cpanid VARCHAR(20) NOT NULL, -- REFERENCES author(cpanid),
1489  
1490 mtime INT,
1491 size INT,
1492  
1493 file_status TEXT,
1494 file_error TEXT,
1495  
1496 meta_status TEXT,
1497 meta_error TEXT,
1498  
1499 dist_name TEXT,
1500 dist_abstract TEXT,
1501 dist_version VARCHAR(20),
1502 dist_version_numified VARCHAR(20),
1503 is_latest_dist BOOLEAN,
1504  
1505 pod_status TEXT,
1506  
1507 sub_status TEXT,
1508  
1509 has_metajson INTEGER,
1510 has_metayml INTEGER,
1511 has_makefilepl INTEGER,
1512 has_buildpl INTEGER,
1513  
1514 rec_ctime INT,
1515 rec_mtime INT
1516 )',
1517 'CREATE UNIQUE INDEX ix_old_file__id ON old_file(id)',
1518 'CREATE UNIQUE INDEX ix_old_file__cpanid__name ON old_file(cpanid,name)',
1519 'CREATE INDEX ix_old_file__rec_ctime ON old_file(rec_ctime)',
1520 'CREATE INDEX ix_old_file__rec_mtime ON old_file(rec_mtime)',
1521 'CREATE INDEX ix_old_file__dist_name ON old_file(dist_name)',
1522  
1523 # add table old_module
1524 'CREATE TABLE old_module ( -- remember to keep schema in-sync with module
1525 id INTEGER NOT NULL PRIMARY KEY,
1526 name VARCHAR(255) NOT NULL,
1527 cpanid VARCHAR(20) NOT NULL, -- REFERENCES author(cpanid), -- [cache]
1528 file_id INTEGER NOT NULL,
1529 version VARCHAR(20),
1530 version_numified DECIMAL,
1531 content_id INTEGER, -- REFERENCES content(id),
1532 abstract TEXT,
1533 rec_ctime INT,
1534 rec_mtime INT
1535 )',
1536 'CREATE INDEX ix_old_module__id ON old_module(id)',
1537 'CREATE INDEX ix_old_module__name ON old_module(name)',
1538 'CREATE INDEX ix_old_module__file_id ON old_module(file_id)',
1539 'CREATE INDEX ix_old_module__cpanid ON old_module(cpanid)',
1540 'CREATE INDEX ix_old_module__rec_ctime ON old_module(rec_ctime)',
1541 'CREATE INDEX ix_old_module__rec_mtime ON old_module(rec_mtime)',
1542  
1543 # add table old_script
1544 'CREATE TABLE old_script ( -- remember to keep schema in-sync with script
1545 id INTEGER NOT NULL PRIMARY KEY,
1546 file_id INTEGER NOT NULL, -- REFERENCES file(id), -- [cache]
1547 cpanid VARCHAR(20) NOT NULL, -- REFERENCES author(cpanid), -- [cache]
1548 name TEXT NOT NULL,
1549 content_id INT, -- REFERENCES content(id),
1550 abstract TEXT,
1551 rec_ctime INT,
1552 rec_mtime INT
1553 )',
1554 'CREATE UNIQUE INDEX ix_old_script__id ON old_script(id)',
1555 'CREATE UNIQUE INDEX ix_old_script__file_id__name ON old_script(file_id, name)',
1556 'CREATE INDEX ix_old_script__name ON old_script(name)',
1557 'CREATE INDEX ix_old_script__rec_ctime ON old_script(rec_ctime)',
1558 'CREATE INDEX ix_old_script__rec_mtime ON old_script(rec_mtime)',
1559 ],
1560  
1561 # for testing
1562 install_v1 => [
1563 'CREATE TABLE author (
1564 cpanid VARCHAR(20) NOT NULL PRIMARY KEY,
1565 fullname VARCHAR(255) NOT NULL,
1566 email TEXT
1567 )',
1568  
1569 'CREATE TABLE file (
1570 id INTEGER NOT NULL PRIMARY KEY,
1571 name TEXT NOT NULL,
1572 cpanid VARCHAR(20) NOT NULL REFERENCES author(cpanid),
1573  
1574 -- processing status: ok (meta has been extracted and parsed),
1575 -- nometa (file does contain cpan meta), nofile (file does not
1576 -- exist in mirror), unsupported (file type is not supported,
1577 -- e.g. rar, non archive), metaerr (meta has some error), err
1578 -- (other error).
1579 status TEXT
1580 )',
1581 'CREATE UNIQUE INDEX ix_file__name ON file(name)',
1582  
1583 'CREATE TABLE module (
1584 id INTEGER NOT NULL PRIMARY KEY,
1585 name VARCHAR(255) NOT NULL,
1586 file_id INTEGER NOT NULL,
1587 version VARCHAR(20)
1588 )',
1589 'CREATE UNIQUE INDEX ix_module__name ON module(name)',
1590 'CREATE INDEX ix_module__file_id ON module(file_id)',
1591  
1592 # this is inserted
1593 'CREATE TABLE dist (
1594 id INTEGER NOT NULL PRIMARY KEY,
1595 name VARCHAR(90) NOT NULL,
1596 abstract TEXT,
1597 file_id INTEGER NOT NULL,
1598 version VARCHAR(20)
1599 )',
1600 'CREATE INDEX ix_dist__name ON dist(name)',
1601 'CREATE UNIQUE INDEX ix_dist__file_id ON dist(file_id)',
1602  
1603 'CREATE TABLE dep (
1604 dist_id INTEGER,
1605 module_id INTEGER, -- if module is known (listed in module table), only its id will be recorded here
1606 module_name TEXT, -- if module is unknown (unlisted in module table), only the name will be recorded here
1607 rel TEXT, -- relationship: requires, ...
1608 phase TEXT, -- runtime, ...
1609 version TEXT,
1610 FOREIGN KEY (dist_id) REFERENCES dist(id),
1611 FOREIGN KEY (module_id) REFERENCES module(id)
1612 )',
1613 'CREATE INDEX ix_dep__module_name ON dep(module_name)',
1614 'CREATE UNIQUE INDEX ix_dep__dist_id__module_id ON dep(dist_id,module_id)',
1615 ],
1616 }; # spec
1617  
1618 0 ▶sub _create_schema {
Subroutine _create_schema: not called CC=2 SCAR=17.9
1619 0 require SQL::Schema::Versioned;
1620  
1621 0 my $dbh = shift;
1622  
1623 0 my $res = SQL::Schema::Versioned::create_or_update_db_schema(
1624 dbh => $dbh, spec => $db_schema_spec);
1625 0 ▶ die "Can't create/update schema: $res->[0] - $res->[1]\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
1626 unless $res->[0] == 200;
1627 }
1628  
1629 0 ▶sub _db_path {
Subroutine _db_path: not called CC=2 SCAR=17.9
1630 0 my ($cpan, $index_name) = @_;
1631 0 ▶ $index_name =~ m!/|\\! ? $index_name : "$cpan/$index_name";
Branch: 1 branch
BranchTrueFalseTotal
$index_name =~ m[/|\\] ? : 0 0 0
1632 }
1633  
1634 0 ▶sub _use_db_bootstrap {
Subroutine _use_db_bootstrap: not called CC=4 SCAR=30.0
1635 0 require File::ShareDir;
1636 0 require File::Which;
1637 0 require IPC::System::Options;
1638  
1639 0 my $db_path = shift;
1640 0 ▶ return if -f $db_path;
Branch: 1 branch
BranchTrueFalseTotal
if -f $db_path 0 0 0
1641  
1642 0 my $dist_dir;
1643 0 eval { $dist_dir = File::ShareDir::dist_dir("App-lcpan-Bootstrap") };
1644 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1645 0 log_warn "Could not find bootstrap database, consider installing ".
1646 "App::lcpan::Bootstrap for faster index creation";
1647 0 return;
1648 }
1649 0 ▶ unless (File::Which::which("xz")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (File::Which::which("xz")) 0 0 0
1650 0 log_warn "Could not use bootstrap database, the 'xz' utility ".
1651 "is not available to decompress the bootstrap";
1652 0 return;
1653 }
1654 0 log_info "Decompressing bootstrap database ...";
1655 0 IPC::System::Options::system(
1656 {shell=>1, die=>1, log=>1},
1657 "xz", "-cd", "$dist_dir/db/index.db.xz", \">", $db_path,
1658 );
1659 }
1660  
1661 0 ▶sub _connect_db {
Subroutine _connect_db: not called CC=5 SCAR=34.0
1662 0 require DBI;
1663  
1664 0 my ($mode, $cpan, $index_name, $use_bootstrap, $update_db_schema) = @_;
1665  
1666 0 my $db_path = _db_path($cpan, $index_name);
1667 0 ▶ _use_db_bootstrap($db_path) if $use_bootstrap;
Branch: 1 branch
BranchTrueFalseTotal
if $use_bootstrap 0 0 0
1668 0 log_trace("Connecting to SQLite database at %s ...", $db_path);
1669 0 ▶ if ($mode eq 'ro') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "ro") 0 0 0
1670 # avoid creating the index file automatically if we are only in
1671 # read-only mode
1672 0 ▶ die "Can't find index '$db_path'\n" unless -f $db_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $db_path 0 0 0
1673 }
1674 0 my $dbh = DBI->connect("dbi:SQLite:dbname=$db_path", undef, undef,
1675 {RaiseError=>1});
1676 0 $dbh->do("PRAGMA cache_size = 400000"); # 400M
1677 0 ▶ _create_schema($dbh) if $update_db_schema;
Branch: 1 branch
BranchTrueFalseTotal
if $update_db_schema 0 0 0
1678 0 $dbh;
1679 }
1680  
1681 # all subcommands (except special ones like 'update') call this first. lcpan can
1682 # be used in daemon mode or CLI, and this routine handles both case. in daemon
1683 # mode, we set $App::lcpan::state (containing database handle, etc) and reuse
1684 # it. in CLI, there is no reuse between invocation.
1685 0 ▶sub _init {
Subroutine _init: not called CC=2 SCAR=17.9
1686 0 my ($args, $mode) = @_;
1687  
1688 0 ▶ unless ($App::lcpan::state) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($App::lcpan::state) 0 0 0
1689 0 _set_args_default($args);
1690 my $state = {
1691 dbh => _connect_db($mode, $args->{cpan}, $args->{index_name}, $args->{use_bootstrap}, $args->{update_db_schema}),
1692 cpan => $args->{cpan},
1693 index_name => $args->{index_name},
1694 0 };
1695 0 $App::lcpan::state = $state;
1696 }
1697 0 $App::lcpan::state;
1698 }
1699  
1700 # return "" if success, or error string
1701 0 ▶sub _check_meta {
Subroutine _check_meta: not called CC=3 SCAR=24.8
1702 0 my $meta = shift;
1703  
1704 0 ▶ unless (ref($meta) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $meta eq "HASH") 0 0 0
1705 0 return "not a hash";
1706 }
1707 0 ▶ unless (defined $meta->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"name"}) 0 0 0
1708 0 return "does not contain name";
1709 }
1710 0 "";
1711 }
1712  
1713 0 ▶sub _parse_meta_json {
Subroutine _parse_meta_json: not called CC=3 SCAR=24.8
1714 0 require Parse::CPAN::Meta;
1715  
1716 0 my $content = shift;
1717  
1718 0 my $data;
1719 0 eval {
1720 0 $data = Parse::CPAN::Meta->load_json_string($content);
1721 };
1722 0 ▶ return ($@, undef) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1723 0 my $metaerr = _check_meta($data);
1724 0 ▶ return ($metaerr, undef) if $metaerr;
Branch: 1 branch
BranchTrueFalseTotal
if $metaerr 0 0 0
1725 0 return ("", $data);
1726 }
1727  
1728 0 ▶sub _parse_meta_yml {
Subroutine _parse_meta_yml: not called CC=3 SCAR=24.8
1729 0 require Parse::CPAN::Meta;
1730  
1731 0 my $content = shift;
1732  
1733 0 my $data;
1734 0 eval {
1735 0 $data = Parse::CPAN::Meta->load_yaml_string($content);
1736 };
1737 0 ▶ return ($@, undef) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1738 0 my $metaerr = _check_meta($data);
1739 0 ▶ return ($metaerr, undef) if $metaerr;
Branch: 1 branch
BranchTrueFalseTotal
if $metaerr 0 0 0
1740 0 return ("", $data);
1741 }
1742  
1743 0 ▶sub _add_prereqs {
Subroutine _add_prereqs: not called CC=3 SCAR=24.8
1744 0 my ($file_id, $hash, $phase, $rel, $sth_ins_dep, $sth_sel_mod) = @_;
1745 0 log_trace(" Adding prereqs (%s %s): %s", $phase, $rel, $hash);
1746 0 my $now = time();
1747 0 for my $mod (keys %$hash) {
1748 0 $sth_sel_mod->execute($mod);
1749 0 my $row = $sth_sel_mod->fetchrow_hashref;
1750 0 my ($mod_id, $mod_name);
1751 0 ▶ if ($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) { } 0 0 0
1752 0 $mod_id = $row->{id};
1753 } else {
1754 0 $mod_name = $mod;
1755 }
1756 0 my $ver = $hash->{$mod};
1757 0 $sth_ins_dep->execute($file_id, $mod_id, $mod_name, $phase,
1758 $rel, $ver, _numify_ver($ver),
1759 $now, $now);
1760 }
1761 }
1762  
1763 0 ▶sub _index_pod {
Subroutine _index_pod: not called CC=10 SCAR=47.0
1764 0 my ($file_id, $file_name, $script_name,
1765 $content_id, $content_path,
1766 $ct,
1767 $type,
1768  
1769 $sth_sel_mod,
1770 $sth_sel_script,
1771 $sth_set_module_abstract,
1772 $sth_set_script_abstract,
1773 $sth_set_content_package,
1774  
1775 $module_ids,
1776 $module_file_ids,
1777 $script_file_ids,
1778 $scripts_re,
1779 $sth_ins_mention,
1780 ) = @_;
1781  
1782 0 log_trace(" Indexing POD of %s", $content_path);
1783  
1784 0 my $abstract;
1785 0 ▶ if ($ct =~ /^=head1 \s+ NAME\s*\R
Branch: 1 branch
BranchTrueFalseTotal
if ($ct =~ /^=head1 \s+ NAME\s*\R \s*\R \S+ \s+ - \s+ ([^\r\n]+) /mx) 0 0 0
1786 \s*\R
1787 \S+ \s+ - \s+ ([^\r\n]+)
1788 /mx) {
1789 0 $abstract = $1;
1790 }
1791  
1792 0 my $pkg;
1793 0 my ($module_id, $script_id);
1794 0 ▶ if ($ct =~ /^\s*package [ \t]+ ([A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z0-9_]+)*)\b
Branch: 1 branch
BranchTrueFalseTotal
if ($ct =~ /^\s*package [ \t]+ ([A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z0-9_]+)*)\b /mx) 0 0 0
1795 /mx) {
1796 0 $pkg = $1;
1797 0 log_trace(" found package declaration '%s'", $pkg);
1798 0 $sth_set_content_package->execute($pkg, time(), $content_id);
1799  
1800 0 ▶ if ($type eq 'pm_or_pod') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "pm_or_pod") 0 0 0
1801 # set module abstract if pkg refers to a known module
1802 0 $sth_sel_mod->execute($pkg);
1803 0 my $row = $sth_sel_mod->fetchrow_hashref;
1804 0 $sth_sel_mod->finish;
1805 0 ▶ if ($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) 0 0 0
1806 0 $module_id = $row->{id};
1807 0 ▶ if ($abstract) {
Branch: 1 branch
BranchTrueFalseTotal
if ($abstract) 0 0 0
1808 0 log_trace(" set abstract for module %s: %s", $pkg, $abstract);
1809 0 $sth_set_module_abstract->execute($abstract, time(), $module_id);
1810 }
1811 }
1812 }
1813 }
1814  
1815 0 ▶ if (defined $script_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $script_name) 0 0 0
1816 0 $sth_sel_script->execute($script_name, $file_id);
1817 0 my $row = $sth_sel_script->fetchrow_hashref;
1818 0 $sth_sel_script->finish;
1819 0 ▶ if (!$row) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($row) 0 0 0
1820 # shouldn't happen
1821 0 log_warn("BUG: Unknown script %s in %s (%s), skipped",
1822 $script_name, $content_path, $file_name);
1823 0 return;
1824 }
1825 0 $script_id = $row->{id};
1826 # set script abstract
1827 0 ▶ if ($abstract) {
Branch: 1 branch
BranchTrueFalseTotal
if ($abstract) 0 0 0
1828 0 log_trace(" set abstract for script %s (%s): %s", $script_name, $file_name, $abstract);
1829 0 $sth_set_script_abstract->execute($abstract, time(), $script_id);
1830 }
1831 }
1832  
1833 # list pod mentions
1834 {
1835 # turns out we cannot reuse Pod::Simple object? we must recreate the
1836 # instance for every parse.
1837  
1838 0 require App::lcpan::PodParser;
1839 0 my $pod_parser = App::lcpan::PodParser->new;
1840 0 $pod_parser->{file_id} = $file_id;
1841 0 $pod_parser->{content_id} = $content_id;
1842 0 $pod_parser->{module_ids} = $module_ids;
1843 0 $pod_parser->{module_file_ids} = $module_file_ids;
1844 0 $pod_parser->{script_file_ids} = $script_file_ids;
1845 0 $pod_parser->{scripts_re} = $scripts_re;
1846 0 $pod_parser->{sth_ins_mention} = $sth_ins_mention;
1847  
1848 0 eval {
1849 0 $pod_parser->parse_string_document($ct);
1850 };
1851 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1852 0 log_error("Can't parse POD for file '%s', skipped", $content_path);
1853 }
1854 }
1855 }
1856  
1857 0 ▶sub _index_sub {
Subroutine _index_sub: not called CC=7 SCAR=40.3
1858 0 my ($file_id,
1859 $content_id, $content_path,
1860 $ct,
1861  
1862 $sth_ins_sub,
1863 ) = @_;
1864  
1865 0 log_trace(" Indexing subs in %s", $content_path);
1866  
1867 0 require Compiler::Lexer;
1868 0 my $lexer = Compiler::Lexer->new;
1869 0 my $tokens = $lexer->tokenize($ct);
1870 0 for my $i (0..@$tokens-1) {
1871 0 my $t = $tokens->[$i];
1872 0 my $sub;
1873 0 ▶ if ($i < @$tokens-1 && $t->{name} eq 'FunctionDecl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$tokens - 1 and $t->{"name"} eq "FunctionDecl") 0 0 0
Condition0%0/3
$i < @$tokens - 1 and $t->{"name"} eq "FunctionDecl"
!ll&&!rl&&r
000
MC/DC0%0/2
$i < @$tokens - 1 and $t->{"name"} eq "FunctionDecl"
$i < @$tokens - 1 $t->{"name"} eq "FunctionDecl"
Truth table0%0/3
A and B
A= $i < @$tokens - 1B= $t->{"name"} eq "FunctionDecl"
ABresult
0X0
100
111
1874 0 my $t2 = $tokens->[$i+1];
1875 0 ▶ if ($t2->{name} eq 'Function') {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2->{"name"} eq "Function") 0 0 0
1876 0 $sub = $t2->{data};
1877 }
1878 }
1879 0 ▶ next unless $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub 0 0 0
1880 0 ▶ next if $sub =~ /\A_/;
Branch: 1 branch
BranchTrueFalseTotal
if $sub =~ /\A_/ 0 0 0
1881 0 log_trace(" found sub declaration '%s' (line %s)", $sub, $t->{line});
1882 0 my $now = time();
1883 0 $sth_ins_sub->execute($sub, $t->{line}, $file_id, $content_id, $now,$now);
1884 }
1885 }
1886  
1887 0 ▶sub _update_files {
Subroutine _update_files: not called CC=11 SCAR=48.8
1888 0 require IPC::System::Options;
1889 0 require JSON::PP;
1890  
1891 0 my %args = @_;
1892 0 _set_args_default(\%args);
1893 0 my $cpan = $args{cpan};
1894 0 my $index_name = $args{index_name};
1895  
1896 0 ▶ my $remote_url = $args{remote_url} // "http://mirrors.kernel.org/cpan";
Condition0%0/2
$args{"remote_url"} // "http://mirrors.kernel.org/cpan"
l!l
00
MC/DC0%0/1
$args{"remote_url"} // "http://mirrors.kernel.org/cpan"
$args{"remote_url"}
Truth table0%0/2
A
A= $args{"remote_url"}
Aresult
11
00
1897 0 my $max_file_size = $args{max_file_size};
1898  
1899 0 my %plugin_args;
1900 0 ▶ if ($args{max_file_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"max_file_size"}) 0 0 0
1901 0 $plugin_args{FilterLcpan}{max_size} = $args{max_file_size};
1902 }
1903 0 ▶ if ($args{include_author} && @{ $args{include_author} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"include_author"} and @{$args{"include_author"};}) 0 0 0
Condition0%0/3
$args{"include_author"} and @{$args{"include_author"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"include_author"} and @{$args{"include_author"};}
$args{"include_author"} @{$args{"include_author"};}
Truth table0%0/3
A and B
A= $args{"include_author"}B= @{$args{"include_author"};}
ABresult
0X0
100
111
1904 0 $plugin_args{FilterLcpan}{include_author} = $args{include_author};
1905 }
1906 0 ▶ if ($args{exclude_author} && @{ $args{exclude_author} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"exclude_author"} and @{$args{"exclude_author"};}) 0 0 0
Condition0%0/3
$args{"exclude_author"} and @{$args{"exclude_author"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"exclude_author"} and @{$args{"exclude_author"};}
$args{"exclude_author"} @{$args{"exclude_author"};}
Truth table0%0/3
A and B
A= $args{"exclude_author"}B= @{$args{"exclude_author"};}
ABresult
0X0
100
111
1907 0 $plugin_args{FilterLcpan}{exclude_author} = $args{exclude_author};
1908 }
1909 0 ▶ $plugin_args{FilterLcpan}{verbose} = 1 if log_is_info();
Branch: 1 branch
BranchTrueFalseTotal
if log_is_info() 0 0 0
1910 0 ▶ if (defined $args{retry_max_attempts}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"retry_max_attempts"}) 0 0 0
1911 0 $plugin_args{Retry}{max_attempts} = $args{retry_max_attempts};
1912 }
1913 0 ▶ if (defined $args{retry_delay}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"retry_delay"}) 0 0 0
1914 0 $plugin_args{Retry}{delay} = $args{retry_delay};
1915 }
1916  
1917 0 ▶ my @cmd = (
Branch: 1 branch
BranchTrueFalseTotal
log_is_warn() ? : 0 0 0
1918 "minicpan",
1919 (log_is_warn() ? () : ("-q")),
1920 "-l", $cpan,
1921 "-r", $remote_url,
1922 );
1923 0 my $env = {};
1924 0 $env->{LWP_USERAGENT_PLUGINS} = JSON::PP::encode_json([%plugin_args]);
1925 0 $env->{PERL5OPT} = "-MLWP::Protocol::Patch::CountBytesIn -MEnd::PrintBytesIn -MLWP::UserAgent::Patch::Plugin";
1926  
1927 0 IPC::System::Options::system(
1928 {die=>1, log=>1, env=>$env},
1929 @cmd,
1930 );
1931  
1932 0 my $dbh = _connect_db('rw', $cpan, $index_name, $args{use_bootstrap}, $args{update_db_schema});
1933 0 $dbh->do("INSERT OR REPLACE INTO meta (name,value) VALUES (?,?)",
1934 {}, 'last_mirror_time', time());
1935  
1936 0 [200];
1937 }
1938  
1939 0 ▶sub _delete_releases_records {
Subroutine _delete_releases_records: not called CC=4 SCAR=30.0
1940 0 my ($dbh, @file_ids) = @_;
1941  
1942 0 log_trace(" Deleting dep records");
1943 0 $dbh->do("DELETE FROM dep WHERE file_id IN (".join(",",@file_ids).")");
1944  
1945 {
1946 0 my $sth = $dbh->prepare("SELECT name FROM module WHERE file_id IN (".join(",",@file_ids).")");
1947 0 $sth->execute;
1948 0 my @mods;
1949 0 ▶ while (my ($mod) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($mod) = $sth->fetchrow_array) 0 0 0
1950 0 push @mods, $mod;
1951 }
1952  
1953 0 my $sth_upd_ns_dec_num_mod = $dbh->prepare("UPDATE namespace SET num_modules=num_modules-1 WHERE name=?");
1954 0 for my $mod (@mods) {
1955 0 while (1) {
1956 0 $sth_upd_ns_dec_num_mod->execute($mod);
1957 0 ▶ $mod =~ s/::\w+\z// or last;
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ s/::\w+\z// or last 0 0 0
1958 }
1959 }
1960 0 $dbh->do("DELETE FROM namespace WHERE num_modules <= 0");
1961  
1962 #log_trace(" Copying module records to old_module");
1963 #$dbh->do("INSERT INTO old_module SELECT * FROM module WHERE file_id IN (".join(",",@file_ids).")");
1964  
1965 0 log_trace(" Deleting module records");
1966 0 $dbh->do("DELETE FROM module WHERE file_id IN (".join(",",@file_ids).")");
1967 }
1968  
1969 0 log_trace(" Deleting mention records");
1970 0 $dbh->do("DELETE FROM mention WHERE source_file_id IN (".join(",",@file_ids).")");
1971  
1972 #log_trace(" Copying script records to old_script");
1973 #$dbh->do("INSERT INTO old_script SELECT * FROM script WHERE file_id IN (".join(",",@file_ids).")");
1974  
1975 0 log_trace(" Deleting script records");
1976 0 $dbh->do("DELETE FROM script WHERE file_id IN (".join(",",@file_ids).")");
1977  
1978 0 log_trace(" Deleting sub records");
1979 0 $dbh->do("DELETE FROM sub WHERE file_id IN (".join(",",@file_ids).")");
1980  
1981 0 log_trace(" Deleting content records");
1982 0 $dbh->do("DELETE FROM content WHERE file_id IN (".join(",",@file_ids).")");
1983  
1984 #log_trace(" Copying file records to old_file");
1985 #$dbh->do("INSERT INTO old_file SELECT * FROM file WHERE id IN (".join(",",@file_ids).")");
1986  
1987 0 log_trace(" Deleting file records");
1988 0 $dbh->do("DELETE FROM file WHERE id IN (".join(",",@file_ids).")");
1989 }
1990  
1991 98 my $re_metajson = qr!^[/\\]?(?:[^/\\]+[/\\])?META\.json$!;
1992 98 my $re_metayml = qr!^[/\\]?(?:[^/\\]+[/\\])?META\.yml$!;
1993  
1994 0 ▶sub _sort_prefer_metajson_over_metayml {
Subroutine _sort_prefer_metajson_over_metayml: not called CC=5 SCAR=34.0
1995 0 my @members = @_;
1996  
1997 # make sure we prefer META.json (SPEC 2.0) over .yml (SPEC 1.4)
1998 sort {
1999 0 ▶ my $a_filename = $a->{full_path} // $a->fileName;
Condition0%0/3
$App::lcpan::a->{"full_path"} // $a->fileName
l!l&&r!l&&!r
000
MC/DC0%0/2
$App::lcpan::a->{"full_path"} // $a->fileName
$App::lcpan::a->{"full_path"} $a->fileName
Truth table0%0/3
A // B
A= $App::lcpan::a->{"full_path"}B= $a->fileName
ABresult
1X1
011
000
2000 0 ▶ my $b_filename = $b->{full_path} // $b->fileName;
Condition0%0/3
$App::lcpan::b->{"full_path"} // $b->fileName
l!l&&r!l&&!r
000
MC/DC0%0/2
$App::lcpan::b->{"full_path"} // $b->fileName
$App::lcpan::b->{"full_path"} $b->fileName
Truth table0%0/3
A // B
A= $App::lcpan::b->{"full_path"}B= $b->fileName
ABresult
1X1
011
000
2001 0 my $a_is_metajson = $a_filename =~ $re_metajson;
2002 0 my $b_is_metajson = $b_filename =~ $re_metajson;
2003 0 my $a_is_metayml = $a_filename =~ $re_metayml;
2004 0 my $b_is_metayml = $b_filename =~ $re_metayml;
2005  
2006 0 ▶ ($a_is_metajson && $b_is_metayml) ? -1 :
Branch: 1 branch
BranchTrueFalseTotal
$a_is_metajson && $b_is_metayml ? : 0 0 0
Condition0%0/3
$a_is_metajson and $b_is_metayml
!ll&&!rl&&r
000
MC/DC0%0/2
$a_is_metajson and $b_is_metayml
$a_is_metajson $b_is_metayml
Truth table0%0/3
A and B
A= $a_is_metajsonB= $b_is_metayml
ABresult
0X0
100
111
2007 ($a_filename cmp $b_filename);
2008 } @members;
2009 }
2010  
2011 0 ▶sub _list_archive_members {
Subroutine _list_archive_members: not called CC=5 SCAR=34.0
2012 0 my ($path, $filename, $fileid) = @_;
2013  
2014 0 my ($zip, $tar);
2015 0 my @members;
2016 0 ▶ if ($path =~ /\.zip$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\.zip$/i) { } 0 0 0
2017 0 require Archive::Zip;
2018 0 $zip = Archive::Zip->new;
2019 $zip->read($path) == Archive::Zip::AZ_OK()
2020 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$zip->read($path) == Archive::Zip::AZ_OK() or do { log_error("Can't read zip file '%s', skipped", $filename); return [500, "can't read zip '${filename}', skipped", undef, {"func.file_id", $fileid}] } 0 0 0
2021 0 log_error("Can't read zip file '%s', skipped", $filename);
2022 0 return [500, "can't read zip '$filename', skipped", undef, {'func.file_id'=>$fileid}];
2023 };
2024 #log_trace(" listing zip members ...");
2025 0 @members = $zip->members;
2026 #log_trace(" members: %s", \@members);
2027 } else {
2028 0 require Archive::Tar;
2029 0 eval {
2030 0 $tar = Archive::Tar->new;
2031 0 $tar->read($path); # can still die untrapped when out of mem
2032 0 ▶ die $tar->error if $tar->error;
Branch: 1 branch
BranchTrueFalseTotal
if $tar->error 0 0 0
2033 #log_trace(" listing tar members ...");
2034 0 @members = $tar->list_files(["full_path","mode","mtime","size"]);
2035 #log_trace(" members: %s", \@members);
2036 };
2037 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2038 0 log_error("Can't read tar file '%s', skipped", $filename);
2039 0 return [500, "$@", undef, {'func.file_id'=>$fileid}];
2040 }
2041 }
2042 0 [200, "OK", \@members, {'func.zip' => $zip, 'func.tar' => $tar}];
2043 }
2044  
2045 0 ▶sub _get_meta {
Subroutine _get_meta: not called CC=14 SCAR=53.5
2046 0 my ($la_res) = @_;
2047 0 my @members = _sort_prefer_metajson_over_metayml(@{$la_res->[2]});
2048  
2049 0 my $zip = $la_res->[3]{'func.zip'};
2050 0 my $tar = $la_res->[3]{'func.tar'};
2051 0 my $meta;
2052  
2053 0 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) { } 0 0 0
2054 0 for my $member (@members) {
2055 0 ▶ if ($member->fileName =~ m!(?:/|\\)?(META\.yml|META\.json)$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member->fileName =~ m[(?:/|\\)?(META\.yml|META\.json)$]) 0 0 0
2056 0 log_trace(" found META: %s", $member->fileName);
2057 0 my $type = $1;
2058 #log_trace("content=[[%s]]", $content);
2059 0 my $content = $zip->contents($member);
2060 0 ▶ if ($type eq 'META.yml') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'META.yml') { } 0 0 0
elsif ($type eq 'META.json') { } 0 0 0
2061 0 (my $metaerr, $meta) = _parse_meta_yml($content);
2062 0 ▶ return [500, $metaerr] if $metaerr;
Branch: 1 branch
BranchTrueFalseTotal
if $metaerr 0 0 0
2063 } elsif ($type eq 'META.json') {
2064 0 (my $metaerr, $meta) = _parse_meta_json($content);
2065 0 ▶ return [500, $metaerr] if $metaerr;
Branch: 1 branch
BranchTrueFalseTotal
if $metaerr 0 0 0
2066 }
2067 0 last;
2068 }
2069 }
2070 } else {
2071 0 for my $member (@members) {
2072 0 ▶ if ($member->{full_path} =~ m!/?(META\.yml|META\.json)$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member->{"full_path"} =~ m[/?(META\.yml|META\.json)$]) 0 0 0
2073 0 log_trace(" found META %s", $member->{full_path});
2074 0 my $type = $1;
2075 0 my ($obj) = $tar->get_files($member->{full_path});
2076 0 my $content = $obj->get_content;
2077 0 ▶ if ($type eq 'META.yml') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'META.yml') { } 0 0 0
elsif ($type eq 'META.json') { } 0 0 0
2078 0 (my $metaerr, $meta) = _parse_meta_yml($content);
2079 0 ▶ return [500, $metaerr] if $metaerr;
Branch: 1 branch
BranchTrueFalseTotal
if $metaerr 0 0 0
2080 } elsif ($type eq 'META.json') {
2081 0 (my $metaerr, $meta) = _parse_meta_json($content);
2082 0 ▶ return [500, $metaerr] if $metaerr;
Branch: 1 branch
BranchTrueFalseTotal
if $metaerr 0 0 0
2083 }
2084 0 last;
2085 }
2086 }
2087 }
2088 0 [200, "OK", $meta];
2089 }
2090  
2091 0 ▶sub _update_index {
Subroutine _update_index: not called CC=119 SCAR=95.4
2092 0 require DBI;
2093 0 require File::Temp;
2094 0 require IO::Compress::Gzip;
2095  
2096 0 my %args = @_;
2097 0 _set_args_default(\%args);
2098 0 my $cpan = $args{cpan};
2099 0 my $index_name = $args{index_name};
2100  
2101 0 my $db_path = _db_path($cpan, $index_name);
2102 0 ▶ if ($args{num_backups} > 0 && (-f $db_path)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"num_backups"} > 0 and -f $db_path) 0 0 0
Condition0%0/3
$args{"num_backups"} > 0 and -f $db_path
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"num_backups"} > 0 and -f $db_path
$args{"num_backups"} > 0 -f $db_path
Truth table0%0/3
A and B
A= $args{"num_backups"} > 0B= -f $db_path
ABresult
0X0
100
111
2103 0 require File::Copy;
2104 0 require Logfile::Rotate;
2105 0 log_info("Rotating old indexes ...");
2106 my $rotate = Logfile::Rotate->new(
2107 File => $db_path,
2108 Count => $args{num_backups},
2109 0 Gzip => 'no',
2110 );
2111 0 $rotate->rotate;
2112 0 ▶ File::Copy::copy("$db_path.1", $db_path)
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy("$db_path.1", $db_path) or return [500, "Copy $db_path.1 -> $db_path failed: $!"] 0 0 0
2113 or return [500, "Copy $db_path.1 -> $db_path failed: $!"];
2114 }
2115  
2116 0 my $dbh = _connect_db('rw', $cpan, $index_name, $args{use_bootstrap}, $args{update_db_schema});
2117  
2118 # check whether we need to reindex if a sufficiently old (and possibly
2119 # incorrect) version of us did the reindexing
2120 {
2121 0 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.2
2122 0 my $our_version = ${__PACKAGE__.'::VERSION'};
2123  
2124 0 my ($indexer_version) = $dbh->selectrow_array("SELECT value FROM meta WHERE name='indexer_version'");
2125 0 ▶ last unless $indexer_version;
Branch: 1 branch
BranchTrueFalseTotal
unless $indexer_version 0 0 0
2126 0 ▶ if ($our_version && version->parse($indexer_version) > version->parse($our_version)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($our_version and "version"->parse($indexer_version) > "version"->parse($our_version)) 0 0 0
Condition0%0/3
$our_version and "version"->parse($indexer_version) > "version"->parse($our_version)
!ll&&!rl&&r
000
MC/DC0%0/2
$our_version and "version"->parse($indexer_version) > "version"->parse($our_version)
$our_version "version"->parse($indexer_version) > "version"->parse($our_version)
Truth table0%0/3
A and B
A= $our_versionB= "version"->parse($indexer_version) > "version"->parse($our_version)
ABresult
0X0
100
111
2127 0 return [412, "Database is indexed by version ($indexer_version) newer than current software's version ($our_version), bailing out"];
2128 }
2129 0 ▶ if (version->parse($indexer_version) <= version->parse("0.35")) {
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse($indexer_version) <= "version"->parse("0.35")) 0 0 0
2130 0 log_info("Reindexing from scratch, deleting previous index content ...");
2131 0 _reset($dbh);
2132 }
2133 }
2134  
2135 0 _dblog($dbh, 40, "update_index", "Begin updating index");
2136  
2137 # parse 01mailrc.txt.gz and insert the parse result to 'author' table
2138 PARSE_MAILRC:
2139 {
2140 0 require DBIx::UpdateTable::FromHoH;
2141  
2142 0 my $path = "$cpan/authors/01mailrc.txt.gz";
2143 0 log_info("Parsing %s ...", $path);
2144 0 ▶ open my($fh), "<:gzip", $path or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:gzip", $path or do { log_info("%s does not exist, skipped", $path); last PARSE_MAILRC } 0 0 0
2145 0 log_info("%s does not exist, skipped", $path);
2146 0 last PARSE_MAILRC;
2147 };
2148  
2149 0 my $hoh = {};
2150 0 my $line = 0;
2151 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
2152 0 $line++;
2153 0 ▶ my ($cpanid, $fullname, $email) = /^alias (\S+)\s+"(.*) <(.+)>"/ or do {
Branch: 1 branch
BranchTrueFalseTotal
() = /^alias (\S+)\s+"(.*) <(.+)>"/ or do { log_warn(" line %d: syntax error, skipped: %s", $line, $_); next } 0 0 0
2154 0 log_warn(" line %d: syntax error, skipped: %s", $line, $_);
2155 0 next;
2156 };
2157 0 $hoh->{$cpanid} = {fullname=>$fullname, email=>$email};
2158 }
2159 0 my $now = time();
2160 0 my $res = DBIx::UpdateTable::FromHoH::update_table_from_hoh(
2161 dbh => $dbh,
2162 table => 'author',
2163 hoh => $hoh,
2164 key_column => 'cpanid',
2165 data_columns => [qw/fullname email/],
2166 extra_insert_columns => {rec_ctime=>$now, rec_mtime=>$now},
2167 extra_update_columns => {rec_mtime=>$now},
2168 );
2169 0 ▶ if ($res->[0] == 200) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->[0] == 200) { } 0 0 0
elsif ($res->[0] == 304) { } 0 0 0
2170 0 log_info("Updated author table: %s", $res);
2171 } elsif ($res->[0] == 304) {
2172 0 log_trace("author table unchanged: %s", $res);
2173 } else {
2174 0 log_error("Can't update author table: %s", $res);
2175 }
2176 }
2177  
2178 # some darkpans (e.g. produced by OrePAN) has authors/00whois.xml instead
2179 PARSE_WHOIS:
2180 {
2181 0 my $path = "$cpan/authors/00whois.xml";
2182 0 log_info("Parsing %s ...", $path);
2183 0 ▶ open my($fh), "<", $path or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or do { log_info("%s does not exist, skipped", $path); last PARSE_WHOIS } 0 0 0
2184 0 log_info("%s does not exist, skipped", $path);
2185 0 last PARSE_WHOIS;
2186 };
2187  
2188 # currently we don't bother to use a real xml parser and just use regex
2189 # instead
2190 0 my $content = do { local $/; ~~<$fh> };
2191  
2192 # i would like to use INSERT OR IGNORE, but rows affected returned by
2193 # execute() is always 1?
2194  
2195 0 my $hoh = {};
2196 0 ▶ while ($content =~ m!<id>(\w+)</id>!g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[<id>(\w+)</id>]g) 0 0 0
2197 0 my ($cpanid) = ($1);
2198 0 $hoh->{$cpanid} = {fullname=>$cpanid, email=>undef};
2199 }
2200 0 my $now = time();
2201 0 my $res = DBIx::UpdateTable::FromHoH::update_table_from_hoh(
2202 dbh => $dbh,
2203 table => 'author',
2204 hoh => $hoh,
2205 key_column => 'cpanid',
2206 data_columns => [qw/fullname email/],
2207 extra_insert_columns => {rec_ctime=>$now, rec_mtime=>$now},
2208 extra_update_columns => {rec_mtime=>$now},
2209 );
2210 0 ▶ if ($res->[0] == 200) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->[0] == 200) { } 0 0 0
elsif ($res->[0] == 304) { } 0 0 0
2211 0 log_info("Updated author table: %s", $res);
2212 } elsif ($res->[0] == 304) {
2213 0 log_trace("author table unchanged: %s", $res);
2214 } else {
2215 0 log_error("Can't update author table: %s", $res);
2216 }
2217 }
2218  
2219 # parse 02packages.details.txt.gz and insert the parse result to 'file' and
2220 # 'module' tables. we haven't parsed distribution names yet because that
2221 # will need information from META.{json,yaml} inside release files.
2222 PARSE_PACKAGES:
2223 {
2224 0 my $path = "$cpan/modules/02packages.details.txt.gz";
2225 0 log_info("Parsing %s ...", $path);
2226 0 ▶ open my($fh), "<:gzip", $path or die "Can't open $path (<:gzip): $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:gzip", $path or die "Can't open $path (<:gzip): $!" 0 0 0
2227  
2228 0 my $sth_sel_file = $dbh->prepare("SELECT id FROM file WHERE name=? AND cpanid=?");
2229 0 my $sth_ins_file = $dbh->prepare("INSERT INTO file (name,cpanid,mtime,size, rec_ctime,rec_mtime) VALUES (?,?,?,?, ?,?)");
2230 0 my $sth_ins_mod = $dbh->prepare("INSERT INTO module (name,file_id,cpanid,version,version_numified, rec_ctime,rec_mtime) VALUES (?,?,?,?,?, ?,?)");
2231 0 my $sth_upd_mod = $dbh->prepare("UPDATE module SET file_id=?,cpanid=?,version=?,version_numified=?, rec_mtime=? WHERE name=?"); # sqlite currently does not have upsert
2232  
2233 0 $dbh->begin_work;
2234  
2235 0 my %file_ids_in_table; # key="cpanid|filename"
2236 0 my $sth = $dbh->prepare("SELECT cpanid,name,id FROM file");
2237 0 $sth->execute;
2238 0 ▶ while (my ($cpanid, $name, $id) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
2239 0 $file_ids_in_table{"$cpanid|$name"} = $id;
2240 }
2241  
2242 0 my %file_ids_in_02packages; # key="cpanid|filename", val=id (or undef if already exists in db)
2243 0 my $line = 0;
2244 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
2245 0 $line++;
2246 0 ▶ next unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
2247 0 ▶ next if /^\S+:\s/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\S+:\s/ 0 0 0
2248 0 chomp;
2249 0 my ($pkg, $ver, $path) = split /\s+/, $_;
2250 0 ▶ $ver = undef if $ver eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $ver eq "undef" 0 0 0
2251 0 ▶ my ($author, $file) = $path =~ m!^./../(.+?)/(.+)! or do {
Branch: 1 branch
BranchTrueFalseTotal
() = $path =~ m[^./../(.+?)/(.+)] or do { log_warn(" line %d: Invalid path %s, skipped", $line, $path); next } 0 0 0
2252 0 log_warn(" line %d: Invalid path %s, skipped", $line, $path);
2253 0 next;
2254 };
2255 0 my $file_id;
2256 0 ▶ if (exists $file_ids_in_02packages{"$author|$file"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $file_ids_in_02packages{"$author|$file"}) { } 0 0 0
2257 0 $file_id = $file_ids_in_02packages{"$author|$file"};
2258 } else {
2259 0 $sth_sel_file->execute($file, $author);
2260 0 my $path = _fullpath($file, $cpan, $author);
2261 0 my @stat = stat $path;
2262 0 ▶ unless ($sth_sel_file->fetchrow_arrayref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth_sel_file->fetchrow_arrayref) 0 0 0
2263 0 my $now = time();
2264 0 ▶ $sth_ins_file->execute(
Branch: 2 branches
BranchTrueFalseTotal
@stat ? : 0 0 0
@stat ? : 0 0 0
2265 $file, $author, @stat ? $stat[9] : undef, @stat ? $stat[7] : undef,
2266 $now, $now);
2267 0 $file_id = $dbh->last_insert_id("","","","");
2268 0 log_trace(" New file: %s (author %s)", $file, $author);
2269 }
2270 0 $file_ids_in_02packages{"$author|$file"} = $file_id;
2271 }
2272 0 ▶ next unless $file_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $file_id 0 0 0
2273  
2274 0 my $mod_id;
2275 0 ▶ if (($mod_id) = $dbh->selectrow_array("SELECT id FROM module WHERE name=?", {}, $pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (($mod_id) = $dbh->selectrow_array('SELECT id FROM module WHERE name=?', {}, $pkg)) { } 0 0 0
2276 0 $sth_upd_mod->execute( $file_id, $author, $ver, _numify_ver($ver), time(), $pkg);
2277 } else {
2278 0 my $now = time();
2279 0 $sth_ins_mod->execute($pkg, $file_id, $author, $ver, _numify_ver($ver), $now,$now);
2280 0 $mod_id = $dbh->last_insert_id("","","","");
2281 0 _set_namespace($dbh, $pkg);
2282 }
2283  
2284 0 log_trace(" New/updated module: %s (file ID=%d, module ID=%d)", $pkg, $file_id, $mod_id);
2285 } # while <fh>
2286  
2287 # cleanup: delete file record (as well as dists, modules, and deps
2288 # records) for files in db that are no longer in 02packages.
2289 CLEANUP:
2290 {
2291 0 my @old_file_ids;
2292 my @old_file_entries; # ("author|filename", ...)
2293 0 for my $k (sort keys %file_ids_in_table) {
2294 0 ▶ next if exists $file_ids_in_02packages{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $file_ids_in_02packages{$k} 0 0 0
2295 0 push @old_file_ids, $file_ids_in_table{$k};
2296 0 push @old_file_entries, $k;
2297 }
2298 0 ▶ last CLEANUP unless @old_file_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @old_file_ids 0 0 0
2299  
2300 0 _delete_releases_records($dbh, @old_file_ids);
2301 0 log_trace(" Deleted file records (%d): %s", ~~@old_file_entries, \@old_file_entries);
2302 }
2303  
2304 0 $dbh->commit;
2305 }
2306  
2307 0 my @passes;
2308 0 ▶ if ($args{skip_file_indexing_pass_1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'skip_file_indexing_pass_1'}) { } 0 0 0
2309 0 log_info("Will be skipping file indexing pass 1");
2310 } else {
2311 0 push @passes, 1;
2312 }
2313 0 ▶ if ($args{skip_file_indexing_pass_2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'skip_file_indexing_pass_2'}) { } 0 0 0
2314 0 log_info("Will be skipping file indexing pass 2");
2315 } else {
2316 0 push @passes, 2;
2317 }
2318 0 ▶ if ($args{skip_file_indexing_pass_3} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'skip_file_indexing_pass_3'} or $args{'skip_sub_indexing'} // 1) { } 0 0 0
Condition0%0/5
$args{"skip_file_indexing_pass_3"} or $args{"skip_sub_indexing"} // 1
l!l&&r!l&&!r
000
$args{"skip_sub_indexing"} // 1
l!l
00
MC/DC0%0/2
$args{"skip_file_indexing_pass_3"} or $args{"skip_sub_indexing"} // 1
$args{"skip_file_indexing_pass_3"} $args{"skip_sub_indexing"}
Truth table0%0/3
A or B
A= $args{"skip_file_indexing_pass_3"}B= $args{"skip_sub_indexing"}
ABresult
1X1
011
000
2319 ($args{skip_sub_indexing} // 1)) {
2320 0 log_info("Will be skipping file indexing pass 3");
2321 } else {
2322 0 push @passes, 3;
2323 }
2324  
2325 PROCESS_FILES_PASS:
2326 0 for my $pass (@passes) {
2327 # we're processing files in several passes.
2328  
2329 # the first pass: insert content, scripts, extract meta, insert dep
2330 # information, set file_status and meta_status.
2331  
2332 # the second pass: extract PODs and insert module/script abstracts and
2333 # pod mentions.
2334  
2335 # the third pass: subroutine indexing
2336  
2337 # we're doing it in several passes because: in pass 2, we want to
2338 # collect all known scripts first to be able to detect links to scripts
2339 # in POD (collected in pass 1). also some passes are more high-level
2340 # and/or experimental and/or optional.
2341  
2342 0 ▶ my $sth = $dbh->prepare(
Branch: 2 branches
BranchTrueFalseTotal
$pass == 1 ? : 0 0 0
$pass == 2 ? : 0 0 0
2343 $pass == 1 ?
2344 "SELECT * FROM file WHERE file_status IS NULL OR meta_status IS NULL ORDER BY name" :
2345  
2346 $pass == 2 ?
2347 "SELECT * FROM file WHERE pod_status IS NULL AND file_status NOT IN ('nofile','unsupported','err') ORDER BY name" :
2348  
2349 "SELECT * FROM file WHERE sub_status IS NULL AND file_status NOT IN ('nofile','unsupported','err') ".
2350 "AND EXISTS(SELECT id FROM content WHERE file_id=file.id AND package IS NOT NULL) ORDER BY name"
2351 );
2352 0 $sth->execute;
2353  
2354 0 my @files;
2355 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
2356 0 push @files, $row;
2357 }
2358  
2359 0 my $sth_set_file_status = $dbh->prepare("UPDATE file SET file_status=?,file_error=?, rec_mtime=? WHERE id=?");
2360 0 my $sth_ins_content = $dbh->prepare("INSERT OR REPLACE INTO content (file_id,path,mtime,size, rec_ctime,rec_mtime) VALUES (?,?,?,?, ?,?)");
2361 0 my $sth_ins_script = $dbh->prepare("INSERT OR REPLACE INTO script (name, cpanid, content_id, file_id, rec_ctime,rec_mtime) VALUES (?,?,?,?, ?,?)");
2362  
2363 0 my $sth_set_meta_status = $dbh->prepare("UPDATE file SET meta_status=?,meta_error=?, rec_mtime=? WHERE id=?");
2364 0 my $sth_set_meta_info = $dbh->prepare("UPDATE file SET has_metajson=?,has_metayml=?,has_makefilepl=?,has_buildpl=?, rec_mtime=? WHERE id=?");
2365 0 my $sth_set_dist_info = $dbh->prepare("UPDATE file SET dist_name=?,dist_abstract=?,dist_version=?,dist_version_numified=?, rec_mtime=? WHERE id=?");
2366 0 my $sth_ins_dep = $dbh->prepare("INSERT OR REPLACE INTO dep (file_id,module_id,module_name,phase,rel, version,version_numified, rec_ctime,rec_mtime) VALUES (?,?,?,?,?, ?,?, ?,?)");
2367  
2368 0 my $sth_sel_mod = $dbh->prepare("SELECT * FROM module WHERE name=?");
2369 0 my $sth_sel_script = $dbh->prepare("SELECT * FROM script WHERE name=? AND file_id=?");
2370  
2371 # for pass 2
2372 0 my $sth_set_pod_status = $dbh->prepare("UPDATE file SET pod_status=?, rec_mtime=? WHERE id=?");
2373 0 my $sth_sel_content = $dbh->prepare("SELECT * FROM content WHERE file_id=?");
2374 0 my $sth_set_module_abstract = $dbh->prepare("UPDATE module SET abstract=?, rec_mtime=? WHERE id=?");
2375 0 my $sth_set_script_abstract = $dbh->prepare("UPDATE script SET abstract=?, rec_mtime=? WHERE id=?");
2376 0 my $sth_ins_mention = $dbh->prepare("INSERT OR IGNORE INTO mention (source_content_id,source_file_id,module_id,module_name,script_name, rec_ctime,rec_mtime) VALUES (?,?,?,?,?, ?,?)");
2377 0 my $sth_set_content_package = $dbh->prepare("UPDATE content SET package=?, rec_mtime=? WHERE id=?");
2378  
2379 # for pass 3
2380 0 my $sth_sel_content__has_package = $dbh->prepare("SELECT * FROM content WHERE file_id=? AND package IS NOT NULL");
2381 0 my $sth_ins_sub = $dbh->prepare("INSERT OR IGNORE INTO sub (name, linum, file_id, content_id, rec_ctime,rec_mtime) VALUES (?,?,?,?, ?,?)");
2382 0 my $sth_set_sub_status = $dbh->prepare("UPDATE file SET sub_status=?, rec_mtime=? WHERE id=?");
2383  
2384 0 my $module_ids; # hash, key=module name, value=module id
2385 my $module_file_ids; # hash, key=module name, value=file id
2386 0 my $script_file_ids; # hash, key=script name, value=[file id, ...]
2387 0 my $scripts_re;
2388 0 ▶ if ($pass == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 2) 0 0 0
2389 # prepare the names of all scripts & modules, for quick reference
2390 0 $module_ids = {};
2391 0 $module_file_ids = {};
2392 0 $script_file_ids = {};
2393 0 my $sth = $dbh->prepare("SELECT id,file_id,name FROM module");
2394 0 $sth->execute;
2395 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
2396 0 $module_ids->{$row->{name}} = $row->{id};
2397 0 $module_file_ids->{$row->{name}} = $row->{file_id};
2398 }
2399  
2400 0 my %script_names;
2401 0 $sth = $dbh->prepare("SELECT name,file_id FROM script");
2402 0 $sth->execute;
2403 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
2404 0 $script_names{ $row->{name} }++;
2405 0 ▶ $script_file_ids->{$row->{name}} //= [];
Condition0%0/2
$$script_file_ids{$row->{"name"}} //= []
l!l
00
MC/DC0%0/1
$$script_file_ids{$row->{"name"}} //= []
$$script_file_ids{$row->{"name"}}
Truth table0%0/2
A
A= $$script_file_ids{$row->{"name"}}
Aresult
11
00
2406 0 push @{ $script_file_ids->{$row->{name}} }, $row->{file_id};
2407 }
2408 0 ▶ my @script_names = sort {length($b) <=> length($a) || $a cmp $b}
Condition0%0/3
length $b <=> length $a || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a $a cmp $b
Truth table0%0/3
A || B
A= length $b <=> length $aB= $a cmp $b
ABresult
1X1
011
000
2409 keys %script_names;
2410 0 $scripts_re = "\\A(?:" . join("|", map {quotemeta} @script_names) . ")\\z";
2411 0 $scripts_re = qr/$scripts_re/;
2412 #log_trace("TMP: script_re = %s", $scripts_re);
2413 #log_trace("TMP: scripts_names = %s", \%script_names);
2414 }
2415  
2416 0 my $i = 0;
2417 0 my $after_begin;
2418  
2419 FILE:
2420 0 for my $file (@files) {
2421  
2422 # commit after every 500 files
2423 0 ▶ if ($i % 500 == 499) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 500 == 499) 0 0 0
2424 0 log_trace("COMMIT");
2425 0 $dbh->commit;
2426 0 $dbh->begin_work;
2427 }
2428 0 ▶ if ($i % 500 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 500 == 0) 0 0 0
2429 0 ▶ unless ($after_begin) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($after_begin) 0 0 0
2430 0 log_trace("BEGIN");
2431 0 $dbh->begin_work;
2432 0 $after_begin = 1;
2433 }
2434 }
2435 0 $i++;
2436  
2437 0 ▶ if (my $reason = $builtin_file_skip_list{ $file->{name} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reason = $builtin_file_skip_list{$file->{"name"}}) 0 0 0
2438 0 log_info("Skipped file %s (reason: built-in file skip list: %s)", $file->{name}, $reason);
2439 0 next FILE;
2440 }
2441  
2442 0 ▶ if ($args{skip_index_files} && first {$_ eq $file->{name}} @{ $args{skip_index_files} }) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"skip_index_files"} and &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_index_files"};})) 0 0 0
Condition0%0/3
$args{"skip_index_files"} and &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_index_files"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"skip_index_files"} and &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_index_files"};})
$args{"skip_index_files"} &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_index_files"};})
Truth table0%0/3
A and B
A= $args{"skip_index_files"}B= &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_index_files"};})
ABresult
0X0
100
111
2443 0 log_info("Skipped file %s (reason: skip_index_files)", $file->{name});
2444 0 next FILE;
2445 }
2446  
2447 0 ▶ if ($args{skip_index_file_patterns} && first {$file->{name} =~ $_} @{ $args{skip_index_file_patterns} }) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"skip_index_file_patterns"} and &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_index_file_patterns"};})) 0 0 0
Condition0%0/3
$args{"skip_index_file_patterns"} and &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_index_file_patterns"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"skip_index_file_patterns"} and &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_index_file_patterns"};})
$args{"skip_index_file_patterns"} &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_index_file_patterns"};})
Truth table0%0/3
A and B
A= $args{"skip_index_file_patterns"}B= &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_index_file_patterns"};})
ABresult
0X0
100
111
2448 0 log_info("Skipped file %s (reason: skip_index_file_patterns)", $file->{name});
2449 0 next FILE;
2450 }
2451  
2452 0 my $path = _fullpath($file->{name}, $cpan, $file->{cpanid});
2453  
2454 0 log_info("[pass %d/3][#%i/%d] Processing file %s ...",
2455 $pass, $i, ~~@files, $path);
2456  
2457 0 ▶ if (!$file->{file_status}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file->{"file_status"}) 0 0 0
2458 0 ▶ unless (-f $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $path) 0 0 0
2459 0 log_error("File %s doesn't exist, skipped", $path);
2460 0 $sth_set_file_status->execute("nofile", undef, time(), $file->{id});
2461 0 $sth_set_meta_status->execute("nometa", undef, time(), $file->{id});
2462 0 next FILE;
2463 }
2464 0 ▶ if ($path !~ /(.+)\.(tar|tar\.gz|tar\.bz2|tar\.Z|tgz|tbz2?|zip)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ /(.+)\.(tar|tar\.gz|tar\.bz2|tar\.Z|tgz|tbz2?|zip)$/i) 0 0 0
2465 0 log_error("Doesn't support file type: %s, skipped", $file->{name});
2466 0 $sth_set_file_status->execute("unsupported", undef, time(), $file->{id});
2467 0 $sth_set_meta_status->execute("nometa", undef, time(), $file->{id});
2468 0 next FILE;
2469 }
2470 }
2471  
2472 0 ▶ next FILE if $file->{file_status} && $file->{file_status} =~ /\A(unsupported)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"file_status"} and $file->{"file_status"} =~ /\A(unsupported)\z/ 0 0 0
Condition0%0/3
$file->{"file_status"} and $file->{"file_status"} =~ /\A(unsupported)\z/
!ll&&!rl&&r
000
MC/DC0%0/2
$file->{"file_status"} and $file->{"file_status"} =~ /\A(unsupported)\z/
$file->{"file_status"} $file->{"file_status"} =~ /\A(unsupported)\z/
Truth table0%0/3
A and B
A= $file->{"file_status"}B= $file->{"file_status"} =~ /\A(unsupported)\z/
ABresult
0X0
100
111
2473  
2474 0 my $la_res = _list_archive_members($path, $file->{name}, $file->{id});
2475 0 ▶ unless ($la_res->[0] == 200) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($la_res->[0] == 200) 0 0 0
2476 0 $sth_set_file_status->execute("err", $la_res->[1], time(), $la_res->[3]{'func.file_id'});
2477 0 $sth_set_meta_status->execute("err", "file err", time(), $la_res->[3]{'func.file_id'});
2478 0 next FILE;
2479 }
2480 0 my @members = @{ $la_res->[2] };
2481 0 my $zip = $la_res->[3]{'func.zip'};
2482 0 my $tar = $la_res->[3]{'func.tar'};
2483  
2484 0 ▶ my $code_is_script = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
2485 0 my $name = shift;
2486 0 ▶ unless ($name =~ m!\A
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ m[\A (?:\./)? (?:[^/]+/)? (?:s?bin|scripts?)/ ([^/]+) \z]x) 0 0 0
2487 (?:\./)?
2488 (?:[^/]+/)?
2489 (?:s?bin|scripts?)/
2490 ([^/]+)
2491 \z!x) {
2492 0 return (undef);
2493 }
2494 0 my $script_name = $1;
2495 0 ▶ if ($script_name =~ /\A\./ # e.g. "bin/.exists"
Branch: 1 branch
BranchTrueFalseTotal
if ($script_name =~ /\A\./ or $script_name =~ /\A(?:README(?:\.\w+)?)\z/) 0 0 0
Condition0%0/3
$script_name =~ /\A\./ or $script_name =~ /\A(?:README(?:\.\w+)?)\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
$script_name =~ /\A\./ or $script_name =~ /\A(?:README(?:\.\w+)?)\z/
$script_name =~ /\A\./ $script_name =~ /\A(?:README(?:\.\w+)?)\z/
Truth table0%0/3
A or B
A= $script_name =~ /\A\./B= $script_name =~ /\A(?:README(?:\.\w+)?)\z/
ABresult
1X1
011
000
2496 || $script_name =~ /\A(?:README(?:\.\w+)?)\z/) { # probably not a script
2497 0 return (undef);
2498 }
2499 0 return ($script_name);
2500 0 };
2501  
2502 0 ▶ my $code_is_pm_or_pod = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
2503 0 my $name = shift;
2504 # flat, *.pm in top-level
2505 0 ▶ if ($name =~ m!\A
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ m[\A (?:\./)? (?:[^/]+/)? # enclosing dir [^/]+\.(?:pm|pod)? \z ]xi) 0 0 0
2506 (?:\./)?
2507 (?:[^/]+/)? # enclosing dir
2508 [^/]+\.(?:pm|pod)?
2509 \z
2510 !ix) {
2511 0 return 1;
2512 }
2513 # *.pm under lib
2514 0 ▶ if ($name =~ m!\A
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ m[\A (?:\./)? (?:[^/]+/)? # enclosing dir lib/ (?:[^/]+/)* [^/]+\.(?:pm|pod)? \z ]xi) 0 0 0
2515 (?:\./)?
2516 (?:[^/]+/)? # enclosing dir
2517 lib/
2518 (?:[^/]+/)*
2519 [^/]+\.(?:pm|pod)?
2520 \z
2521 !ix) {
2522 0 return 1;
2523 }
2524 0 return 0;
2525 0 };
2526  
2527 0 ▶ if (!$file->{file_status}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file->{"file_status"}) 0 0 0
2528 # list contents & scripts and insert into database
2529 0 my %script_names;
2530 0 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) { } 0 0 0
2531 0 for my $member (@members) {
2532 # skip directory/symlinks
2533 0 ▶ next if $member->{isSymbolicLink} || $member->{fileName} =~ m!/\z!;
Branch: 1 branch
BranchTrueFalseTotal
if $member->{"isSymbolicLink"} or $member->{"fileName"} =~ m[/\z] 0 0 0
Condition0%0/3
$member->{"isSymbolicLink"} or $member->{"fileName"} =~ m[/\z]
l!l&&r!l&&!r
000
MC/DC0%0/2
$member->{"isSymbolicLink"} or $member->{"fileName"} =~ m[/\z]
$member->{"isSymbolicLink"} $member->{"fileName"} =~ m[/\z]
Truth table0%0/3
A or B
A= $member->{"isSymbolicLink"}B= $member->{"fileName"} =~ m[/\z]
ABresult
1X1
011
000
2534 0 my $now = time();
2535 $sth_ins_content->execute(
2536 $file->{id}, $member->{fileName}, $member->{lastModFileDateTime}, $member->{uncompressedSize},
2537 0 $now,$now);
2538 0 my $content_id = $dbh->last_insert_id("","","","");
2539 0 my ($script_name) = $code_is_script->($member->{fileName});
2540 0 ▶ if (defined $script_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $script_name) 0 0 0
2541 0 ▶ unless ($script_names{$script_name}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($script_names{$script_name}++) 0 0 0
2542 0 my $now = time();
2543 $sth_ins_script->execute($script_name, $file->{cpanid}, $content_id, $file->{id},
2544 0 $now,$now);
2545 }
2546 }
2547 }
2548 } else {
2549 0 my %mem; # tar allows duplicate path?
2550 0 for my $member (@members) {
2551 0 ▶ next if $member->{full_path} =~ m!/\z!;
Branch: 1 branch
BranchTrueFalseTotal
if $member->{"full_path"} =~ m[/\z] 0 0 0
2552 0 ▶ next if !$member->{size};
Branch: 1 branch
BranchTrueFalseTotal
unless $member->{"size"} 0 0 0
2553 0 ▶ next if $mem{$member->{full_path}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $mem{$member->{"full_path"}}++ 0 0 0
2554 0 my $now = time();
2555 $sth_ins_content->execute(
2556 $file->{id}, $member->{full_path}, $member->{mtime}, $member->{size},
2557 0 $now,$now);
2558 0 my $content_id = $dbh->last_insert_id("","","","");
2559 0 my ($script_name) = $code_is_script->($member->{full_path});
2560 0 ▶ if (defined $script_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $script_name) 0 0 0
2561 0 ▶ unless ($script_names{$script_name}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($script_names{$script_name}++) 0 0 0
2562 0 my $now = time();
2563 $sth_ins_script->execute($script_name, $file->{cpanid}, $content_id, $file->{id},
2564 0 $now,$now);
2565 }
2566 }
2567 }
2568 }
2569 0 $sth_set_file_status->execute("ok", undef, time(), $file->{id});
2570 0 $file->{file_status} = 'ok';
2571 }
2572  
2573 0 ▶ next FILE if $file->{file_status} ne 'ok';
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"file_status"} ne "ok" 0 0 0
2574  
2575 0 my $meta;
2576 GET_META:
2577 {
2578 0 ▶ last if $file->{meta_status};
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"meta_status"} 0 0 0
2579 0 my ($has_metajson, $has_metayml, $has_makefilepl, $has_buildpl);
2580 0 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) { } 0 0 0
2581 0 ▶ $has_metajson = (first { $_ =~ $re_metajson } @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_ =~ /$re_metajson/; } , @members) ? : 0 0 0
2582 0 ▶ $has_metayml = (first { $_ =~ $re_metayml } @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_ =~ /$re_metayml/; } , @members) ? : 0 0 0
2583 0 ▶ $has_makefilepl = (first {m!^[/\\]?(?:[^/\\]+[/\\])?Makefile\.PL$!} @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { m(^[/\\]?(?:[^/\\]+[/\\])?Makefile\.PL$); } , @members) ? : 0 0 0
2584 0 ▶ $has_buildpl = (first {m!^[/\\]?(?:[^/\\]+[/\\])?Build\.PL$!} @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { m(^[/\\]?(?:[^/\\]+[/\\])?Build\.PL$); } , @members) ? : 0 0 0
2585 } else {
2586 0 ▶ $has_metajson = (first { $_->{full_path} =~ $re_metajson } @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_->{'full_path'} =~ /$re_metajson/; } , @members) ? : 0 0 0
2587 0 ▶ $has_metayml = (first { $_->{full_path} =~ $re_metayml } @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_->{'full_path'} =~ /$re_metayml/; } , @members) ? : 0 0 0
2588 0 ▶ $has_makefilepl = (first {$_->{full_path} =~ m!/([^/]+)?Makefile\.PL$!} @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_->{'full_path'} =~ m[/([^/]+)?Makefile\.PL$]; } , @members) ? : 0 0 0
2589 0 ▶ $has_buildpl = (first {$_->{full_path} =~ m!/([^/]+)?Build\.PL$!} @members) ? 1:0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_->{'full_path'} =~ m[/([^/]+)?Build\.PL$]; } , @members) ? : 0 0 0
2590 }
2591  
2592 0 my $gm_res = _get_meta($la_res);
2593 0 ▶ if ($gm_res->[0] == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gm_res->[0] == 200) { } 0 0 0
2594 0 $meta = $gm_res->[2];
2595 } else {
2596 0 log_warn(" error in meta: %s", $gm_res->[1]);
2597 }
2598 0 ▶ $sth_set_meta_status->execute($meta ? "ok" : "nometa", undef, time(), $file->{id});
Branch: 1 branch
BranchTrueFalseTotal
$meta ? : 0 0 0
2599 0 $sth_set_meta_info->execute($has_metajson, $has_metayml, $has_makefilepl, $has_buildpl, time(), $file->{id});
2600 }
2601  
2602 GET_DEPS:
2603 {
2604 0 ▶ last unless $meta;
Branch: 1 branch
BranchTrueFalseTotal
unless $meta 0 0 0
2605  
2606 # insert dist & dependency information from meta
2607  
2608 0 my $dist_name = $meta->{name};
2609 0 my $dist_abstract = $meta->{abstract};
2610 0 my $dist_version = $meta->{version};
2611 0 $dist_name =~ s/::/-/g; # sometimes author miswrites module name
2612  
2613 0 $sth_set_dist_info->execute($dist_name, $dist_abstract, $dist_version, _numify_ver($dist_version), time(), $file->{id});
2614  
2615 # insert dependency information
2616 0 ▶ if (ref($meta->{configure_requires}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta->{"configure_requires"} eq "HASH") 0 0 0
2617 0 _add_prereqs($file->{id}, $meta->{configure_requires}, 'configure', 'requires', $sth_ins_dep, $sth_sel_mod);
2618 }
2619 0 ▶ if (ref($meta->{build_requires}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta->{"build_requires"} eq "HASH") 0 0 0
2620 0 _add_prereqs($file->{id}, $meta->{build_requires}, 'build', 'requires', $sth_ins_dep, $sth_sel_mod);
2621 }
2622 0 ▶ if (ref($meta->{test_requires}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta->{"test_requires"} eq "HASH") 0 0 0
2623 0 _add_prereqs($file->{id}, $meta->{test_requires}, 'test', 'requires', $sth_ins_dep, $sth_sel_mod);
2624 }
2625 0 ▶ if (ref($meta->{requires}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta->{"requires"} eq "HASH") 0 0 0
2626 0 _add_prereqs($file->{id}, $meta->{requires}, 'runtime', 'requires', $sth_ins_dep, $sth_sel_mod);
2627 }
2628 0 ▶ if (ref($meta->{prereqs}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta->{"prereqs"} eq "HASH") 0 0 0
2629 0 for my $phase (keys %{ $meta->{prereqs} }) {
2630 0 my $phprereqs = $meta->{prereqs}{$phase};
2631 0 for my $rel (keys %$phprereqs) {
2632 0 _add_prereqs($file->{id}, $phprereqs->{$rel}, $phase, $rel, $sth_ins_dep, $sth_sel_mod);
2633 }
2634 }
2635 }
2636 } # GET_DEPS
2637  
2638 PARSE_POD:
2639 {
2640 0 ▶ last if $pass != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $pass != 2 0 0 0
2641 0 ▶ last if $file->{pod_status};
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"pod_status"} 0 0 0
2642  
2643 0 my @contents;
2644 0 $sth_sel_content->execute($file->{id});
2645 0 ▶ while (my $row = $sth_sel_content->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth_sel_content->fetchrow_hashref) 0 0 0
2646 0 push @contents, $row;
2647 }
2648 0 $sth_sel_content->finish;
2649  
2650 0 for my $content (@contents) {
2651 0 my ($script_name) = $code_is_script->($content->{path});
2652 0 my $is_pm_or_pod = $code_is_pm_or_pod->($content->{path});
2653 0 ▶ next unless defined($script_name) || $is_pm_or_pod;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $script_name or $is_pm_or_pod 0 0 0
Condition0%0/3
defined $script_name or $is_pm_or_pod
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $script_name or $is_pm_or_pod
defined $script_name $is_pm_or_pod
Truth table0%0/3
A or B
A= defined $script_nameB= $is_pm_or_pod
ABresult
1X1
011
000
2654  
2655 0 my $ct;
2656 0 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) { } 0 0 0
2657 0 $ct = $zip->contents($content->{path});
2658 } else {
2659 0 my ($obj) = $tar->get_files($content->{path});
2660 0 $ct = $obj->get_content;
2661 }
2662  
2663 _index_pod(
2664 $file->{id}, $file->{name}, $script_name,
2665 $content->{id}, $content->{path},
2666 0 ▶ $ct,
Branch: 1 branch
BranchTrueFalseTotal
defined $script_name ? : 0 0 0
2667 defined($script_name) ? 'script' : 'pm_or_pod',
2668  
2669 $sth_sel_mod,
2670 $sth_sel_script,
2671 $sth_set_module_abstract,
2672 $sth_set_script_abstract,
2673 $sth_set_content_package,
2674  
2675 $module_ids,
2676 $module_file_ids,
2677 $script_file_ids,
2678 $scripts_re,
2679 $sth_ins_mention,
2680 );
2681 } # for each content
2682  
2683 0 $sth_set_pod_status->execute("ok", time(), $file->{id});
2684 } # PARSE_POD
2685  
2686 PARSE_SUB:
2687 {
2688 0 ▶ last if $pass != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $pass != 3 0 0 0
2689  
2690 0 ▶ if (my $reason = $builtin_file_skip_list_sub{ $file->{name} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reason = $builtin_file_skip_list_sub{$file->{"name"}}) 0 0 0
2691 0 log_info("Skipped indexing subs for file %s (reason: built-in file skip list for sub: %s)", $file->{name}, $reason);
2692 0 $sth_set_sub_status->execute("skipped", time(), $file->{id});
2693 0 last;
2694 }
2695  
2696 0 ▶ if ($args{skip_sub_indexing_files} && first {$_ eq $file->{name}} @{ $args{skip_sub_indexing_files} }) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"skip_sub_indexing_files"} and &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_sub_indexing_files"};})) 0 0 0
Condition0%0/3
$args{"skip_sub_indexing_files"} and &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_sub_indexing_files"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"skip_sub_indexing_files"} and &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_sub_indexing_files"};})
$args{"skip_sub_indexing_files"} &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_sub_indexing_files"};})
Truth table0%0/3
A and B
A= $args{"skip_sub_indexing_files"}B= &first(sub { $_ eq $file->{"name"}; } , @{$args{"skip_sub_indexing_files"};})
ABresult
0X0
100
111
2697 0 log_info("Skipped indexing subs for file %s (reason: skip_sub_indexing_files)", $file->{name});
2698 0 $sth_set_sub_status->execute("skipped", time(), $file->{id});
2699 0 last;
2700 }
2701  
2702 0 ▶ if ($args{skip_sub_indexing_file_patterns} && first {$file->{name} =~ $_} @{ $args{skip_sub_indexing_file_patterns} }) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"skip_sub_indexing_file_patterns"} and &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_sub_indexing_file_patterns"};})) 0 0 0
Condition0%0/3
$args{"skip_sub_indexing_file_patterns"} and &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_sub_indexing_file_patterns"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"skip_sub_indexing_file_patterns"} and &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_sub_indexing_file_patterns"};})
$args{"skip_sub_indexing_file_patterns"} &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_sub_indexing_file_patterns"};})
Truth table0%0/3
A and B
A= $args{"skip_sub_indexing_file_patterns"}B= &first(sub { $file->{"name"} =~ /$_/; } , @{$args{"skip_sub_indexing_file_patterns"};})
ABresult
0X0
100
111
2703 0 log_info("Skipped indexing subs for file %s (reason: skip_sub_indexing_file_patterns)", $file->{name});
2704 0 $sth_set_sub_status->execute("skipped", time(), $file->{id});
2705 0 last;
2706 }
2707  
2708 0 my @contents;
2709 0 $sth_sel_content__has_package->execute($file->{id});
2710 0 ▶ while (my $row = $sth_sel_content__has_package->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth_sel_content__has_package->fetchrow_hashref) 0 0 0
2711 0 push @contents, $row;
2712 }
2713 0 $sth_sel_content__has_package->finish;
2714  
2715 0 for my $content (@contents) {
2716 0 my $ct;
2717 0 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) { } 0 0 0
2718 0 $ct = $zip->contents($content->{path});
2719 } else {
2720 0 my ($obj) = $tar->get_files($content->{path});
2721 0 $ct = $obj->get_content;
2722 }
2723  
2724 _index_sub(
2725 $file->{id},
2726 $content->{id}, $content->{path},
2727 0 $ct,
2728  
2729 $sth_ins_sub,
2730 );
2731 } # for each content
2732  
2733 0 $sth_set_sub_status->execute("ok", time(), $file->{id});
2734 } # PARSE_SUB
2735  
2736 } # for each file
2737  
2738 0 ▶ if ($after_begin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after_begin) 0 0 0
2739 0 log_trace("COMMIT");
2740 0 $dbh->commit;
2741 }
2742 } # process files
2743  
2744 # TODO: try to extract its CPAN META or Makefile.PL/Build.PL (dependencies
2745 # information), parse its PODs (module/script abstracts, 'mentions'
2746 # information)
2747  
2748 # there remains some files for which we haven't determine the dist name of
2749 # (e.g. non-existing file, no info, other error). we determine the dist from
2750 # the module name.
2751 {
2752 0 my $sth = $dbh->prepare("SELECT * FROM file WHERE dist_name IS NULL");
2753 0 my @files;
2754 0 $sth->execute;
2755 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
2756 0 push @files, $row;
2757 }
2758  
2759 0 my $sth_sel_mod = $dbh->prepare("SELECT * FROM module WHERE file_id=? ORDER BY name LIMIT 1");
2760 0 my $sth_set_dist_info = $dbh->prepare("UPDATE file SET dist_name=?,dist_version=?,dist_version_numified=?, rec_mtime=? WHERE id=?");
2761  
2762 0 $dbh->begin_work;
2763 FILE:
2764 0 for my $file (@files) {
2765 0 $sth_sel_mod->execute($file->{id});
2766 0 ▶ my $row = $sth_sel_mod->fetchrow_hashref or next FILE;
Branch: 1 branch
BranchTrueFalseTotal
my $row = $sth_sel_mod->fetchrow_hashref or next FILE 0 0 0
2767 0 my $dist_name = $row->{name};
2768 0 $dist_name =~ s/::/-/g;
2769 0 log_trace("Setting dist name for %s as %s (from module name %s)", $row->{name}, $dist_name, $row->{name});
2770 0 $sth_set_dist_info->execute($dist_name, $row->{version}, _numify_ver($row->{version}), time(), $file->{id});
2771 }
2772 0 $dbh->commit;
2773 }
2774  
2775 {
2776 0 log_trace("Updating is_latest_dist column ...");
2777 0 $dbh->do("UPDATE file SET is_latest_dist=".
2778 "(SELECT CASE WHEN EXISTS(SELECT name FROM file f2 WHERE f2.dist_name=file.dist_name AND f2.dist_version_numified>file.dist_version_numified) THEN 0 ELSE 1 END)".
2779 " WHERE dist_name IS NOT NULL");
2780 }
2781  
2782 UPDATE_TIMESTAMPS: {
2783 0 my $now = time();
2784  
2785 0 _dblog($dbh, 40, "update_index", "Finish updating index");
2786  
2787 0 my ($index_creation_time_exists) = $dbh->selectrow_array(
2788 "SELECT 1 FROM META WHERE name='index_creation_time'");
2789 0 my ($last_index_time) = $dbh->selectrow_array(
2790 "SELECT value FROM META WHERE name='last_index_time'");
2791 0 ▶ unless ($index_creation_time_exists) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($index_creation_time_exists) 0 0 0
2792 0 ▶ $dbh->do("INSERT INTO meta (name,value) VALUES (?,?)",
Branch: 1 branch
BranchTrueFalseTotal
$last_index_time ? : 0 0 0
2793 {}, 'index_creation_time',
2794 $last_index_time ? undef : $now);
2795 }
2796 0 $dbh->do("INSERT OR REPLACE INTO meta (name,value) VALUES (?,?)",
2797 {}, 'last_index_time', $now);
2798  
2799 # record the module version that does the indexing
2800 {
2801 0 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.2
2802 $dbh->do("INSERT OR REPLACE INTO meta (name,value) VALUES (?,?)",
2803 0 {}, 'indexer_version', ${__PACKAGE__.'::VERSION'});
2804 }
2805 }
2806  
2807 0 [200];
2808 }
2809  
2810 $SPEC{'update'} = {
2811 v => 1.1,
2812 summary => 'Create/update local CPAN mirror',
2813 description => <<'_',
2814  
2815 This subcommand first create/update the mirror files by downloading from a
2816 remote CPAN mirror, then update the index.
2817  
2818 _
2819 args_rels => {
2820 # it should be: update_index=0 conflicts with force_update_index
2821 #choose_one => [qw/update_index force_update_index/],
2822 },
2823 args => {
2824 %common_args,
2825 max_file_size => {
2826 summary => 'If set, skip downloading files larger than this',
2827 schema => 'int',
2828 tags => ['category:filtering'],
2829 },
2830 retry_max_attempts => {
2831 summary => 'Number of retry attempts on failed HTTP request',
2832 schema => 'int',
2833 tags => ['category:retry'],
2834 },
2835 retry_delay => {
2836 summary => 'Number of seconds to delay between retry attempt',
2837 schema => 'int',
2838 tags => ['category:retry'],
2839 },
2840 include_author => {
2841 summary => 'Only include files from certain author(s)',
2842 'summary.alt.plurality.singular' => 'Only include files from certain author',
2843 schema => ['array*', of=>['str*', match=>qr/\A[A-Z]{2,9}\z/]],
2844 tags => ['category:filtering'],
2845 },
2846 exclude_author => {
2847 summary => 'Exclude files from certain author(s)',
2848 'summary.alt.plurality.singular' => 'Exclude files from certain author',
2849 schema => ['array*', of=>['str*', match=>qr/\A[A-Z]{2,9}\z/]],
2850 tags => ['category:filtering'],
2851 },
2852 remote_url => {
2853 summary => 'Select CPAN mirror to download from',
2854 schema => 'str*',
2855 },
2856 update_files => {
2857 summary => 'Update the files',
2858 'summary.alt.bool.not' => 'Skip updating the files',
2859 schema => 'bool',
2860 default => 1,
2861 },
2862 update_index => {
2863 summary => 'Update the index',
2864 'summary.alt.bool.not' => 'Skip updating the index',
2865 schema => 'bool',
2866 default => 1,
2867 },
2868 force_update_index => {
2869 summary => 'Update the index even though there is no change in files',
2870 schema => ['bool', is=>1],
2871 },
2872 skip_index_files => {
2873 summary => 'Skip one or more files from being indexed',
2874 'x.name.is_plural' => 1,
2875 'summary.alt.plurality.singular' => 'Skip a file from being indexed',
2876 schema => ['array*', of=>'str*'],
2877 cmdline_aliases => {
2878 F => {
2879 summary => 'Alias for --skip-index-file',
2880 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2881 0 ▶ $_[0]{skip_index_files} //= [];
Condition0%0/2
$_[0]{"skip_index_files"} //= []
l!l
00
MC/DC0%0/1
$_[0]{"skip_index_files"} //= []
$_[0]{"skip_index_files"}
Truth table0%0/2
A
A= $_[0]{"skip_index_files"}
Aresult
11
00
2882 0 push @{ $_[0]{skip_index_files} }, $_[1];
2883 },
2884 },
2885 },
2886 98 examples => ['Foo-Bar-1.23.tar.gz'],
2887 },
2888 skip_index_file_patterns => {
2889 summary => 'Skip one or more file patterns from being indexed',
2890 'x.name.is_plural' => 1,
2891 'summary.alt.plurality.singular' => 'Specify a file pattern to skip from being indexed',
2892 schema => ['array*', of=>'re*'],
2893 cmdline_aliases => {
2894 },
2895 examples => ['^Foo-Bar-\d'],
2896 },
2897 skip_sub_indexing_files => {
2898 summary => 'Skip one or more files from being parsed for subs',
2899 'x.name.is_plural' => 1,
2900 'x.name.singular' => 'skip_sub_indexing_file',
2901 'summary.alt.plurality.singular' => 'Skip a file from being parsed for subs',
2902 schema => ['array*', of=>'str*'],
2903 examples => ['Foo-Bar-1.23.tar.gz'],
2904 },
2905 skip_sub_indexing_file_patterns => {
2906 summary => 'Skip one or more file patterns from being parsed for subs',
2907 'x.name.is_plural' => 1,
2908 'x.name.singular' => 'skip_sub_indexing_file_pattern',
2909 'summary.alt.plurality.singular' => 'Specify a file pattern to skip being parsed for subs',
2910 schema => ['array*', of=>'re*'],
2911 cmdline_aliases => {
2912 },
2913 examples => ['^Foo-Bar-\d'],
2914 },
2915 skip_file_indexing_pass_1 => {
2916 schema => 'bool*',
2917 },
2918 skip_file_indexing_pass_2 => {
2919 schema => 'bool*',
2920 },
2921 skip_file_indexing_pass_3 => {
2922 schema => 'bool*',
2923 },
2924 skip_sub_indexing => {
2925 schema => ['bool'],
2926 default => 1,
2927 description => <<'_',
2928  
2929 Since sub indexing is still experimental, it is not enabled by default. To
2930 enable it, pass the `--no-skip-sub-indexing` option.
2931  
2932 _
2933 },
2934 },
2935 tags => ['write-to-db', 'write-to-fs'],
2936 };
2937 0 ▶sub update {
Subroutine update: not called CC=11 SCAR=48.8
Pod documented
2938 0 my %args = @_;
2939 0 _set_args_default(\%args);
2940 0 my $cpan = $args{cpan};
2941  
2942 0 my $packages_path = "$cpan/modules/02packages.details.txt.gz";
2943 0 my @st1 = stat($packages_path);
2944 0 ▶ if (!$args{update_files}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'update_files'}) { } 0 0 0
2945 0 log_info("Skipped updating files (reason: option update_files=0)");
2946 } else {
2947 0 _update_files(%args); # it only returns 200 or dies
2948 }
2949 0 my @st2 = stat($packages_path);
2950  
2951 0 ▶ if (!$args{update_index} && !$args{force_update_index}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $args{'update_index'} || $args{'force_update_index'}) { } 0 0 0
elsif (not $args{'force_update_index'} and $args{'update_files'} and @st1 and @st2 and $st1[9] == $st2[9] and $st1[7] == $st2[7]) { } 0 0 0
Condition0%0/3
$args{'update_index'} || $args{'force_update_index'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'update_index'} || $args{'force_update_index'}
$args{'update_index'} $args{'force_update_index'}
Truth table0%0/3
A || B
A= $args{'update_index'}B= $args{'force_update_index'}
ABresult
1X1
011
000
2952 0 log_info("Skipped updating index (reason: option update_index=0)");
2953 ▶ } elsif (!$args{force_update_index} && $args{update_files} &&
Condition0%0/15
not $args{"force_update_index"} and $args{"update_files"} and @st1 and @st2 and $st1[9] == $st2[9] and $st1[7] == $st2[7]
!ll&&!rl&&r
000
not $args{"force_update_index"} and $args{"update_files"} and @st1 and @st2 and $st1[9] == $st2[9]
!ll&&!rl&&r
000
not $args{"force_update_index"} and $args{"update_files"} and @st1 and @st2
!ll&&!rl&&r
000
not $args{"force_update_index"} and $args{"update_files"} and @st1
!ll&&!rl&&r
000
not $args{"force_update_index"} and $args{"update_files"}
!ll&&!rl&&r
000
MC/DC0%0/6
not $args{"force_update_index"} and $args{"update_files"} and @st1 and @st2 and $st1[9] == $st2[9] and $st1[7] == $st2[7]
not $args{"force_update_index"} $args{"update_files"} @st1 @st2 $st1[9] == $st2[9] $st1[7] == $st2[7]
Truth table0%0/7
not(A) and B and C and D and E and F
A= not $args{"force_update_index"}B= $args{"update_files"}C= @st1D= @st2E= $st1[9] == $st2[9]F= $st1[7] == $st2[7]
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
2954 @st1 && @st2 && $st1[9] == $st2[9] && $st1[7] == $st2[7]) {
2955 0 log_info("%s doesn't change mtime/size, skipping updating index",
2956 $packages_path);
2957 0 return [304, "Files did not change, index not updated"];
2958 } else {
2959 0 my $res = _update_index(%args);
2960 0 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
2961 }
2962 0 [200, "OK"];
2963 }
2964  
2965 0 ▶sub _table_exists {
Subroutine _table_exists: not called CC=2 SCAR=17.9
2966 0 my ($dbh, $schema, $name) = @_;
2967 0 my $sth = $dbh->table_info(undef, $schema, $name, undef);
2968 0 ▶ $sth->fetchrow_hashref ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$sth->fetchrow_hashref ? : 0 0 0
2969 }
2970  
2971 0 ▶sub _reset {
Subroutine _reset: not called CC=12 SCAR=50.5
2972 # this sub is used since v7, so we need to check tables that have not
2973 # existed in v7 or earlier.
2974 0 my ($dbh, $soft) = @_;
2975 0 $dbh->do("DELETE FROM dep");
2976 0 $dbh->do("DELETE FROM namespace");
2977 0 ▶ $dbh->do("DELETE FROM mention") if _table_exists($dbh, "main", "mention");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "mention") 0 0 0
2978 0 $dbh->do("DELETE FROM module");
2979 0 ▶ $dbh->do("DELETE FROM old_module")if _table_exists($dbh, "main", "old_module");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "old_module") 0 0 0
2980 0 ▶ $dbh->do("DELETE FROM script") if _table_exists($dbh, "main", "script");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "script") 0 0 0
2981 0 ▶ $dbh->do("DELETE FROM old_script")if _table_exists($dbh, "main", "old_script");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "old_script") 0 0 0
2982 0 ▶ $dbh->do("DELETE FROM sub") if _table_exists($dbh, "main", "sub");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "sub") 0 0 0
2983 0 ▶ $dbh->do("DELETE FROM dist") if _table_exists($dbh, "main", "dist");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "dist") 0 0 0
2984 0 ▶ $dbh->do("DELETE FROM content") if _table_exists($dbh, "main", "content");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "content") 0 0 0
2985 0 $dbh->do("DELETE FROM file");
2986 0 ▶ $dbh->do("DELETE FROM old_file") if _table_exists($dbh, "main", "old_file");
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "old_file") 0 0 0
2987 0 $dbh->do("DELETE FROM author");
2988 0 ▶ $dbh->do("DELETE FROM log") if _table_exists($dbh, "main", "log") && !$soft;
Branch: 1 branch
BranchTrueFalseTotal
if _table_exists($dbh, "main", "log") and not $soft 0 0 0
Condition0%0/3
_table_exists($dbh, "main", "log") and not $soft
!ll&&!rl&&r
000
MC/DC0%0/2
_table_exists($dbh, "main", "log") and not $soft
_table_exists($dbh, "main", "log") not $soft
Truth table0%0/3
A and not(B)
A= _table_exists($dbh, "main", "log")B= not $soft
ABresult
0X0
100
111
2989  
2990 0 ▶ $dbh->do("DELETE FROM meta WHERE name='index_creation_time'") if !$soft;
Branch: 1 branch
BranchTrueFalseTotal
if not $soft 0 0 0
2991 }
2992  
2993 98 $SPEC{'reset'} = {
2994 v => 1.1,
2995 summary => 'Reset (empty) the database index',
2996 description => <<'_',
2997  
2998 All data tables will be emptied. This includes all records in the `log` table as
2999 well as `index_creation_time` record in the `meta` table, so there is no records
3000 of previous indexing activity. There is also no record of resetting in the
3001 `log`.
3002  
3003 Tables are not dropped and re-created. The `meta` table is not emptied.
3004  
3005 _
3006 args => {
3007 %common_args,
3008 },
3009 tags => ['write-to-db'],
3010 };
3011 0 ▶sub reset {
Subroutine reset: not called CC=2 SCAR=17.9
Pod documented
3012 0 require IO::Prompt::I18N;
3013  
3014 0 my %args = @_;
3015  
3016 0 my $state = _init(\%args, 'rw');
3017 0 my $dbh = $state->{dbh};
3018  
3019 0 ▶ return [200, "Cancelled"]
Branch: 1 branch
BranchTrueFalseTotal
unless IO::Prompt::I18N::confirm("Confirm reset index", {"default", 0}) 0 0 0
3020 unless IO::Prompt::I18N::confirm("Confirm reset index", {default=>0});
3021  
3022 0 _reset($dbh);
3023 0 [200, "Reset"];
3024 }
3025  
3026 98 $SPEC{'stats'} = {
3027 v => 1.1,
3028 summary => 'Statistics of your local CPAN mirror',
3029 args => {
3030 %common_args,
3031 },
3032 };
3033 0 ▶sub stats {
Subroutine stats: not called CC=2 SCAR=17.9
Pod documented
3034 0 my %args = @_;
3035  
3036 0 my $state = _init(\%args, 'ro');
3037 0 my $dbh = $state->{dbh};
3038  
3039 0 my $stat = {};
3040  
3041 0 ($stat->{num_authors}) = $dbh->selectrow_array("SELECT COUNT(*) FROM author");
3042 0 ($stat->{num_authors_with_releases}) = $dbh->selectrow_array("SELECT COUNT(DISTINCT cpanid) FROM file");
3043 0 ($stat->{num_modules}) = $dbh->selectrow_array("SELECT COUNT(*) FROM module");
3044 0 ($stat->{num_namespaces}) = $dbh->selectrow_array("SELECT COUNT(*) FROM namespace");
3045 (
3046 $stat->{num_releases},
3047 $stat->{num_releases_with_metajson},
3048 $stat->{num_releases_with_metayml},
3049 $stat->{num_releases_with_makefilepl},
3050 $stat->{num_releases_with_buildpl},
3051 0 ) = $dbh->selectrow_array("SELECT
3052 COUNT(*),
3053 SUM(CASE has_metajson WHEN 1 THEN 1 ELSE 0 END),
3054 SUM(CASE has_metayml WHEN 1 THEN 1 ELSE 0 END),
3055 SUM(CASE has_makefilepl WHEN 1 THEN 1 ELSE 0 END),
3056 SUM(CASE has_buildpl WHEN 1 THEN 1 ELSE 0 END)
3057 FROM file");
3058 0 ($stat->{schema_version}) = $dbh->selectrow_array("SELECT value FROM meta WHERE name='schema_version'");
3059  
3060 0 ($stat->{num_scripts}) = $dbh->selectrow_array("SELECT COUNT(DISTINCT name) FROM script");
3061 0 ($stat->{num_content}) = $dbh->selectrow_array("SELECT COUNT(*) FROM content");
3062 0 ($stat->{num_mentions}) = $dbh->selectrow_array("SELECT COUNT(*) FROM mention");
3063  
3064 0 ($stat->{total_filesize}) = $dbh->selectrow_array("SELECT SUM(size) FROM file");
3065  
3066 0 ($stat->{num_subs}) = $dbh->selectrow_array("SELECT COUNT(*) FROM sub");
3067  
3068 {
3069 0 my ($time) = $dbh->selectrow_array("SELECT value FROM meta WHERE name='index_creation_time'");
3070 0 $stat->{raw_index_creation_time} = $time;
3071 0 $stat->{index_creation_time} = _fmt_time($time);
3072 }
3073 {
3074 0 my ($time) = $dbh->selectrow_array("SELECT value FROM meta WHERE name='last_index_time'");
3075 0 $stat->{raw_last_index_time} = $time;
3076 0 $stat->{last_index_time} = _fmt_time($time);
3077 }
3078 {
3079 0 my ($ver) = $dbh->selectrow_array("SELECT value FROM meta WHERE name='indexer_version'");
3080 0 $stat->{indexer_version} = $ver;
3081 }
3082 {
3083 0 my @st = stat "$state->{cpan}/modules/02packages.details.txt.gz";
3084 0 ▶ $stat->{mirror_mtime} = _fmt_time(@st ? $st[9] : undef);
Branch: 1 branch
BranchTrueFalseTotal
@st ? : 0 0 0
3085 0 $stat->{raw_mirror_mtime} = $st[9];
3086 }
3087  
3088 0 [200, "OK", $stat];
3089 }
3090  
3091 98 $SPEC{'log'} = {
3092 v => 1.1,
3093 summary => 'Show database index log',
3094 args => {
3095 %common_args,
3096 },
3097 };
3098 0 ▶sub log {
Subroutine log: not called CC=2 SCAR=17.9
Pod documented
3099 0 my %args = @_;
3100  
3101 0 my $state = _init(\%args, 'ro');
3102 0 my $dbh = $state->{dbh};
3103  
3104 0 my $sth = $dbh->prepare("SELECT * FROM log ORDER BY date");
3105 0 $sth->execute;
3106 0 my @rows;
3107 0 ▶ while (my $row = $sth->fetchrow_hashref) { push @rows, $row }
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
3108  
3109 0 [200, "OK", \@rows, {
3110 'table.fields' => ['id', 'date', 'pid', 'lcpan_version', 'level', 'category', 'summary'],
3111 'table.field_formats' => [undef, 'iso8601_datetime', undef, undef, undef, undef, undef],
3112 }];
3113 }
3114  
3115 0 ▶sub _complete_mod {
Subroutine _complete_mod: not called CC=12 SCAR=50.5
3116 0 my %args = @_;
3117  
3118 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3119  
3120 # completing from an empty word is very slow
3121 0 ▶ return {message=>"Please enter a few characters of module name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3122 unless length $word;
3123  
3124 # only run under pericmd
3125 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3126 0 my $r = $args{r};
3127  
3128 # allow writing Mod::SubMod as Mod/SubMod
3129 0 ▶ my $uses_slash = $word =~ s!/!::!g ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$word =~ s[/][::]g ? : 0 0 0
3130  
3131 # force read config file, because by default it is turned off when in
3132 # completion
3133 0 $r->{read_config} = 1;
3134 0 my $res = $cmdline->parse_argv($r);
3135 0 _set_args_default($res->[2]);
3136  
3137 0 my $dbh;
3138 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3139  
3140 # if we can't connect (probably because database is not yet setup), bail
3141 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3142 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3143 0 return undef;
3144 }
3145  
3146 0 my $sth = $dbh->prepare(
3147 "SELECT DISTINCT name,abstract FROM module WHERE name LIKE ? ORDER BY name");
3148 0 $sth->execute($word . '%');
3149  
3150 # XXX follow Complete::Common::OPT_CI
3151  
3152 0 my @res;
3153 0 ▶ while (my ($mod,$abstract) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3154 # only complete one level deeper at a time
3155 0 ▶ if ($mod =~ /:\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /:\z/) { } 0 0 0
3156 0 ▶ next unless $mod =~ /\A\Q$word\E:*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod =~ /\A\Q$word\E:*\w+\z/i 0 0 0
3157 } else {
3158 0 ▶ next unless $mod =~ /\A\Q$word\E\w*(::\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod =~ /\A\Q$word\E\w*(::\w+)?\z/i 0 0 0
3159 }
3160 0 push @res, {word=>$mod, summary=>$abstract};
3161 }
3162  
3163 # convert back to slash if user originally typed with slash
3164 0 ▶ if ($uses_slash) { for (@res) { $_->{word} =~ s!::!/!g } }
Branch: 1 branch
BranchTrueFalseTotal
if ($uses_slash) 0 0 0
3165  
3166 0 \@res;
3167 };
3168  
3169 0 ▶sub _complete_mod_or_dist {
Subroutine _complete_mod_or_dist: not called CC=17 SCAR=57.2
3170 0 my %args = @_;
3171  
3172 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3173  
3174 # completing from an empty word is very slow
3175 0 ▶ return {message=>"Please enter a few characters of module/distro name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3176 unless length $word;
3177  
3178 # only run under pericmd
3179 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3180 0 my $r = $args{r};
3181  
3182 # allow writing Mod::SubMod as Mod/SubMod
3183 0 ▶ my $uses_slash = $word =~ s!/!::!g ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$word =~ s[/][::]g ? : 0 0 0
3184  
3185 # force read config file, because by default it is turned off when in
3186 # completion
3187 0 $r->{read_config} = 1;
3188 0 my $res = $cmdline->parse_argv($r);
3189 0 _set_args_default($res->[2]);
3190  
3191 0 my $dbh;
3192 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3193  
3194 # if we can't connect (probably because database is not yet setup), bail
3195 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3196 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3197 0 return undef;
3198 }
3199  
3200 0 my $sth;
3201  
3202 my $is_dist;
3203 0 ▶ if ($word =~ /-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /-/) { } 0 0 0
3204 0 $is_dist++;
3205 0 $sth = $dbh->prepare(
3206 "SELECT DISTINCT dist_name,dist_abstract FROM file WHERE dist_name LIKE ? ORDER BY dist_name");
3207 } else {
3208 0 $sth = $dbh->prepare(
3209 "SELECT name,abstract FROM module WHERE name LIKE ? ORDER BY name");
3210 }
3211 0 $sth->execute($word . '%');
3212  
3213 # XXX follow Complete::Common::OPT_CI
3214  
3215 0 my @res;
3216 0 ▶ while (my ($e,$summary) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3217 # only complete one level deeper at a time
3218 0 ▶ if ($is_dist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dist) { } 0 0 0
3219 0 ▶ if ($e =~ /-\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /-\z/) { } 0 0 0
3220 0 ▶ next unless $e =~ /\A\Q$word\E-*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E-*\w+\z/i 0 0 0
3221 } else {
3222 0 ▶ next unless $e =~ /\A\Q$word\E\w*(-\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E\w*(-\w+)?\z/i 0 0 0
3223 }
3224 } else {
3225 0 ▶ if ($e =~ /:\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /:\z/) { } 0 0 0
3226 0 ▶ next unless $e =~ /\A\Q$word\E:*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E:*\w+\z/i 0 0 0
3227 } else {
3228 0 ▶ next unless $e =~ /\A\Q$word\E\w*(::\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E\w*(::\w+)?\z/i 0 0 0
3229 }
3230 }
3231 0 push @res, {word=>$e, summary=>$summary};
3232 }
3233  
3234 # convert back to slash if user originally typed with slash
3235 0 ▶ if ($uses_slash) { for (@res) { $_->{word} =~ s!::!/!g } }
Branch: 1 branch
BranchTrueFalseTotal
if ($uses_slash) 0 0 0
3236  
3237 0 \@res;
3238 };
3239  
3240 0 ▶sub _complete_mod_or_dist_or_script {
Subroutine _complete_mod_or_dist_or_script: not called CC=19 SCAR=59.4
3241 0 my %args = @_;
3242  
3243 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3244  
3245 # completing from an empty word is very slow
3246 0 ▶ return {message=>"Please enter a few characters of module/distro/script name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3247 unless length $word;
3248  
3249 # only run under pericmd
3250 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3251 0 my $r = $args{r};
3252  
3253 # allow writing Mod::SubMod as Mod/SubMod
3254 0 ▶ my $uses_slash = $word =~ s!/!::!g ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$word =~ s[/][::]g ? : 0 0 0
3255  
3256 # force read config file, because by default it is turned off when in
3257 # completion
3258 0 $r->{read_config} = 1;
3259 0 my $res = $cmdline->parse_argv($r);
3260 0 _set_args_default($res->[2]);
3261  
3262 0 my $dbh;
3263 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3264  
3265 # if we can't connect (probably because database is not yet setup), bail
3266 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3267 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3268 0 return undef;
3269 }
3270  
3271 0 my $sth;
3272  
3273 my $is_dist;
3274 0 ▶ if ($word =~ /-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /-/) { } 0 0 0
3275 0 $is_dist++;
3276 0 $sth = $dbh->prepare(
3277 "SELECT DISTINCT dist_name,dist_abstract FROM file WHERE dist_name LIKE ? ORDER BY dist_name");
3278 } else {
3279 0 $sth = $dbh->prepare(
3280 "SELECT name FROM module,abstract WHERE name LIKE ? ORDER BY name");
3281 }
3282 0 $sth->execute($word . '%');
3283  
3284 # XXX follow Complete::Common::OPT_CI
3285  
3286 0 my @res;
3287 0 ▶ while (my ($e,$summary) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3288 # only complete one level deeper at a time
3289 0 ▶ if ($is_dist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dist) { } 0 0 0
3290 0 ▶ if ($e =~ /-\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /-\z/) { } 0 0 0
3291 0 ▶ next unless $e =~ /\A\Q$word\E-*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E-*\w+\z/i 0 0 0
3292 } else {
3293 0 ▶ next unless $e =~ /\A\Q$word\E\w*(-\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E\w*(-\w+)?\z/i 0 0 0
3294 }
3295 } else {
3296 0 ▶ if ($e =~ /:\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /:\z/) { } 0 0 0
3297 0 ▶ next unless $e =~ /\A\Q$word\E:*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E:*\w+\z/i 0 0 0
3298 } else {
3299 0 ▶ next unless $e =~ /\A\Q$word\E\w*(::\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\Q$word\E\w*(::\w+)?\z/i 0 0 0
3300 }
3301 }
3302 0 push @res, {word=>$e, summary=>$summary};
3303 }
3304  
3305 # also get candidates from script name
3306 0 ▶ unless ($word =~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($word =~ /::/) 0 0 0
3307 0 $sth = $dbh->prepare(
3308 "SELECT DISTINCT name,abstract FROM script WHERE name LIKE ? ORDER BY name");
3309 0 $sth->execute($word . '%');
3310 0 ▶ while (my ($e,$abstract) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3311 0 push @res, {word=>$e, summary=>$abstract};
3312 }
3313 }
3314  
3315 # convert back to slash if user originally typed with slash
3316 0 ▶ if ($uses_slash) { for (@res) { $_->{word} =~ s!::!/!g } }
Branch: 1 branch
BranchTrueFalseTotal
if ($uses_slash) 0 0 0
3317  
3318 0 \@res;
3319 };
3320  
3321 0 ▶sub _complete_ns {
Subroutine _complete_ns: not called CC=13 SCAR=52.0
3322 0 my %args = @_;
3323  
3324 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3325  
3326 # completing from an empty word is very slow
3327 0 ▶ return {message=>"Please enter a few characters of namespace first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3328 unless length $word;
3329  
3330 # only run under pericmd
3331 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3332 0 my $r = $args{r};
3333  
3334 # allow writing Mod::SubMod as Mod/SubMod
3335 0 ▶ my $uses_slash = $word =~ s!/!::!g ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$word =~ s[/][::]g ? : 0 0 0
3336  
3337 # force read config file, because by default it is turned off when in
3338 # completion
3339 0 $r->{read_config} = 1;
3340 0 my $res = $cmdline->parse_argv($r);
3341 0 _set_args_default($res->[2]);
3342  
3343 0 my $dbh;
3344 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3345  
3346 # if we can't connect (probably because database is not yet setup), bail
3347 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3348 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3349 0 return undef;
3350 }
3351  
3352 0 my $sth = $dbh->prepare(
3353 "SELECT ns.name name, m.abstract FROM namespace ns LEFT JOIN module m ON ns.name=m.name WHERE ns.name LIKE ? ORDER BY ns.name");
3354 0 $sth->execute($word . '%');
3355  
3356 # XXX follow Complete::Common::OPT_CI
3357  
3358 0 my @res;
3359 0 ▶ while (my ($ns, $abstract) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3360 # only complete one level deeper at a time
3361 0 ▶ if ($ns =~ /:\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns =~ /:\z/) { } 0 0 0
3362 0 ▶ next unless $ns =~ /\A\Q$word\E:*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $ns =~ /\A\Q$word\E:*\w+\z/i 0 0 0
3363 } else {
3364 0 ▶ next unless $ns =~ /\A\Q$word\E\w*(::\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $ns =~ /\A\Q$word\E\w*(::\w+)?\z/i 0 0 0
3365 }
3366 0 ▶ push @res, {word=>$ns, (defined($abstract) ? (summary=>$abstract) : ())};
Branch: 1 branch
BranchTrueFalseTotal
defined $abstract ? : 0 0 0
3367 }
3368  
3369 # convert back to slash if user originally typed with slash
3370 0 ▶ if ($uses_slash) { for (@res) { $_->{word} =~ s!::!/!g } }
Branch: 1 branch
BranchTrueFalseTotal
if ($uses_slash) 0 0 0
3371  
3372 0 \@res;
3373 };
3374  
3375 0 ▶sub _complete_script {
Subroutine _complete_script: not called CC=6 SCAR=37.4
3376 0 my %args = @_;
3377  
3378 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3379  
3380 # completing from an empty word is very slow
3381 0 ▶ return {message=>"Please enter a few characters of script name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3382 unless length $word;
3383  
3384 # only run under pericmd
3385 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3386 0 my $r = $args{r};
3387  
3388 # force read config file, because by default it is turned off when in
3389 # completion
3390 0 $r->{read_config} = 1;
3391 0 my $res = $cmdline->parse_argv($r);
3392 0 _set_args_default($res->[2]);
3393  
3394 0 my $dbh;
3395 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3396  
3397 # if we can't connect (probably because database is not yet setup), bail
3398 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3399 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3400 0 return undef;
3401 }
3402  
3403 0 my $sth = $dbh->prepare(
3404 "SELECT DISTINCT name,abstract FROM script WHERE name LIKE ? ORDER BY name");
3405 0 $sth->execute($word . '%');
3406  
3407 # XXX follow Complete::Common::OPT_CI
3408  
3409 0 my @res;
3410 0 ▶ while (my ($script, $abstract) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3411 0 push @res, {word=>$script, summary=>$abstract};
3412 }
3413  
3414 0 \@res;
3415 };
3416  
3417 0 ▶sub _complete_dist {
Subroutine _complete_dist: not called CC=9 SCAR=45.0
3418 0 my %args = @_;
3419  
3420 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3421  
3422 # completing from an empty word is very slow
3423 0 ▶ return {message=>"Please enter a few characters of distro name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3424 unless length $word;
3425  
3426 # only run under pericmd
3427 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3428 0 my $r = $args{r};
3429  
3430 # force read config file, because by default it is turned off when in
3431 # completion
3432 0 $r->{read_config} = 1;
3433 0 my $res = $cmdline->parse_argv($r);
3434 0 _set_args_default($res->[2]);
3435  
3436 0 my $dbh;
3437 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3438  
3439 # if we can't connect (probably because database is not yet setup), bail
3440 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3441 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3442 0 return undef;
3443 }
3444  
3445 0 my $sth = $dbh->prepare(
3446 "SELECT DISTINCT dist_name,dist_abstract FROM file WHERE dist_name LIKE ? ORDER BY dist_name");
3447 0 $sth->execute($word . '%');
3448  
3449 # XXX follow Complete::Common::OPT_CI
3450  
3451 0 my @res;
3452 0 ▶ while (my ($dist,$abstract) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3453 # only complete one level deeper at a time
3454 0 ▶ if ($dist =~ /-\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist =~ /-\z/) { } 0 0 0
3455 0 ▶ next unless $dist =~ /\A\Q$word\E-*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $dist =~ /\A\Q$word\E-*\w+\z/i 0 0 0
3456 } else {
3457 0 ▶ next unless $dist =~ /\A\Q$word\E\w*(-\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $dist =~ /\A\Q$word\E\w*(-\w+)?\z/i 0 0 0
3458 }
3459 0 push @res, {word=>$dist, summary=>$abstract};
3460 }
3461  
3462 0 \@res;
3463 };
3464  
3465 0 ▶sub _complete_cpanid {
Subroutine _complete_cpanid: not called CC=6 SCAR=37.4
3466 0 my %args = @_;
3467  
3468 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3469  
3470 # completing from an empty word is very slow
3471 0 ▶ return {message=>"Please enter a few characters of PAUSE ID first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3472 unless length $word;
3473  
3474 # only run under pericmd
3475 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3476 0 my $r = $args{r};
3477  
3478 # force read config file, because by default it is turned off when in
3479 # completion
3480 0 $r->{read_config} = 1;
3481 0 my $res = $cmdline->parse_argv($r);
3482 0 _set_args_default($res->[2]);
3483  
3484 0 my $dbh;
3485 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3486  
3487 # if we can't connect (probably because database is not yet setup), bail
3488 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3489 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3490 0 return undef;
3491 }
3492  
3493 0 my $sth = $dbh->prepare(
3494 "SELECT cpanid,fullname FROM author WHERE cpanid LIKE ? ORDER BY cpanid");
3495 0 $sth->execute($word . '%');
3496  
3497 # XXX follow Complete::Common::OPT_CI
3498  
3499 0 my @res;
3500 0 ▶ while (my ($cpanid, $fullname) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3501 0 push @res, {word=>$cpanid, summary=>$fullname};
3502 }
3503  
3504 0 \@res;
3505 };
3506  
3507 0 ▶sub _complete_rel {
Subroutine _complete_rel: not called CC=6 SCAR=37.4
3508 0 my %args = @_;
3509  
3510 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3511  
3512 # completing from an empty word is very slow
3513 0 ▶ return {message=>"Please enter a few characters of release name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3514 unless length $word;
3515  
3516 # only run under pericmd
3517 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3518 0 my $r = $args{r};
3519  
3520 # force read config file, because by default it is turned off when in
3521 # completion
3522 0 $r->{read_config} = 1;
3523 0 my $res = $cmdline->parse_argv($r);
3524 0 _set_args_default($res->[2]);
3525  
3526 0 my $dbh;
3527 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3528  
3529 # if we can't connect (probably because database is not yet setup), bail
3530 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3531 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3532 0 return undef;
3533 }
3534  
3535 0 my $sth = $dbh->prepare(
3536 "SELECT name,dist_abstract FROM file WHERE name LIKE ? ORDER BY name");
3537 0 $sth->execute($word . '%');
3538  
3539 # XXX follow Complete::Common::OPT_CI
3540  
3541 0 my @res;
3542 0 ▶ while (my ($rel,$abstract) = $sth->fetchrow_array) { #
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
3543 0 push @res, {word=>$rel, summary=>$abstract};
3544 }
3545  
3546 0 \@res;
3547 };
3548  
3549 0 ▶sub _complete_content_package_or_script {
Subroutine _complete_content_package_or_script: not called CC=14 SCAR=53.5
3550 0 my %args = @_;
3551  
3552 0 ▶ my $word = $args{word} // '';
Condition0%0/2
$args{"word"} // ""
l!l
00
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
Aresult
11
00
3553  
3554 # completing from an empty word is very slow
3555 0 ▶ return {message=>"Please enter a few characters of content/package/script name first", static=>1}
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 0 0 0
3556 unless length $word;
3557  
3558 # only run under pericmd
3559 0 ▶ my $cmdline = $args{cmdline} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $cmdline = $args{"cmdline"} or return undef 0 0 0
3560 0 my $r = $args{r};
3561  
3562 # allow writing Mod::SubMod as Mod/SubMod
3563 0 ▶ my $uses_slash = $word =~ s!/!::!g ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$word =~ s[/][::]g ? : 0 0 0
3564  
3565 # force read config file, because by default it is turned off when in
3566 # completion
3567 0 $r->{read_config} = 1;
3568 0 my $res = $cmdline->parse_argv($r);
3569 0 _set_args_default($res->[2]);
3570  
3571 0 my $dbh;
3572 0 eval { $dbh = _connect_db('ro', $res->[2]{cpan}, $res->[2]{index_name}, 0, 0) };
3573  
3574 # if we can't connect (probably because database is not yet setup), bail
3575 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3576 0 log_trace("[comp] can't connect to db, bailing: %s", $@);
3577 0 return undef;
3578 }
3579  
3580 0 my $sth;
3581 my @res;
3582  
3583 # complete from content package
3584 {
3585 0 $sth = $dbh->prepare(
3586 "SELECT DISTINCT package FROM content WHERE package LIKE ? ORDER BY package");
3587 0 $sth->execute($word . '%');
3588  
3589 # XXX follow Complete::Common::OPT_CI
3590  
3591 0 ▶ while (my ($pkg) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($pkg) = $sth->fetchrow_array) 0 0 0
3592 # only complete one level deeper at a time
3593 0 ▶ if ($pkg =~ /:\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /:\z/) { } 0 0 0
3594 0 ▶ next unless $pkg =~ /\A\Q$word\E:*\w+\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /\A\Q$word\E:*\w+\z/i 0 0 0
3595 } else {
3596 0 ▶ next unless $pkg =~ /\A\Q$word\E\w*(::\w+)?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /\A\Q$word\E\w*(::\w+)?\z/i 0 0 0
3597 }
3598 0 push @res, $pkg;
3599 }
3600 }
3601  
3602 # complete from script
3603 {
3604 0 ▶ last if $word =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /::/ 0 0 0
3605 0 $sth = $dbh->prepare(
3606 "SELECT DISTINCT name FROM script WHERE name LIKE ? ORDER BY name");
3607 0 $sth->execute($word . '%');
3608  
3609 # XXX follow Complete::Common::OPT_CI
3610  
3611 0 ▶ while (my ($script) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($script) = $sth->fetchrow_array) 0 0 0
3612 0 push @res, $script;
3613 }
3614 }
3615  
3616 # convert back to slash if user originally typed with slash
3617 0 ▶ if ($uses_slash) { for (@res) { s!::!/!g } }
Branch: 1 branch
BranchTrueFalseTotal
if ($uses_slash) 0 0 0
3618  
3619 0 \@res;
3620 };
3621  
3622  
3623 $SPEC{authors} = {
3624 v => 1.1,
3625 summary => 'List authors',
3626 args => {
3627 %common_args,
3628 98 ▶ %{( modclone {
Subroutine __ANON__: called CC=1 SCAR=6.1
3629 0 ▶ $_->{query}{element_completion} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
3630 0 my %args = @_;
3631 0 my $r = $args{r};
3632 0 ▶ return undef unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 0 0
3633 0 my $cmdline = $args{cmdline};
3634 0 my $res = $cmdline->parse_argv($r);
3635 0 ▶ return undef unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
3636  
3637 # provide completion for modules if query_type is exact-cpanid
3638 0 ▶ my $qt = $res->[2]{query_type} // '';
Condition0%0/2
$res->[2]{"query_type"} // ""
l!l
00
MC/DC0%0/1
$res->[2]{"query_type"} // ""
$res->[2]{"query_type"}
Truth table0%0/2
A
A= $res->[2]{"query_type"}
Aresult
11
00
3639 0 ▶ return _complete_cpanid(%args) if $qt eq 'exact-cpanid';
Branch: 1 branch
BranchTrueFalseTotal
if $qt eq "exact-cpanid" 0 0 0
3640  
3641 0 undef;
3642 98 };
3643 98 } \%query_multi_args )},
3644 query_type => {
3645 schema => ['str*', in=>[qw/any cpanid exact-cpanid fullname regexp-fullname email exact-email/]],
3646 default => 'any',
3647 cmdline_aliases => {
3648 x => {
3649 summary => 'Shortcut --query-type exact-cpanid',
3650 is_flag => 1,
3651 0 ▶ code => sub { $_[0]{query_type} = 'exact-cpanid' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3652 },
3653 r => {
3654 summary => 'Shortcut --query-type regexp-fullname',
3655 is_flag => 1,
3656 0 ▶ code => sub { $_[0]{query_type} = 'regexp-fullname' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3657 },
3658 n => {
3659 summary => 'Shortcut --query-type cpanid',
3660 is_flag => 1,
3661 0 ▶ code => sub { $_[0]{query_type} = 'cpanid' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3662 },
3663 },
3664 },
3665 98 %fctime_or_mtime_args,
3666 %sort_args_for_authors,
3667 %paging_args,
3668 },
3669 result => {
3670 description => <<'_',
3671  
3672 By default will return an array of CPAN ID's. If you set `detail` to true, will
3673 return array of records.
3674  
3675 _
3676 },
3677 examples => [
3678 {
3679 summary => 'List all authors',
3680 argv => [],
3681 test => 0,
3682 'x.doc.show_result' => 0,
3683 },
3684 {
3685 summary => 'Find CPAN IDs which start with something',
3686 argv => ['MICHAEL%'],
3687 result => ['MICHAEL', 'MICHAELW'],
3688 test => 0,
3689 },
3690 ],
3691 };
3692 0 ▶sub authors {
Subroutine authors: not called CC=31 SCAR=69.0
Pod documented
3693 0 my %args = @_;
3694  
3695 0 my $state = _init(\%args, 'ro');
3696 0 my $dbh = $state->{dbh};
3697  
3698 0 my $detail = $args{detail};
3699 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
3700 0 ▶ my $sort = $args{sort} // ['id'];
Condition0%0/2
$args{"sort"} // ["id"]
l!l
00
MC/DC0%0/1
$args{"sort"} // ["id"]
$args{"sort"}
Truth table0%0/2
A
A= $args{"sort"}
Aresult
11
00
3701  
3702 0 my @bind;
3703 my @where;
3704 {
3705 0 my @q_where;
3706 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
3707 0 ▶ if ($qt eq 'any') {
Branch: 7 branches
BranchTrueFalseTotal
if ($qt eq 'any') { } 0 0 0
elsif ($qt eq 'cpanid') { } 0 0 0
elsif ($qt eq 'exact-cpanid') { } 0 0 0
elsif ($qt eq 'fullname') { } 0 0 0
elsif ($qt eq 'regexp-fullname') { } 0 0 0
elsif ($qt eq 'email') { } 0 0 0
elsif ($qt eq 'exact-email') { } 0 0 0
3708 0 ▶ my $q = uc($q0 =~ /%/ ? $q0 : '%'.$q0.'%');
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3709 0 push @q_where, "(cpanid LIKE ? OR fullname LIKE ? OR email like ?)";
3710 0 push @bind, $q, $q, $q;
3711 } elsif ($qt eq 'cpanid') {
3712 0 ▶ my $q = uc($q0 =~ /%/ ? $q0 : '%'.$q0.'%');
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3713 0 push @q_where, "(cpanid LIKE ?)";
3714 0 push @bind, $q;
3715 } elsif ($qt eq 'exact-cpanid') {
3716 0 push @q_where, "(cpanid=?)";
3717 0 push @bind, uc($q0);
3718 } elsif ($qt eq 'fullname') {
3719 0 ▶ my $q = uc($q0 =~ /%/ ? $q0 : '%'.$q0.'%');
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3720 0 push @q_where, "(fullname LIKE ?)";
3721 0 push @bind, $q;
3722 } elsif ($qt eq 'regexp-fullname') {
3723 0 push @q_where, "(fullname REGEXP ?)";
3724 0 push @bind, $q0;
3725 } elsif ($qt eq 'email') {
3726 0 ▶ my $q = uc($q0 =~ /%/ ? $q0 : '%'.$q0.'%');
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3727 0 push @q_where, "(email LIKE ?)";
3728 0 push @bind, $q;
3729 } elsif ($qt eq 'exact-email') {
3730 0 push @q_where, "(LOWER(email)=?)";
3731 0 push @bind, lc($q0);
3732 }
3733 }
3734 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
3735 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
3736 } elsif (@q_where == 1) {
3737 0 push @where, @q_where;
3738 }
3739 }
3740  
3741 0 _set_since(\%args, $dbh);
3742 0 _add_since_where_clause(\%args, \@where, 'author');
3743  
3744 0 my @order;
3745 0 ▶ if ($args{random}) { push @order, "RANDOM()" }
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"random"}) 0 0 0
3746 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
3747  
3748 my $sql = "SELECT
3749 cpanid id,
3750 fullname name,
3751 email
3752 FROM author".
3753 (@where ? " WHERE ".join(" AND ", @where) : "").
3754 (@order ? " ORDER BY ".join(", ", @order) : "").
3755 0 ▶ ($args{result_limit} ? " LIMIT ".($args{result_start} && $args{result_start} > 1 ? ($args{result_start}-1)."," : "").($args{result_limit}+0) : "");
Branch: 4 branches
BranchTrueFalseTotal
@where ? : 0 0 0
@order ? : 0 0 0
$args{'result_limit'} ? : 0 0 0
$args{'result_start'} && $args{'result_start'} > 1 ? : 0 0 0
Condition0%0/3
$args{"result_start"} and $args{"result_start"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"result_start"} and $args{"result_start"} > 1
$args{"result_start"} $args{"result_start"} > 1
Truth table0%0/3
A and B
A= $args{"result_start"}B= $args{"result_start"} > 1
ABresult
0X0
100
111
3756  
3757 0 my @res;
3758 0 my $sth = $dbh->prepare($sql);
3759 0 $sth->execute(@bind);
3760 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
3761 0 ▶ push @res, $detail ? $row : $row->{id};
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 0 0 0
3762 }
3763 0 my $resmeta = {};
3764 0 ▶ $resmeta->{'table.fields'} = [qw/id name email/]
Branch: 1 branch
BranchTrueFalseTotal
if $detail 0 0 0
3765 if $detail;
3766 0 [200, "OK", \@res, $resmeta];
3767 }
3768  
3769 $SPEC{modules} = {
3770 v => 1.1,
3771 summary => 'List modules/packages',
3772 args => {
3773 %common_args,
3774 98 ▶ %{( modclone {
Subroutine __ANON__: called CC=1 SCAR=6.1
3775 0 ▶ $_->{query}{element_completion} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
3776 0 my %args = @_;
3777 0 my $r = $args{r};
3778 0 ▶ return undef unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 0 0
3779 0 my $cmdline = $args{cmdline};
3780 0 my $res = $cmdline->parse_argv($r);
3781 0 ▶ return undef unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
3782  
3783 # provide completion for modules if query_type is exact-name
3784 0 ▶ my $qt = $res->[2]{query_type} // '';
Condition0%0/2
$res->[2]{"query_type"} // ""
l!l
00
MC/DC0%0/1
$res->[2]{"query_type"} // ""
$res->[2]{"query_type"}
Truth table0%0/2
A
A= $res->[2]{"query_type"}
Aresult
11
00
3785 0 ▶ return _complete_mod(%args) if $qt eq 'exact-name';
Branch: 1 branch
BranchTrueFalseTotal
if $qt eq "exact-name" 0 0 0
3786  
3787 0 undef;
3788 98 };
3789 98 } \%query_multi_args )},
3790 query_type => {
3791 schema => ['str*', in=>[qw/any name exact-name regexp-name abstract/]],
3792 default => 'any',
3793 cmdline_aliases => {
3794 x => {
3795 summary => 'Shortcut --query-type exact-name',
3796 is_flag => 1,
3797 0 ▶ code => sub { $_[0]{query_type} = 'exact-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3798 },
3799 r => {
3800 summary => 'Shortcut --query-type regexp-name',
3801 is_flag => 1,
3802 0 ▶ code => sub { $_[0]{query_type} = 'regexp-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3803 },
3804 n => {
3805 summary => 'Shortcut --query-type name',
3806 is_flag => 1,
3807 0 ▶ code => sub { $_[0]{query_type} = 'name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3808 },
3809 },
3810 },
3811 98 %fauthor_args,
3812 %fdist_args,
3813 %flatest_args,
3814 %finclude_core_args,
3815 %finclude_noncore_args,
3816 %perl_version_args,
3817 %fctime_args,
3818 %fmtime_args,
3819 %fctime_or_mtime_args,
3820 namespaces => {
3821 'x.name.is_plural' => 1,
3822 summary => 'Select modules belonging to certain namespace(s)',
3823 schema => ['array*', of=>'perl::modname*'],
3824 tags => ['category:filtering'],
3825 element_completion => \&_complete_ns,
3826 cmdline_aliases => {N => {}},
3827 },
3828 %sort_args_for_mods,
3829 %paging_args,
3830 },
3831 result => {
3832 description => <<'_',
3833  
3834 By default will return an array of package names. If you set `detail` to true,
3835 will return array of records.
3836  
3837 _
3838 },
3839 };
3840 0 ▶sub modules {
Subroutine modules: not called CC=48 SCAR=77.6
Pod documented
3841 0 require Module::CoreList::More;
3842  
3843 0 my %args = @_;
3844  
3845 0 my $state = _init(\%args, 'ro');
3846 0 my $dbh = $state->{dbh};
3847  
3848 0 my $detail = $args{detail};
3849 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
3850 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
3851 0 ▶ my $sort = $args{sort} // ['module'];
Condition0%0/2
$args{"sort"} // ["module"]
l!l
00
MC/DC0%0/1
$args{"sort"} // ["module"]
$args{"sort"}
Truth table0%0/2
A
A= $args{"sort"}
Aresult
11
00
3852 0 ▶ my $include_core = $args{include_core} // 1;
Condition0%0/2
$args{"include_core"} // 1
l!l
00
MC/DC0%0/1
$args{"include_core"} // 1
$args{"include_core"}
Truth table0%0/2
A
A= $args{"include_core"}
Aresult
11
00
3853 0 ▶ my $include_noncore = $args{include_noncore} // 1;
Condition0%0/2
$args{"include_noncore"} // 1
l!l
00
MC/DC0%0/1
$args{"include_noncore"} // 1
$args{"include_noncore"}
Truth table0%0/2
A
A= $args{"include_noncore"}
Aresult
11
00
3854 0 ▶ my $plver = $args{perl_version} // "$^V";
Condition0%0/2
$args{"perl_version"} // "$^V"
l!l
00
MC/DC0%0/1
$args{"perl_version"} // "$^V"
$args{"perl_version"}
Truth table0%0/2
A
A= $args{"perl_version"}
Aresult
11
00
3855  
3856 0 my @cols = (
3857 ['module.name', 'module'],
3858 ['module.version', 'version'],
3859 ['module.abstract', 'abstract'],
3860 ['file.dist_name', 'dist'],
3861 ['file.cpanid', 'author'],
3862 ['file.mtime', 'rel_mtime', 'iso8601_datetime'],
3863 );
3864  
3865 0 my @bind;
3866 my @where;
3867 {
3868 0 my @q_where;
3869 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
3870 0 ▶ if ($qt eq 'any') {
Branch: 5 branches
BranchTrueFalseTotal
if ($qt eq 'any') { } 0 0 0
elsif ($qt eq 'name') { } 0 0 0
elsif ($qt eq 'exact-name') { } 0 0 0
elsif ($qt eq 'regexp-name') { } 0 0 0
elsif ($qt eq 'abstract') { } 0 0 0
3871 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3872 0 push @q_where, "(module.name LIKE ? OR module.abstract LIKE ? OR file.dist_name LIKE ?)";
3873 0 push @bind, $q, $q, $q;
3874 } elsif ($qt eq 'name') {
3875 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3876 0 push @q_where, "(module.name LIKE ?)";
3877 0 push @bind, $q;
3878 } elsif ($qt eq 'exact-name') {
3879 0 push @q_where, "(module.name=?)";
3880 0 push @bind, $q0;
3881 } elsif ($qt eq 'regexp-name') {
3882 0 push @q_where, "(module.name REGEXP ?)";
3883 0 push @bind, $q0;
3884 } elsif ($qt eq 'abstract') {
3885 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
3886 0 push @q_where, "(module.abstract LIKE ?)";
3887 0 push @bind, $q;
3888 }
3889 }
3890 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
3891 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
3892 } elsif (@q_where == 1) {
3893 0 push @where, @q_where;
3894 }
3895 }
3896 0 ▶ if ($author) {
Branch: 1 branch
BranchTrueFalseTotal
if ($author) 0 0 0
3897 0 push @where, "(author=?)";
3898 0 push @bind, $author;
3899 }
3900 0 ▶ if ($args{dist}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"dist"}) 0 0 0
3901 0 push @where, "(dist=?)";
3902 0 push @bind, $args{dist};
3903 }
3904 0 ▶ if ($args{namespaces} && @{ $args{namespaces} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"namespaces"} and @{$args{"namespaces"};}) 0 0 0
Condition0%0/3
$args{"namespaces"} and @{$args{"namespaces"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"namespaces"} and @{$args{"namespaces"};}
$args{"namespaces"} @{$args{"namespaces"};}
Truth table0%0/3
A and B
A= $args{"namespaces"}B= @{$args{"namespaces"};}
ABresult
0X0
100
111
3905 0 my @ns_where;
3906 0 for my $ns (@{ $args{namespaces} }) {
3907 0 ▶ return [400, "Invalid namespace '$ns', please use Word or Word(::Sub)+"]
Branch: 1 branch
BranchTrueFalseTotal
unless $ns =~ /\A\w+(::\w+)*\z/ 0 0 0
3908 unless $ns =~ /\A\w+(::\w+)*\z/;
3909 0 push @ns_where, "(module.name='$ns' OR module.name LIKE '$ns\::%')";
3910 }
3911 0 push @where, "(".join(" OR ", @ns_where).")";
3912 }
3913 0 ▶ if ($args{latest}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'latest'}) { } 0 0 0
elsif (defined $args{'latest'}) { } 0 0 0
3914 0 push @where, "file.is_latest_dist";
3915 } elsif (defined $args{latest}) {
3916 0 push @where, "NOT file.is_latest_dist";
3917 }
3918  
3919 0 _set_since(\%args, $dbh);
3920 0 _add_since_where_clause(\%args, \@where, 'module');
3921  
3922 0 my @order;
3923 0 ▶ if ($args{random}) { push @order, "RANDOM()" }
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"random"}) 0 0 0
3924 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
3925  
3926 0 ▶ my $sql = "SELECT ".join(", ", map {ref($_) ? "$_->[0] AS $_->[1]" : $_} @cols)."
Branch: 5 branches
BranchTrueFalseTotal
ref $_ ? : 0 0 0
@where ? : 0 0 0
@order ? : 0 0 0
$args{'result_limit'} ? : 0 0 0
$args{'result_start'} && $args{'result_start'} > 1 ? : 0 0 0
Condition0%0/3
$args{"result_start"} and $args{"result_start"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"result_start"} and $args{"result_start"} > 1
$args{"result_start"} $args{"result_start"} > 1
Truth table0%0/3
A and B
A= $args{"result_start"}B= $args{"result_start"} > 1
ABresult
0X0
100
111
3927 FROM module
3928 LEFT JOIN file ON module.file_id=file.id
3929 ".
3930 (@where ? " WHERE ".join(" AND ", @where) : "").
3931 (@order ? " ORDER BY ".join(", ", @order) : "").
3932 0 ($args{result_limit} ? " LIMIT ".($args{result_start} && $args{result_start} > 1 ? ($args{result_start}-1)."," : "").($args{result_limit}+0) : "");
3933  
3934 0 my @res;
3935 0 my $sth = $dbh->prepare($sql);
3936 0 $sth->execute(@bind);
3937 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
3938 $row->{is_core} = $row->{module} eq 'perl' ||
3939 Module::CoreList::More->is_still_core(
3940 $row->{module}, undef,
3941 0 ▶ version->parse($plver)->numify);
Condition0%0/3
$row->{'module'} eq 'perl' || 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
l!l&&r!l&&!r
000
MC/DC0%0/2
$row->{'module'} eq 'perl' || 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
$row->{'module'} eq 'perl' 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
Truth table0%0/3
A || B
A= $row->{'module'} eq 'perl'B= 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
ABresult
1X1
011
000
3942 0 ▶ next if !$include_core && $row->{is_core};
Branch: 1 branch
BranchTrueFalseTotal
if not $include_core and $row->{"is_core"} 0 0 0
Condition0%0/3
not $include_core and $row->{"is_core"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $include_core and $row->{"is_core"}
not $include_core $row->{"is_core"}
Truth table0%0/3
not(A) and B
A= not $include_coreB= $row->{"is_core"}
ABresult
0X0
100
111
3943 0 ▶ next if !$include_noncore && !$row->{is_core};
Branch: 1 branch
BranchTrueFalseTotal
unless $include_noncore or $row->{"is_core"} 0 0 0
Condition0%0/3
$include_noncore or $row->{"is_core"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$include_noncore or $row->{"is_core"}
$include_noncore $row->{"is_core"}
Truth table0%0/3
A or B
A= $include_noncoreB= $row->{"is_core"}
ABresult
1X1
011
000
3944 0 ▶ push @res, $detail ? $row : $row->{module};
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 0 0 0
3945 }
3946 0 my $resmeta = {};
3947 0 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) 0 0 0
3948 $resmeta->{'table.fields'} = [
3949 0 ▶ (map {ref($_) ? $_->[1] : $_} @cols),
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
3950 ("is_core")];
3951 $resmeta->{'table.field_formats'} = [
3952 0 ▶ (map {ref($_) ? $_->[2] : undef} @cols),
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
3953 (undef)];
3954 }
3955 0 [200, "OK", \@res, $resmeta];
3956 }
3957  
3958 98 $SPEC{packages} = $SPEC{modules};
3959 0 ▶sub packages { goto &modules }
Subroutine packages: not called CC=1 SCAR=6.9
Pod documented
3960  
3961 $SPEC{dists} = {
3962 v => 1.1,
3963 summary => 'List distributions',
3964 args => {
3965 %common_args,
3966 98 ▶ %{( modclone {
Subroutine __ANON__: called CC=1 SCAR=6.1
3967 0 ▶ $_->{query}{element_completion} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
3968 0 my %args = @_;
3969 0 my $r = $args{r};
3970 0 ▶ return undef unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 0 0
3971 0 my $cmdline = $args{cmdline};
3972 0 my $res = $cmdline->parse_argv($r);
3973 0 ▶ return undef unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
3974  
3975 # provide completion for dists if query_type is exact-name
3976 0 ▶ my $qt = $res->[2]{query_type} // '';
Condition0%0/2
$res->[2]{"query_type"} // ""
l!l
00
MC/DC0%0/1
$res->[2]{"query_type"} // ""
$res->[2]{"query_type"}
Truth table0%0/2
A
A= $res->[2]{"query_type"}
Aresult
11
00
3977 0 ▶ return _complete_dist(%args) if $qt eq 'exact-name';
Branch: 1 branch
BranchTrueFalseTotal
if $qt eq "exact-name" 0 0 0
3978  
3979 0 undef;
3980 98 };
3981 98 } \%query_multi_args )},
3982 query_type => {
3983 schema => ['str*', in=>[qw/any name exact-name regexp-name abstract/]],
3984 default => 'any',
3985 cmdline_aliases => {
3986 x => {
3987 summary => 'Shortcut for --query-type exact-name',
3988 is_flag => 1,
3989 0 ▶ code => sub { $_[0]{query_type} = 'exact-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3990 },
3991 r => {
3992 summary => 'Shortcut for --query-type regexp-name',
3993 is_flag => 1,
3994 0 ▶ code => sub { $_[0]{query_type} = 'regexp-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3995 },
3996 n => {
3997 summary => 'Shortcut for --query-type name',
3998 is_flag => 1,
3999 0 ▶ code => sub { $_[0]{query_type} = 'name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4000 },
4001 },
4002 },
4003 98 %fauthor_args,
4004 %flatest_args,
4005 %fctime_args,
4006 %fmtime_args,
4007 %fctime_or_mtime_args,
4008 has_makefilepl => {
4009 schema => 'bool',
4010 tags => ['category:filtering'],
4011 },
4012 has_buildpl => {
4013 schema => 'bool',
4014 tags => ['category:filtering'],
4015 },
4016 has_metayml => {
4017 schema => 'bool',
4018 tags => ['category:filtering'],
4019 },
4020 has_metajson => {
4021 schema => 'bool',
4022 tags => ['category:filtering'],
4023 },
4024 has_multiple_rels => {
4025 'summary.alt.bool.yes' => 'Only list dists having multiple releases indexed',
4026 'summary.alt.bool.not' => 'Only list dists having a single release indexed',
4027 schema => 'bool',
4028 tags => ['category:filtering'],
4029 },
4030 rel_mtime_newer_than => {
4031 schema => ['date*', 'x.perl.coerce_rules' => ['From_str::natural']],
4032 tags => ['category:filtering'],
4033 },
4034 %sort_args_for_dists,
4035 %paging_args,
4036 },
4037 result => {
4038 description => <<'_',
4039  
4040 By default will return an array of distribution names. If you set `detail` to
4041 true, will return array of records.
4042  
4043 _
4044 },
4045 args_rels => {
4046 choose_one => [qw/latest has_multiple_rels/],
4047 },
4048 examples => [
4049 {
4050 summary => 'List all distributions',
4051 argv => ['--cpan', '/cpan'],
4052 test => 0,
4053 'x.doc.show_result' => 0,
4054 },
4055 {
4056 summary => 'List all distributions (latest version only)',
4057 argv => ['--cpan', '/cpan', '--latest'],
4058 test => 0,
4059 'x.doc.show_result' => 0,
4060 },
4061 {
4062 summary => 'Grep by distribution name, return detailed record',
4063 argv => ['--cpan', '/cpan', 'data-table'],
4064 test => 0,
4065 'x.doc.show_result' => 0,
4066 },
4067 {
4068 summary => 'Filter by author, return JSON',
4069 src => '[[prog]] --cpan /cpan --author perlancar --json',
4070 src_plang => 'bash',
4071 test => 0,
4072 'x.doc.show_result' => 0,
4073 },
4074 ],
4075 };
4076 0 ▶sub dists {
Subroutine dists: not called CC=44 SCAR=75.9
Pod documented
4077 0 my %args = @_;
4078  
4079 0 my $state = _init(\%args, 'ro');
4080 0 my $dbh = $state->{dbh};
4081  
4082 0 my $detail = $args{detail};
4083 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
4084 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
4085 0 ▶ my $sort = $args{sort} // ['dist'];
Condition0%0/2
$args{"sort"} // ["dist"]
l!l
00
MC/DC0%0/1
$args{"sort"} // ["dist"]
$args{"sort"}
Truth table0%0/2
A
A= $args{"sort"}
Aresult
11
00
4086  
4087 0 my @cols = (
4088 "f.dist_name dist",
4089 "f.cpanid author",
4090 "f.dist_version version",
4091 "f.name release",
4092 "f.size rel_size",
4093 "f.mtime rel_mtime",
4094 "f.dist_abstract abstract",
4095 );
4096  
4097 0 my %delcols;
4098 my @bind;
4099 0 my @where;
4100 #my @having;
4101 {
4102 0 my @q_where;
4103 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
4104 0 ▶ if ($qt eq 'any') {
Branch: 5 branches
BranchTrueFalseTotal
if ($qt eq 'any') { } 0 0 0
elsif ($qt eq 'name') { } 0 0 0
elsif ($qt eq 'exact-name') { } 0 0 0
elsif ($qt eq 'regexp-name') { } 0 0 0
elsif ($qt eq 'abstract') { } 0 0 0
4105 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
4106 0 push @q_where, "(f.dist_name LIKE ? OR f.dist_abstract LIKE ?)";
4107 0 push @bind, $q, $q;
4108 } elsif ($qt eq 'name') {
4109 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
4110 0 push @q_where, "(f.dist_name LIKE ?)";
4111 0 push @bind, $q;
4112 } elsif ($qt eq 'exact-name') {
4113 0 push @q_where, "(f.dist_name=?)";
4114 0 push @bind, $q0;
4115 } elsif ($qt eq 'regexp-name') {
4116 0 push @q_where, "(f.dist_name REGEXP ?)";
4117 0 push @bind, $q0;
4118 } elsif ($qt eq 'abstract') {
4119 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
4120 0 push @q_where, "(f.dist_abstract LIKE ?)";
4121 0 push @bind, $q;
4122 }
4123 }
4124 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
4125 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
4126 } elsif (@q_where == 1) {
4127 0 push @where, @q_where;
4128 }
4129 }
4130 0 ▶ if ($author) {
Branch: 1 branch
BranchTrueFalseTotal
if ($author) 0 0 0
4131 0 push @where, "(author=?)";
4132 0 push @bind, $author;
4133 }
4134 0 ▶ if ($args{latest}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'latest'}) { } 0 0 0
elsif (defined $args{'latest'}) { } 0 0 0
4135 0 push @where, "is_latest_dist";
4136 } elsif (defined $args{latest}) {
4137 0 push @where, "NOT(is_latest_dist)";
4138 }
4139 0 ▶ if (defined $args{has_makefilepl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_makefilepl"}) 0 0 0
4140 0 ▶ if ($args{has_makefilepl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'has_makefilepl'}) { } 0 0 0
4141 0 push @where, "has_makefilepl<>0";
4142 } else {
4143 0 push @where, "has_makefilepl=0";
4144 }
4145 }
4146 0 ▶ if (defined $args{has_buildpl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_buildpl"}) 0 0 0
4147 0 ▶ if ($args{has_buildpl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'has_buildpl'}) { } 0 0 0
4148 0 push @where, "has_buildpl<>0";
4149 } else {
4150 0 push @where, "has_buildpl=0";
4151 }
4152 }
4153 0 ▶ if (defined $args{has_metayml}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_metayml"}) 0 0 0
4154 0 ▶ if ($args{has_metayml}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'has_metayml'}) { } 0 0 0
4155 0 push @where, "has_metayml<>0";
4156 } else {
4157 0 push @where, "has_metayml=0";
4158 }
4159 }
4160 0 ▶ if (defined $args{has_metajson}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_metajson"}) 0 0 0
4161 0 ▶ if ($args{has_metajson}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'has_metajson'}) { } 0 0 0
4162 0 push @where, "has_metajson<>0";
4163 } else {
4164 0 push @where, "has_metajson=0";
4165 }
4166 }
4167 0 ▶ if (defined $args{has_multiple_rels}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_multiple_rels"}) 0 0 0
4168 0 push @cols, "(SELECT COUNT(*) FROM file f2 WHERE f2.dist_name=f.dist_name) rel_count";
4169 0 ▶ if ($args{has_multiple_rels}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'has_multiple_rels'}) { } 0 0 0
4170 0 push @where, "rel_count > 1";
4171 } else {
4172 0 push @where, "rel_count = 1";
4173 }
4174 0 $delcols{rel_count}++;
4175 }
4176 0 ▶ if (defined $args{rel_mtime_newer_than}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"rel_mtime_newer_than"}) 0 0 0
4177 0 push @where, "f.mtime > ?";
4178 0 push @bind, $args{rel_mtime_newer_than};
4179 }
4180  
4181 0 _set_since(\%args, $dbh);
4182 0 _add_since_where_clause(\%args, \@where, 'f');
4183  
4184 0 my @order;
4185 0 ▶ if ($args{random}) { push @order, "RANDOM()" }
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"random"}) 0 0 0
4186 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
4187  
4188 my $sql = "SELECT ".join(", ", @cols)."
4189 FROM file f
4190 ".
4191 (@where ? " WHERE ".join(" AND ", @where) : "").
4192 (@order ? " ORDER BY ".join(", ", @order) : "").
4193 0 ▶ ($args{result_limit} ? " LIMIT ".($args{result_start} && $args{result_start} > 1 ? ($args{result_start}-1)."," : "").($args{result_limit}+0) : "");
Branch: 4 branches
BranchTrueFalseTotal
@where ? : 0 0 0
@order ? : 0 0 0
$args{'result_limit'} ? : 0 0 0
$args{'result_start'} && $args{'result_start'} > 1 ? : 0 0 0
Condition0%0/3
$args{"result_start"} and $args{"result_start"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"result_start"} and $args{"result_start"} > 1
$args{"result_start"} $args{"result_start"} > 1
Truth table0%0/3
A and B
A= $args{"result_start"}B= $args{"result_start"} > 1
ABresult
0X0
100
111
4194  
4195 0 my @res;
4196 0 my $sth = $dbh->prepare($sql);
4197 0 $sth->execute(@bind);
4198 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
4199 0 delete $row->{$_} for keys %delcols;
4200 0 ▶ push @res, $detail ? $row : $row->{dist};
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 0 0 0
4201 }
4202 0 my $resmeta = {};
4203 0 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) 0 0 0
4204 0 $resmeta->{'table.fields'} = [qw/dist author version release rel_size rel_mtime abstract/];
4205 0 $resmeta->{'table.field_formats'} = [undef, undef, undef, undef, undef, 'iso8601_datetime', undef];
4206 }
4207 0 [200, "OK", \@res, $resmeta];
4208 }
4209  
4210 $SPEC{'releases'} = {
4211 v => 1.1,
4212 summary => 'List releases/tarballs',
4213 args => {
4214 %common_args,
4215 %fauthor_args,
4216 98 ▶ %{( modclone {
Subroutine __ANON__: called CC=1 SCAR=6.1
4217 0 ▶ $_->{query}{element_completion} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
4218 0 my %args = @_;
4219 0 my $r = $args{r};
4220 0 ▶ return undef unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 0 0
4221 0 my $cmdline = $args{cmdline};
4222 0 my $res = $cmdline->parse_argv($r);
4223 0 ▶ return undef unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
4224  
4225 # provide completion for releases if query_type is exact-name
4226 0 ▶ my $qt = $res->[2]{query_type} // '';
Condition0%0/2
$res->[2]{"query_type"} // ""
l!l
00
MC/DC0%0/1
$res->[2]{"query_type"} // ""
$res->[2]{"query_type"}
Truth table0%0/2
A
A= $res->[2]{"query_type"}
Aresult
11
00
4227 0 ▶ return _complete_rel(%args) if $qt eq 'exact-name';
Branch: 1 branch
BranchTrueFalseTotal
if $qt eq "exact-name" 0 0 0
4228  
4229 0 undef;
4230 98 };
4231 98 } \%query_multi_args )},
4232 query_type => {
4233 schema => ['str*', in=>[qw/any name exact-name regexp-name/]],
4234 default => 'any',
4235 cmdline_aliases => {
4236 x => {
4237 summary => 'Shortcut for --query-type exact-name',
4238 is_flag => 1,
4239 0 ▶ code => sub { $_[0]{query_type} = 'exact-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4240 },
4241 r => {
4242 summary => 'Shortcut for --query-type regexp-name',
4243 is_flag => 1,
4244 0 ▶ code => sub { $_[0]{query_type} = 'regexp-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4245 },
4246 n => {
4247 summary => 'Shortcut for --query-type name',
4248 is_flag => 1,
4249 0 ▶ code => sub { $_[0]{query_type} = 'name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4250 },
4251 },
4252 },
4253 98 has_metajson => {schema=>'bool'},
4254 has_metayml => {schema=>'bool'},
4255 has_makefilepl => {schema=>'bool'},
4256 has_buildpl => {schema=>'bool'},
4257 %flatest_args,
4258 %fctime_args,
4259 %fmtime_args,
4260 %fctime_or_mtime_args,
4261 %full_path_args,
4262 %no_path_args,
4263 %sort_args_for_rels,
4264 %paging_args,
4265 },
4266 args_rels => {
4267 choose_one => ['full_path', 'no_path'],
4268 },
4269 description => <<'_',
4270  
4271 The status field is the processing status of the file/release by lcpan. `ok`
4272 means file has been extracted and the meta files parsed, `nofile` means file is
4273 not found in mirror (possibly because the mirroring process excludes the file
4274 e.g. due to file size too large), `nometa` means file does not contain
4275 META.{yml,json}, `unsupported` means file archive format is not supported (e.g.
4276 rar), `err` means some other error in processing file.
4277  
4278 _
4279 };
4280 0 ▶sub releases {
Subroutine releases: not called CC=41 SCAR=74.5
Pod documented
4281 0 my %args = @_;
4282  
4283 0 my $state = _init(\%args, 'ro');
4284 0 my $dbh = $state->{dbh};
4285  
4286 0 my $detail = $args{detail};
4287 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
4288 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
4289 0 ▶ my $sort = $args{sort} // ['name'];
Condition0%0/2
$args{"sort"} // ["name"]
l!l
00
MC/DC0%0/1
$args{"sort"} // ["name"]
$args{"sort"}
Truth table0%0/2
A
A= $args{"sort"}
Aresult
11
00
4290  
4291 0 my @bind;
4292 my @where;
4293 {
4294 0 my @q_where;
4295 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
4296 0 ▶ if ($qt eq 'any' || $qt eq 'name') {
Branch: 3 branches
BranchTrueFalseTotal
if ($qt eq 'any' or $qt eq 'name') { } 0 0 0
elsif ($qt eq 'exact-name') { } 0 0 0
elsif ($qt eq 'regexp-name') { } 0 0 0
Condition0%0/3
$qt eq "any" or $qt eq "name"
l!l&&r!l&&!r
000
MC/DC0%0/2
$qt eq "any" or $qt eq "name"
$qt eq "any" $qt eq "name"
Truth table0%0/3
A or B
A= $qt eq "any"B= $qt eq "name"
ABresult
1X1
011
000
4297 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
4298 0 push @q_where, "(f1.name LIKE ?)";
4299 0 push @bind, $q;
4300 } elsif ($qt eq 'exact-name') {
4301 0 push @q_where, "(f1.name=?)";
4302 0 push @bind, $q0;
4303 } elsif ($qt eq 'regexp-name') {
4304 0 push @q_where, "(f1.name REGEXP ?)";
4305 0 push @bind, $q0;
4306 }
4307 }
4308 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
4309 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
4310 } elsif (@q_where == 1) {
4311 0 push @where, @q_where;
4312 }
4313 }
4314 0 ▶ if ($author) {
Branch: 1 branch
BranchTrueFalseTotal
if ($author) 0 0 0
4315 0 push @where, "(f1.cpanid=?)";
4316 0 push @bind, $author;
4317 }
4318 0 ▶ if (defined $args{has_metajson}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_metajson"}) 0 0 0
4319 0 ▶ push @where, $args{has_metajson} ? "(has_metajson=1)" : "(has_metajson=0)";
Branch: 1 branch
BranchTrueFalseTotal
$args{'has_metajson'} ? : 0 0 0
4320 }
4321 0 ▶ if (defined $args{has_metayml}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_metayml"}) 0 0 0
4322 0 ▶ push @where, $args{has_metayml} ? "(has_metayml=1)" : "(has_metayml=0)";
Branch: 1 branch
BranchTrueFalseTotal
$args{'has_metayml'} ? : 0 0 0
4323 }
4324 0 ▶ if (defined $args{has_makefilepl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_makefilepl"}) 0 0 0
4325 0 ▶ push @where, $args{has_makefilepl} ? "(has_makefilepl=1)" : "(has_makefilepl=0)";
Branch: 1 branch
BranchTrueFalseTotal
$args{'has_makefilepl'} ? : 0 0 0
4326 }
4327 0 ▶ if (defined $args{has_buildpl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"has_buildpl"}) 0 0 0
4328 0 ▶ push @where, $args{has_buildpl} ? "(has_buildpl=1)" : "(has_buildpl=0)";
Branch: 1 branch
BranchTrueFalseTotal
$args{'has_buildpl'} ? : 0 0 0
4329 }
4330 0 ▶ if ($args{latest}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'latest'}) { } 0 0 0
elsif (defined $args{'latest'}) { } 0 0 0
4331 0 push @where, "d.is_latest";
4332 } elsif (defined $args{latest}) {
4333 0 push @where, "NOT(d.is_latest)";
4334 }
4335  
4336 0 _set_since(\%args, $dbh);
4337 0 _add_since_where_clause(\%args, \@where, 'f1');
4338  
4339 0 my @order;
4340 0 ▶ if ($args{random}) { push @order, "RANDOM()" }
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"random"}) 0 0 0
4341 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
4342  
4343 my $sql = "SELECT
4344 f1.name name,
4345 f1.cpanid author,
4346 f1.size size,
4347 f1.mtime mtime,
4348 has_metajson,
4349 has_metayml,
4350 has_makefilepl,
4351 has_buildpl,
4352 file_status,
4353 file_error,
4354 meta_status,
4355 meta_error,
4356 pod_status
4357 FROM file f1
4358 ".
4359 (@where ? " WHERE ".join(" AND ", @where) : "").
4360 (@order ? " ORDER BY ".join(", ", @order) : "").
4361 0 ▶ ($args{result_limit} ? " LIMIT ".($args{result_start} && $args{result_start} > 1 ? ($args{result_start}-1)."," : "").($args{result_limit}+0) : "");
Branch: 4 branches
BranchTrueFalseTotal
@where ? : 0 0 0
@order ? : 0 0 0
$args{'result_limit'} ? : 0 0 0
$args{'result_start'} && $args{'result_start'} > 1 ? : 0 0 0
Condition0%0/3
$args{"result_start"} and $args{"result_start"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"result_start"} and $args{"result_start"} > 1
$args{"result_start"} $args{"result_start"} > 1
Truth table0%0/3
A and B
A= $args{"result_start"}B= $args{"result_start"} > 1
ABresult
0X0
100
111
4362  
4363 0 my @res;
4364 0 my $sth = $dbh->prepare($sql);
4365 0 $sth->execute(@bind);
4366 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
4367 0 ▶ if ($args{no_path}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'no_path'}) { } 0 0 0
elsif ($args{'full_path'}) { } 0 0 0
4368 } elsif ($args{full_path}) {
4369 0 $row->{name} = _fullpath($row->{name}, $state->{cpan}, $row->{author});
4370 } else {
4371 0 $row->{name} = _relpath($row->{name}, $row->{author});
4372 }
4373 0 for (qw/file_error meta_error/) {
4374 0 ▶ $row->{$_} =~ s/\R+/ /g if defined $row->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $row->{$_} 0 0 0
4375 }
4376 0 ▶ push @res, $detail ? $row : $row->{name};
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 0 0 0
4377 }
4378 0 my $resmeta = {};
4379 0 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) 0 0 0
4380 0 $resmeta->{'table.fields'} = [qw/name author size mtime has_metayml has_metajson has_makefilepl has_buildpl file_status file_error meta_status meta_error pod_status/];
4381 0 $resmeta->{'table.field_formats'} = [undef, undef, undef, 'iso8601_datetime', undef, undef, undef, undef, undef, undef, undef, undef, undef];
4382 }
4383 0 [200, "OK", \@res, $resmeta];
4384 }
4385  
4386 0 ▶sub _get_prereqs {
Subroutine _get_prereqs: not called CC=52 SCAR=79.2
4387 0 require Module::CoreList::More;
4388 0 require Version::Util;
4389  
4390 0 my ($file_ids0, $dbh, $memory_by_mod_name, $memory_by_file_id,
4391 $level, $max_level, $filters, $plver, $flatten, $dont_uniquify, $phase, $rel) = @_;
4392  
4393 0 my $file_ids = [];
4394  
4395 0 for my $file_id (@$file_ids0) {
4396 0 ▶ unless ($memory_by_file_id->{$file_id} && $dont_uniquify) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($memory_by_file_id->{$file_id} and $dont_uniquify) 0 0 0
Condition0%0/3
$memory_by_file_id->{$file_id} and $dont_uniquify
!ll&&!rl&&r
000
MC/DC0%0/2
$memory_by_file_id->{$file_id} and $dont_uniquify
$memory_by_file_id->{$file_id} $dont_uniquify
Truth table0%0/3
A and B
A= $memory_by_file_id->{$file_id}B= $dont_uniquify
ABresult
0X0
100
111
4397 0 push @$file_ids, $file_id;
4398 0 $memory_by_file_id->{$file_id} = 1;
4399 }
4400 }
4401  
4402 0 log_trace("Finding dependencies for file ID(s) %s (level=%i) ...", $file_ids, $level);
4403 0 ▶ return [200, "OK", []] unless @$file_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @$file_ids 0 0 0
4404  
4405 0 my @where = ("dp.file_id IN (".join(",", @$file_ids).")");
4406 0 my @bind = ();
4407  
4408 0 ▶ if ($filters->{authors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"authors"}) 0 0 0
4409 0 push @where, '('.join(' OR ', ('author=?') x @{$filters->{authors}}).')';
4410 0 push @bind , @{$filters->{authors}};
4411 }
4412 0 ▶ if ($filters->{authors_arent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"authors_arent"}) 0 0 0
4413 0 for (@{ $filters->{authors_arent} }) {
4414 0 push @where, 'author <> ?';
4415 0 push @bind , $_;
4416 }
4417 }
4418  
4419 0 _add_since_where_clause($filters, \@where, 'dp');
4420  
4421 # fetch the dependency information
4422 0 ▶ my $sth = $dbh->prepare("SELECT
Branch: 1 branch
BranchTrueFalseTotal
$level > 1 ? : 0 0 0
4423 (SELECT dist_name FROM file WHERE id=dp.file_id) AS dist,
4424 CASE
4425 WHEN module_name IS NOT NULL THEN module_name
4426 ELSE (SELECT name FROM module WHERE id=dp.module_id)
4427 END AS module,
4428 (SELECT cpanid FROM module WHERE id=dp.module_id) AS author,
4429 (SELECT dist_name FROM file WHERE id=(SELECT file_id FROM module WHERE id=dp.module_id)) AS module_dist,
4430 (SELECT file_id FROM module WHERE id=dp.module_id) AS module_file_id,
4431 phase,
4432 rel,
4433 version
4434 FROM dep dp
4435 WHERE ".join(" AND ", @where)."
4436 ORDER BY module".($level > 1 ? " DESC" : ""));
4437 0 $sth->execute(@bind);
4438 0 my @res;
4439 MOD:
4440 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
4441 # BUG? we can encounter case where module is undef
4442 0 ▶ next unless defined $row->{module};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row->{"module"} 0 0 0
4443  
4444 0 ▶ next unless $phase eq 'ALL' || $row->{phase} eq $phase;
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "ALL" or $row->{"phase"} eq $phase 0 0 0
Condition0%0/3
$phase eq "ALL" or $row->{"phase"} eq $phase
l!l&&r!l&&!r
000
MC/DC0%0/2
$phase eq "ALL" or $row->{"phase"} eq $phase
$phase eq "ALL" $row->{"phase"} eq $phase
Truth table0%0/3
A or B
A= $phase eq "ALL"B= $row->{"phase"} eq $phase
ABresult
1X1
011
000
4445 0 ▶ next unless $rel eq 'ALL' || $row->{rel} eq $rel;
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "ALL" or $row->{"rel"} eq $rel 0 0 0
Condition0%0/3
$rel eq "ALL" or $row->{"rel"} eq $rel
l!l&&r!l&&!r
000
MC/DC0%0/2
$rel eq "ALL" or $row->{"rel"} eq $rel
$rel eq "ALL" $row->{"rel"} eq $rel
Truth table0%0/3
A or B
A= $rel eq "ALL"B= $row->{"rel"} eq $rel
ABresult
1X1
011
000
4446  
4447 # some dists, e.g. XML-SimpleObject-LibXML (0.60) have garbled prereqs,
4448 # e.g. they write PREREQ_PM => { mod1, mod2 } when it should've been
4449 # PREREQ_PM => {mod1 => 0, mod2=>1.23}. we ignore such deps.
4450 0 ▶ unless (eval { version->parse($row->{version}); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { "version"->parse($row->{"version"}); 1 } }) 0 0 0
4451 0 log_info("Invalid version $row->{version} (in dependency to $row->{module}), skipped");
4452 0 next;
4453 }
4454  
4455 0 ▶ if (!$dont_uniquify && (
Branch: 1 branch
BranchTrueFalseTotal
if (not $dont_uniquify and exists $$memory_by_mod_name{$row->{"module"}} || $level > 1 && defined $row->{"module_dist"} && exists $$memory_by_file_id{$row->{"module_file_id"}}) 0 0 0
Condition0%0/12
not $dont_uniquify and exists $$memory_by_mod_name{$row->{"module"}} || $level > 1 && defined $row->{"module_dist"} && exists $$memory_by_file_id{$row->{"module_file_id"}}
!ll&&!rl&&r
000
exists $$memory_by_mod_name{$row->{"module"}} or $level > 1 and defined $row->{"module_dist"} and exists $$memory_by_file_id{$row->{"module_file_id"}}
l!l&&r!l&&!r
000
$level > 1 and defined $row->{"module_dist"} and exists $$memory_by_file_id{$row->{"module_file_id"}}
!ll&&!rl&&r
000
$level > 1 and defined $row->{"module_dist"}
!ll&&!rl&&r
000
MC/DC0%0/5
not $dont_uniquify and exists $$memory_by_mod_name{$row->{"module"}} || $level > 1 && defined $row->{"module_dist"} && exists $$memory_by_file_id{$row->{"module_file_id"}}
not $dont_uniquify exists $$memory_by_mod_name{$row->{"module"}} $level > 1 defined $row->{"module_dist"} exists $$memory_by_file_id{$row->{"module_file_id"}}
Truth table0%0/6
not(A) and B or C and D and E
A= not $dont_uniquifyB= exists $$memory_by_mod_name{$row->{"module"}}C= $level > 1D= defined $row->{"module_dist"}E= exists $$memory_by_file_id{$row->{"module_file_id"}}
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
4456 (exists $memory_by_mod_name->{$row->{module}}) ||
4457 ($level > 1 && defined $row->{module_dist} && exists $memory_by_file_id->{$row->{module_file_id}})
4458 )
4459 ) {
4460 0 ▶ if ($flatten) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flatten) { } 0 0 0
4461 $memory_by_mod_name->{$row->{module}} = $row->{version}
4462 0 ▶ if version->parse($row->{version}) > version->parse($memory_by_mod_name->{$row->{module}});
Branch: 1 branch
BranchTrueFalseTotal
if "version"->parse($row->{"version"}) > "version"->parse($$memory_by_mod_name{$row->{"module"}}) 0 0 0
4463 } else {
4464 0 next MOD;
4465 }
4466 }
4467  
4468 0 ▶ next if !$filters->{include_indexed} && ( defined $row->{author} || $row->{module} eq 'perl');
Branch: 1 branch
BranchTrueFalseTotal
if not $filters->{"include_indexed"} and defined $row->{"author"} || $row->{"module"} eq "perl" 0 0 0
Condition0%0/6
not $filters->{"include_indexed"} and defined $row->{"author"} || $row->{"module"} eq "perl"
!ll&&!rl&&r
000
defined $row->{"author"} or $row->{"module"} eq "perl"
l!l&&r!l&&!r
000
MC/DC0%0/3
not $filters->{"include_indexed"} and defined $row->{"author"} || $row->{"module"} eq "perl"
not $filters->{"include_indexed"} defined $row->{"author"} $row->{"module"} eq "perl"
Truth table0%0/4
not(A) and B or C
A= not $filters->{"include_indexed"}B= defined $row->{"author"}C= $row->{"module"} eq "perl"
ABCresult
0XX0
1000
11X1
1011
4469 0 ▶ next if !$filters->{include_unindexed} && (!defined $row->{author} && $row->{module} ne 'perl');
Branch: 1 branch
BranchTrueFalseTotal
if not $filters->{"include_unindexed"} and (not defined $row->{"author"} and $row->{"module"} ne "perl") 0 0 0
Condition0%0/6
not $filters->{"include_unindexed"} and (not defined $row->{"author"} and $row->{"module"} ne "perl")
!ll&&!rl&&r
000
not defined $row->{"author"} and $row->{"module"} ne "perl"
!ll&&!rl&&r
000
MC/DC0%0/3
not $filters->{"include_unindexed"} and (not defined $row->{"author"} and $row->{"module"} ne "perl")
not $filters->{"include_unindexed"} not defined $row->{"author"} $row->{"module"} ne "perl"
Truth table0%0/4
not(A) and not(B) and C
A= not $filters->{"include_unindexed"}B= not defined $row->{"author"}C= $row->{"module"} ne "perl"
ABCresult
0XX0
10X0
1100
1111
4470  
4471 0 ▶ if ($filters->{exclude_deps} && grep { $row->{module} eq $_ } @{ $filters->{exclude_deps} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"exclude_deps"} and grep {$row->{"module"} eq $_;} @{$$filters{"exclude_deps"};}) 0 0 0
Condition0%0/3
$filters->{"exclude_deps"} and grep {$row->{"module"} eq $_;} @{$$filters{"exclude_deps"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$filters->{"exclude_deps"} and grep {$row->{"module"} eq $_;} @{$$filters{"exclude_deps"};}
$filters->{"exclude_deps"} grep {$row->{"module"} eq $_;} @{$$filters{"exclude_deps"};}
Truth table0%0/3
A and B
A= $filters->{"exclude_deps"}B= grep {$row->{"module"} eq $_;} @{$$filters{"exclude_deps"};}
ABresult
0X0
100
111
4472 0 next;
4473 }
4474  
4475 $row->{is_core} = $row->{module} eq 'perl' ||
4476 0 ▶ Module::CoreList::More->is_still_core($row->{module}, undef, version->parse($plver)->numify);
Condition0%0/3
$row->{'module'} eq 'perl' || 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
l!l&&r!l&&!r
000
MC/DC0%0/2
$row->{'module'} eq 'perl' || 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
$row->{'module'} eq 'perl' 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
Truth table0%0/3
A || B
A= $row->{'module'} eq 'perl'B= 'Module::CoreList::More'->is_still_core($row->{'module'}, undef, 'version'->parse($plver)->numify)
ABresult
1X1
011
000
4477 0 ▶ next if !$filters->{include_core} && $row->{is_core};
Branch: 1 branch
BranchTrueFalseTotal
if not $filters->{"include_core"} and $row->{"is_core"} 0 0 0
Condition0%0/3
not $filters->{"include_core"} and $row->{"is_core"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $filters->{"include_core"} and $row->{"is_core"}
not $filters->{"include_core"} $row->{"is_core"}
Truth table0%0/3
not(A) and B
A= not $filters->{"include_core"}B= $row->{"is_core"}
ABresult
0X0
100
111
4478 0 ▶ next if !$filters->{include_noncore} && !$row->{is_core};
Branch: 1 branch
BranchTrueFalseTotal
unless $filters->{"include_noncore"} or $row->{"is_core"} 0 0 0
Condition0%0/3
$filters->{"include_noncore"} or $row->{"is_core"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$filters->{"include_noncore"} or $row->{"is_core"}
$filters->{"include_noncore"} $row->{"is_core"}
Truth table0%0/3
A or B
A= $filters->{"include_noncore"}B= $row->{"is_core"}
ABresult
1X1
011
000
4479 0 ▶ if (defined $memory_by_mod_name->{$row->{module}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$memory_by_mod_name{$row->{"module"}}) 0 0 0
4480 0 ▶ if (Version::Util::version_gt($row->{version}, $memory_by_mod_name->{$row->{module}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (Version::Util::version_gt($row->{"version"}, $$memory_by_mod_name{$row->{"module"}})) 0 0 0
4481 0 $memory_by_mod_name->{$row->{module}} = $row->{version};
4482 }
4483 0 ▶ next unless $dont_uniquify;
Branch: 1 branch
BranchTrueFalseTotal
unless $dont_uniquify 0 0 0
4484 }
4485 0 ▶ delete $row->{phase} unless $phase eq 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "ALL" 0 0 0
4486 0 ▶ delete $row->{rel} unless $rel eq 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "ALL" 0 0 0
4487 0 $memory_by_mod_name->{$row->{module}} = $row->{version};
4488 0 $row->{level} = $level;
4489 0 push @res, $row;
4490 }
4491  
4492 0 ▶ if (@res && ($max_level==-1 || $level < $max_level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@res and $max_level == -1 || $level < $max_level) 0 0 0
Condition0%0/6
@res and $max_level == -1 || $level < $max_level
!ll&&!rl&&r
000
$max_level == -1 or $level < $max_level
l!l&&r!l&&!r
000
MC/DC0%0/3
@res and $max_level == -1 || $level < $max_level
@res $max_level == -1 $level < $max_level
Truth table0%0/4
A and B or C
A= @resB= $max_level == -1C= $level < $max_level
ABCresult
0XX0
1000
11X1
1011
4493 0 my $subres = _get_prereqs([grep {defined} map { $_->{module_file_id} } @res], $dbh,
4494 $memory_by_mod_name,
4495 $memory_by_file_id,
4496 $level+1, $max_level, $filters, $plver, $flatten, $dont_uniquify, $phase, $rel);
4497 0 ▶ return $subres if $subres->[0] != 200;
Branch: 1 branch
BranchTrueFalseTotal
if $subres->[0] != 200 0 0 0
4498 0 ▶ if ($flatten) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flatten) { } 0 0 0
4499 0 my %deps; # key = module name
4500 0 for my $s (@{$subres->[2]}, @res) {
4501 0 $s->{version} = $memory_by_mod_name->{$s->{module}};
4502 0 $deps{ $s->{module} } = $s;
4503 }
4504 0 @res = map {$deps{$_}} sort keys %deps;
4505 } else {
4506 # insert to res in appropriate places
4507 SUBRES_TO_INSERT:
4508 0 for my $s (@{$subres->[2]}) {
4509 0 for my $i (0..@res-1) {
4510 0 my $r = $res[$i];
4511 0 ▶ if (defined($s->{dist}) && defined($r->{module_dist}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"dist"} and defined $r->{"module_dist"} and $s->{"dist"} eq $r->{"module_dist"}) 0 0 0
Condition0%0/6
defined $s->{"dist"} and defined $r->{"module_dist"} and $s->{"dist"} eq $r->{"module_dist"}
!ll&&!rl&&r
000
defined $s->{"dist"} and defined $r->{"module_dist"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $s->{"dist"} and defined $r->{"module_dist"} and $s->{"dist"} eq $r->{"module_dist"}
defined $s->{"dist"} defined $r->{"module_dist"} $s->{"dist"} eq $r->{"module_dist"}
Truth table0%0/4
A and B and C
A= defined $s->{"dist"}B= defined $r->{"module_dist"}C= $s->{"dist"} eq $r->{"module_dist"}
ABCresult
0XX0
10X0
1100
1111
4512 $s->{dist} eq $r->{module_dist}) {
4513 0 splice @res, $i+1, 0, $s;
4514 0 next SUBRES_TO_INSERT;
4515 }
4516 }
4517 0 return [500, "Bug? Can't insert subres (module=$s->{module}, module_dist=$s->{module_dist})"];
4518 }
4519 }
4520 }
4521  
4522 0 [200, "OK", \@res];
4523 }
4524  
4525 0 ▶sub _get_revdeps {
Subroutine _get_revdeps: not called CC=31 SCAR=69.0
4526 0 my ($mods, $dbh, $memory_by_dist_name, $memory_by_mod_name,
4527 $level, $max_level, $filters, $flatten, $dont_uniquify, $phase, $rel) = @_;
4528  
4529 0 log_trace("Finding reverse dependencies for module(s) %s ...", $mods);
4530  
4531 # first, check that all modules are listed
4532 0 my @indexed_mod_names;
4533 my @unindexed_mod_names;
4534 0 for my $mod0 (@$mods) {
4535 0 my ($mod);
4536 0 ▶ if (ref($mod0) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mod0 eq 'HASH') { } 0 0 0
4537 0 $mod = $mod0->{mod};
4538 } else {
4539 ($mod) = $dbh->selectrow_array("SELECT name FROM module WHERE name=?", {}, $mod0)
4540 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
($mod) = $dbh->selectrow_array("SELECT name FROM module WHERE name=?", {}, $mod0) or do { warn "lcpan: Module is unindexed: $mod0\n"; push @unindexed_mod_names, $mod0; next } 0 0 0
4541 0 warn "lcpan: Module is unindexed: $mod0\n";
4542 0 push @unindexed_mod_names, $mod0;
4543 0 next;
4544 };
4545 }
4546 0 ▶ unless ($memory_by_mod_name->{$mod} && $dont_uniquify) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($memory_by_mod_name->{$mod} and $dont_uniquify) 0 0 0
Condition0%0/3
$memory_by_mod_name->{$mod} and $dont_uniquify
!ll&&!rl&&r
000
MC/DC0%0/2
$memory_by_mod_name->{$mod} and $dont_uniquify
$memory_by_mod_name->{$mod} $dont_uniquify
Truth table0%0/3
A and B
A= $memory_by_mod_name->{$mod}B= $dont_uniquify
ABresult
0X0
100
111
4547 0 push @indexed_mod_names, $mod;
4548 0 $memory_by_mod_name->{$mod} = $mod;
4549 }
4550 }
4551 0 ▶ if (@indexed_mod_names) {
Branch: 2 branches
BranchTrueFalseTotal
if (@indexed_mod_names) { } 0 0 0
elsif (@unindexed_mod_names) { } 0 0 0
4552 0 ▶ if (@unindexed_mod_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unindexed_mod_names) 0 0 0
4553 0 warn "lcpan: There are unindexed as well as indexed module names, I'm ignoring unindexed module names for now (".join(", ", @unindexed_mod_names)."), this limitation will be rectified in the future.\n";
4554 0 @unindexed_mod_names = ();
4555 }
4556 } elsif (@unindexed_mod_names) {
4557 0 ▶ warn "lcpan: Can't do multilevel rdeps for unindexed modules (".join(", ", @unindexed_mod_names)."), ignoring multilevel request\n"
Branch: 1 branch
BranchTrueFalseTotal
if $max_level > 1 0 0 0
4558 if $max_level > 1;
4559 0 return _get_revdeps_unindexed(\@unindexed_mod_names, $dbh, $filters, $phase, $rel);
4560 } else {
4561 0 return [200, "OK", []];
4562 }
4563  
4564 0 my @where = ('module IN ('.join(",", map {$dbh->quote($_)} @indexed_mod_names).')');
4565 0 my @bind = ();
4566  
4567 0 push @where, "dist IS NOT NULL";
4568  
4569 0 ▶ if ($filters->{authors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"authors"}) 0 0 0
4570 0 push @where, '('.join(' OR ', ('author=?') x @{$filters->{authors}}).')';
4571 0 push @bind , @{$filters->{authors}};
4572 }
4573 0 ▶ if ($filters->{authors_arent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"authors_arent"}) 0 0 0
4574 0 for (@{ $filters->{authors_arent} }) {
4575 0 push @where, 'author <> ?';
4576 0 push @bind , $_;
4577 }
4578 }
4579  
4580 0 _add_since_where_clause($filters, \@where, 'dp');
4581  
4582 # get all dists that depend on that module
4583 0 ▶ my $sth = $dbh->prepare("SELECT
Branch: 1 branch
BranchTrueFalseTotal
$level > 1 ? : 0 0 0
4584 -- dp.file_id AS _file_id, -- unused, for debugging only
4585 -- dp.module_id AS _mod_id, -- unused, for debugging only
4586  
4587 (SELECT dist_name FROM file WHERE id=dp.file_id) AS dist,
4588 (SELECT dist_name FROM file WHERE id=(SELECT file_id FROM module WHERE id=dp.module_id)) module_dist,
4589 (SELECT name FROM module WHERE dp.module_id=module.id) AS module,
4590 (SELECT cpanid FROM file WHERE dp.file_id=file.id) AS author,
4591 (SELECT dist_version FROM file WHERE dp.file_id=file.id) AS dist_version,
4592 phase,
4593 rel,
4594 version req_version
4595 FROM dep dp
4596 WHERE ".join(" AND ", @where)."
4597 ORDER BY dist".($level > 1 ? " DESC" : ""));
4598 0 $sth->execute(@bind);
4599 0 my @res;
4600 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
4601 0 ▶ next unless $phase eq 'ALL' || $row->{phase} eq $phase;
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "ALL" or $row->{"phase"} eq $phase 0 0 0
Condition0%0/3
$phase eq "ALL" or $row->{"phase"} eq $phase
l!l&&r!l&&!r
000
MC/DC0%0/2
$phase eq "ALL" or $row->{"phase"} eq $phase
$phase eq "ALL" $row->{"phase"} eq $phase
Truth table0%0/3
A or B
A= $phase eq "ALL"B= $row->{"phase"} eq $phase
ABresult
1X1
011
000
4602 0 ▶ next unless $rel eq 'ALL' || $row->{rel} eq $rel;
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "ALL" or $row->{"rel"} eq $rel 0 0 0
Condition0%0/3
$rel eq "ALL" or $row->{"rel"} eq $rel
l!l&&r!l&&!r
000
MC/DC0%0/2
$rel eq "ALL" or $row->{"rel"} eq $rel
$rel eq "ALL" $row->{"rel"} eq $rel
Truth table0%0/3
A or B
A= $rel eq "ALL"B= $row->{"rel"} eq $rel
ABresult
1X1
011
000
4603 0 ▶ next if exists($memory_by_dist_name->{$row->{dist}}) && !$dont_uniquify;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$memory_by_dist_name{$row->{"dist"}} and not $dont_uniquify 0 0 0
Condition0%0/3
exists $$memory_by_dist_name{$row->{"dist"}} and not $dont_uniquify
!ll&&!rl&&r
000
MC/DC0%0/2
exists $$memory_by_dist_name{$row->{"dist"}} and not $dont_uniquify
exists $$memory_by_dist_name{$row->{"dist"}} not $dont_uniquify
Truth table0%0/3
A and not(B)
A= exists $$memory_by_dist_name{$row->{"dist"}}B= not $dont_uniquify
ABresult
0X0
100
111
4604 0 $memory_by_dist_name->{$row->{dist}} = $row->{dist_version};
4605 0 ▶ delete $row->{phase} unless $phase eq 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "ALL" 0 0 0
4606 0 ▶ delete $row->{rel} unless $rel eq 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "ALL" 0 0 0
4607 0 $row->{level} = $level;
4608 0 push @res, $row;
4609 }
4610  
4611 0 ▶ if (@res && ($max_level==-1 || $level < $max_level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@res and $max_level == -1 || $level < $max_level) 0 0 0
Condition0%0/6
@res and $max_level == -1 || $level < $max_level
!ll&&!rl&&r
000
$max_level == -1 or $level < $max_level
l!l&&r!l&&!r
000
MC/DC0%0/3
@res and $max_level == -1 || $level < $max_level
@res $max_level == -1 $level < $max_level
Truth table0%0/4
A and B or C
A= @resB= $max_level == -1C= $level < $max_level
ABCresult
0XX0
1000
11X1
1011
4612 # find the module of those depending dists
4613 my $sth = $dbh->prepare("
4614 SELECT m.name name
4615 FROM file f
4616 JOIN module m
4617 ON f.id=m.file_id
4618 0 WHERE f.dist_name IN (".join(", ", map {$dbh->quote($_->{dist})} @res).")");
4619 0 $sth->execute();
4620 0 my @mods;
4621 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
4622 0 push @mods, {mod=>$row->{name}};
4623 }
4624 0 my $subres = _get_revdeps(\@mods, $dbh,
4625 $memory_by_dist_name, $memory_by_mod_name,
4626 $level+1, $max_level, $filters, $flatten, $dont_uniquify, $phase, $rel);
4627 0 ▶ return $subres if $subres->[0] != 200;
Branch: 1 branch
BranchTrueFalseTotal
if $subres->[0] != 200 0 0 0
4628 # insert to res in appropriate places
4629 SUBRES_TO_INSERT:
4630 0 for my $s (@{$subres->[2]}) {
4631 0 for my $i (reverse 0..@res-1) {
4632 0 my $r = $res[$i];
4633 0 ▶ if ($s->{module_dist} eq $r->{dist}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"module_dist"} eq $r->{"dist"}) 0 0 0
4634 0 splice @res, $i+1, 0, $s;
4635 0 next SUBRES_TO_INSERT;
4636 }
4637 }
4638 0 return [500, "Bug? Can't insert subres (dist=$s->{dist}, module_dist=$s->{module_dist})"];
4639 }
4640 }
4641  
4642 0 [200, "OK", \@res];
4643 }
4644  
4645 0 ▶sub _get_revdeps_unindexed {
Subroutine _get_revdeps_unindexed: not called CC=11 SCAR=48.8
4646 0 my ($mods, $dbh, $filters, $phase, $rel) = @_;
4647  
4648 0 my @where = ('module_name IN ('.join(",", map {$dbh->quote($_)} @$mods).')');
4649 0 my @bind = ();
4650  
4651 0 push @where, "dist IS NOT NULL";
4652  
4653 0 ▶ if ($filters->{authors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"authors"}) 0 0 0
4654 0 push @where, '('.join(' OR ', ('author=?') x @{$filters->{authors}}).')';
4655 0 push @bind , @{$filters->{authors}};
4656 }
4657 0 ▶ if ($filters->{authors_arent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters->{"authors_arent"}) 0 0 0
4658 0 for (@{ $filters->{authors_arent} }) {
4659 0 push @where, 'author <> ?';
4660 0 push @bind , $_;
4661 }
4662 }
4663  
4664 0 _add_since_where_clause($filters, \@where, 'dp');
4665  
4666 # get all dists that depend on that module
4667 0 my $sth = $dbh->prepare("SELECT
4668 -- dp.file_id AS _file_id, -- unused, for debugging only
4669 -- dp.module_id AS _mod_id, -- unused, for debugging only
4670  
4671 (SELECT dist_name FROM file WHERE id=dp.file_id) AS dist,
4672 NULL AS module_dist,
4673 module_name AS module,
4674 (SELECT cpanid FROM file WHERE dp.file_id=file.id) AS author,
4675 (SELECT dist_version FROM file WHERE dp.file_id=file.id) AS dist_version,
4676 phase,
4677 rel,
4678 version req_version
4679 FROM dep dp
4680 WHERE ".join(" AND ", @where)."
4681 ORDER BY dist");
4682 0 $sth->execute(@bind);
4683 0 my @res;
4684 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
4685 0 ▶ next unless $phase eq 'ALL' || $row->{phase} eq $phase;
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "ALL" or $row->{"phase"} eq $phase 0 0 0
Condition0%0/3
$phase eq "ALL" or $row->{"phase"} eq $phase
l!l&&r!l&&!r
000
MC/DC0%0/2
$phase eq "ALL" or $row->{"phase"} eq $phase
$phase eq "ALL" $row->{"phase"} eq $phase
Truth table0%0/3
A or B
A= $phase eq "ALL"B= $row->{"phase"} eq $phase
ABresult
1X1
011
000
4686 0 ▶ next unless $rel eq 'ALL' || $row->{rel} eq $rel;
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "ALL" or $row->{"rel"} eq $rel 0 0 0
Condition0%0/3
$rel eq "ALL" or $row->{"rel"} eq $rel
l!l&&r!l&&!r
000
MC/DC0%0/2
$rel eq "ALL" or $row->{"rel"} eq $rel
$rel eq "ALL" $row->{"rel"} eq $rel
Truth table0%0/3
A or B
A= $rel eq "ALL"B= $row->{"rel"} eq $rel
ABresult
1X1
011
000
4687 0 ▶ delete $row->{phase} unless $phase eq 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "ALL" 0 0 0
4688 0 ▶ delete $row->{rel} unless $rel eq 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
unless $rel eq "ALL" 0 0 0
4689 0 $row->{level} = 1;
4690 0 push @res, $row;
4691 }
4692 0 [200, "OK", \@res];
4693 }
4694  
4695 our %deps_phase_args = (
4696 phase => {
4697 schema => ['str*' => {
4698 match => qr/\A(develop|configure|build|runtime|test|ALL|x_\w+)\z/,
4699 }],
4700 default => 'runtime',
4701 cmdline_aliases => {
4702 all => {
4703 summary => 'Equivalent to --phase ALL --rel ALL',
4704 is_flag => 1,
4705 0 ▶ code => sub { $_[0]{phase} = 'ALL'; $_[0]{rel} = 'ALL' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4706 },
4707 },
4708 98 completion => [qw/develop configure build runtime test ALL/],
4709 tags => ['category:filtering'],
4710 },
4711 );
4712  
4713 98 our %rdeps_phase_args = %{clone(\%deps_phase_args)};
4714 98 $rdeps_phase_args{phase}{default} = 'ALL';
4715  
4716 98 our %deps_rel_args = (
4717 rel => {
4718 schema => ['str*' => {
4719 match => qr/\A(requires|recommends|suggests|conflicts|ALL|x_\w+)\z/,
4720 }],
4721 default => 'requires',
4722 completion => [qw/requires recommends suggests conflicts ALL/],
4723 tags => ['category:filtering'],
4724 },
4725 );
4726  
4727 98 our %rdeps_rel_args = %{clone(\%deps_rel_args)};
4728 98 $rdeps_rel_args{rel}{default} = 'ALL';
4729  
4730 our %rdeps_level_args = (
4731 level => {
4732 summary => 'Recurse for a number of levels (-1 means unlimited)',
4733 schema => ['int*', min=>1, max=>10],
4734 default => 1,
4735 cmdline_aliases => {
4736 l => {},
4737 R => {
4738 summary => 'Recurse (alias for `--level 10`)',
4739 is_flag => 1,
4740 0 ▶ code => sub { $_[0]{level} = 10 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4741 },
4742 },
4743 },
4744 98 );
4745  
4746 our %deps_args = (
4747 %deps_phase_args,
4748 %deps_rel_args,
4749 level => {
4750 summary => 'Recurse for a number of levels (-1 means unlimited)',
4751 schema => 'int*',
4752 default => 1,
4753 cmdline_aliases => {
4754 l => {},
4755 R => {
4756 summary => 'Recurse (alias for `--level -1`)',
4757 is_flag => 1,
4758 0 ▶ code => sub { $_[0]{level} = -1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4759 },
4760 },
4761 },
4762 98 flatten => {
4763 summary => 'Instead of showing tree-like information, flatten it',
4764 schema => 'bool',
4765 description => <<'_',
4766  
4767 When recursing, the default is to show the final result in a tree-like table,
4768 i.e. indented according to levels, e.g.:
4769  
4770 % lcpan deps -R MyModule
4771 | module | author | version |
4772 |-------------------|---------|---------|
4773 | Foo | AUTHOR1 | 0.01 |
4774 | Bar | AUTHOR2 | 0.23 |
4775 | Baz | AUTHOR3 | 1.15 |
4776 | Qux | AUTHOR2 | 0 |
4777  
4778 To be brief, if `Qux` happens to also depends on `Bar`, it will not be shown in
4779 the result. Thus we don't know the actual `Bar` version that is needed by the
4780 dependency tree of `MyModule`. For example, if `Qux` happens to depends on `Bar`
4781 version 0.45 then `MyModule` indirectly requires `Bar` 0.45.
4782  
4783 To list all the direct and indirect dependencies on a single flat list, with
4784 versions already resolved to the largest version required, use the `flatten`
4785 option:
4786  
4787 % lcpan deps -R --flatten MyModule
4788 | module | author | version |
4789 |-------------------|---------|---------|
4790 | Foo | AUTHOR1 | 0.01 |
4791 | Bar | AUTHOR2 | 0.45 |
4792 | Baz | AUTHOR3 | 1.15 |
4793 | Qux | AUTHOR2 | 0 |
4794  
4795 Note that `Bar`'s required version is already 0.45 in the above example.
4796  
4797 _
4798 },
4799 dont_uniquify => {
4800 summary => 'Allow showing multiple modules for different dists',
4801 schema => 'bool*',
4802 },
4803 %finclude_core_args,
4804 %finclude_noncore_args,
4805 %perl_version_args,
4806 with_xs_or_pp => {
4807 summary => 'Check each dependency as XS/PP',
4808 schema => ['bool*', is=>1],
4809 tags => ['category:filtering'],
4810 },
4811 %finclude_indexed_args,
4812 %finclude_unindexed_args,
4813 %fctime_args,
4814 %fmtime_args,
4815 %fctime_or_mtime_args,
4816 );
4817  
4818 98 our $deps_args_rels = {
4819 dep_any => [flatten => ['level']],
4820 };
4821  
4822 98 $SPEC{'deps'} = {
4823 v => 1.1,
4824 summary => 'List dependencies of distributions',
4825 description => <<'_',
4826  
4827 By default only runtime requires are displayed. To see prereqs for other phases
4828 (e.g. configure, or build, or ALL) or for other relationships (e.g. recommends,
4829 or ALL), use the `--phase` and `--rel` options.
4830  
4831 Note that dependencies information are taken from `META.json` or `META.yml`
4832 files. Not all releases (especially older ones) contain them. <prog:lcpan> (like
4833 MetaCPAN) does not extract information from `Makefile.PL` or `Build.PL` because
4834 that requires running (untrusted) code.
4835  
4836 Also, some releases specify dynamic config, so there might actually be more
4837 dependencies.
4838  
4839 _
4840 args => {
4841 %common_args,
4842 %argspec0opt_dists_with_optional_vers,
4843 %argspecopt_mods,
4844 %deps_args,
4845 exclude_deps => {
4846 summary => 'Exclude some dependencies from being shown',
4847 'x.name.is_plural' => 1,
4848 'x.name.singular' => 'exclude_dep',
4849 schema => ['array*', of=>'perl::modname*', min_len=>1],
4850 element_completion => \&_complete_mod,
4851 },
4852 },
4853 args_rels => {
4854 req_one => ['modules', 'dists'],
4855 dep_any => [flatten => ['level']],
4856 },
4857 examples => [
4858 {
4859 summary => 'List what modules Module-List requires',
4860 argv => ['Module-List'],
4861 test => 0,
4862 'x.doc.show_result' => 0,
4863 },
4864 {
4865 summary => 'List modules Module-List requires (module name will be converted to distro name)',
4866 argv => ['Module::List'],
4867 test => 0,
4868 'x.doc.show_result' => 0,
4869 },
4870 {
4871 summary => 'List what distribution that contains Sah::Schema::filename requires',
4872 description => <<'_',
4873  
4874 Sah::Schema::filename is included in Sah-Schemas-Path distribution, so this
4875 command is equivalent to "lcpan deps Sah-Schemas-Path". You can't do "lcpan deps
4876 Sah::Schema::filename" because `lcpan` will assume that you ask "lcpan deps
4877 Sah-Schema-filename" and there is no Sah-Schema-filename distribution.
4878  
4879 _
4880 argv => ['--module', 'Sah::Schema::filename'],
4881 test => 0,
4882 'x.doc.show_result' => 0,
4883 },
4884 {
4885 summary => 'List non-core modules Module-List requires',
4886 argv => ['Module-List', '--exclude-core'],
4887 test => 0,
4888 'x.doc.show_result' => 0,
4889 },
4890 {
4891 summary => 'List dependencies of a specific distribution release',
4892 argv => ['Module-List@0.004'],
4893 test => 0,
4894 'x.doc.show_result' => 0,
4895 },
4896 ],
4897 };
4898 0 ▶sub deps {
Subroutine deps: not called CC=21 SCAR=61.4
Pod documented
4899 0 require Module::XSOrPP;
4900 0 my %args = @_;
4901  
4902 0 my $state = _init(\%args, 'ro');
4903 0 my $dbh = $state->{dbh};
4904  
4905 my $file_ids =
4906 $args{dists} && !$args{modules} ? _dists_with_optional_vers2file_ids($dbh, $args{dists}) :
4907 0 ▶ $args{modules} && !$args{dists} ? _modules2file_ids($dbh, $args{modules}) :
Branch: 2 branches
BranchTrueFalseTotal
$args{'dists'} && !$args{'modules'} ? : 0 0 0
$args{'modules'} && !$args{'dists'} ? : 0 0 0
Condition0%0/6
$args{"dists"} and not $args{"modules"}
!ll&&!rl&&r
000
$args{"modules"} and not $args{"dists"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"dists"} and not $args{"modules"}
$args{"dists"} not $args{"modules"}
MC/DC0%0/2
$args{"modules"} and not $args{"dists"}
$args{"modules"} not $args{"dists"}
Truth table0%0/3
A and not(B)
A= $args{"dists"}B= not $args{"modules"}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $args{"modules"}B= not $args{"dists"}
ABresult
0X0
100
111
4908 (return [400, "Please specify dists OR modules"]);
4909 0 ▶ my $phase = $args{phase} // 'runtime';
Condition0%0/2
$args{"phase"} // "runtime"
l!l
00
MC/DC0%0/1
$args{"phase"} // "runtime"
$args{"phase"}
Truth table0%0/2
A
A= $args{"phase"}
Aresult
11
00
4910 0 ▶ my $rel = $args{rel} // 'requires';
Condition0%0/2
$args{"rel"} // "requires"
l!l
00
MC/DC0%0/1
$args{"rel"} // "requires"
$args{"rel"}
Truth table0%0/2
A
A= $args{"rel"}
Aresult
11
00
4911 0 ▶ my $plver = $args{perl_version} // "$^V";
Condition0%0/2
$args{"perl_version"} // "$^V"
l!l
00
MC/DC0%0/1
$args{"perl_version"} // "$^V"
$args{"perl_version"}
Truth table0%0/2
A
A= $args{"perl_version"}
Aresult
11
00
4912 0 ▶ my $level = $args{level} // 1;
Condition0%0/2
$args{"level"} // 1
l!l
00
MC/DC0%0/1
$args{"level"} // 1
$args{"level"}
Truth table0%0/2
A
A= $args{"level"}
Aresult
11
00
4913 0 ▶ my $include_core = $args{include_core} // 1;
Condition0%0/2
$args{"include_core"} // 1
l!l
00
MC/DC0%0/1
$args{"include_core"} // 1
$args{"include_core"}
Truth table0%0/2
A
A= $args{"include_core"}
Aresult
11
00
4914 0 ▶ my $include_noncore = $args{include_noncore} // 1;
Condition0%0/2
$args{"include_noncore"} // 1
l!l
00
MC/DC0%0/1
$args{"include_noncore"} // 1
$args{"include_noncore"}
Truth table0%0/2
A
A= $args{"include_noncore"}
Aresult
11
00
4915 0 my $with_xs_or_pp = $args{with_xs_or_pp};
4916 0 ▶ my $include_indexed = $args{include_indexed} // 1;
Condition0%0/2
$args{"include_indexed"} // 1
l!l
00
MC/DC0%0/1
$args{"include_indexed"} // 1
$args{"include_indexed"}
Truth table0%0/2
A
A= $args{"include_indexed"}
Aresult
11
00
4917 0 ▶ my $include_unindexed = $args{include_unindexed} // 1;
Condition0%0/2
$args{"include_unindexed"} // 1
l!l
00
MC/DC0%0/1
$args{"include_unindexed"} // 1
$args{"include_unindexed"}
Truth table0%0/2
A
A= $args{"include_unindexed"}
Aresult
11
00
4918  
4919 0 _set_since(\%args, $dbh);
4920 my $filters = {
4921 include_core => $include_core,
4922 include_noncore => $include_noncore,
4923 include_indexed => $include_indexed,
4924 include_unindexed => $include_unindexed,
4925 exclude_deps => $args{exclude_deps},
4926 authors => $args{authors},
4927 authors_arent => $args{authors_arent},
4928 added_since => $args{added_since},
4929 updated_since => $args{updated_since},
4930 added_or_updated_since => $args{added_or_updated_since},
4931 0 };
4932  
4933 my $res = _get_prereqs($file_ids, $dbh, {}, {},
4934 0 1, $level, $filters, $plver, $args{flatten}, $args{dont_uniquify}, $phase, $rel);
4935  
4936 0 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
4937 0 my @cols;
4938 0 push @cols, (qw/module/);
4939 0 ▶ push @cols, "dist" if @$file_ids > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$file_ids > 1 0 0 0
4940 0 push @cols, (qw/author version/);
4941 0 push @cols, "is_core";
4942 0 ▶ push @cols, "xs_or_pp" if $with_xs_or_pp;
Branch: 1 branch
BranchTrueFalseTotal
if $with_xs_or_pp 0 0 0
4943 0 for (@{$res->[2]}) {
4944 0 ▶ if ($with_xs_or_pp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($with_xs_or_pp) 0 0 0
4945 0 $_->{xs_or_pp} = Module::XSOrPP::xs_or_pp($_->{module});
4946 }
4947 $_->{module} = (" " x ($_->{level}-1)) . $_->{module}
4948 0 ▶ unless $args{flatten};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"flatten"} 0 0 0
4949 0 ▶ delete $_->{dist} unless @$file_ids > 1 || $_->{level} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$file_ids > 1 or $_->{"level"} > 1 0 0 0
Condition0%0/3
@$file_ids > 1 or $_->{"level"} > 1
l!l&&r!l&&!r
000
MC/DC0%0/2
@$file_ids > 1 or $_->{"level"} > 1
@$file_ids > 1 $_->{"level"} > 1
Truth table0%0/3
A or B
A= @$file_ids > 1B= $_->{"level"} > 1
ABresult
1X1
011
000
4950 0 delete $_->{module_file_id};
4951 0 delete $_->{level};
4952 }
4953  
4954 0 my $resmeta = {};
4955 0 $resmeta->{'table.fields'} = \@cols;
4956 0 $res->[3] = $resmeta;
4957 0 $res;
4958 }
4959  
4960 98 my %rdeps_args = (
4961 %common_args,
4962 %argspec0opt_modules,
4963 %argspecopt_dists,
4964 %rdeps_rel_args,
4965 %rdeps_phase_args,
4966 %rdeps_level_args,
4967 flatten => {
4968 summary => 'Instead of showing tree-like information, flatten it',
4969 schema => 'bool',
4970 description => <<'_',
4971  
4972 See deps' *flatten* argument for more details.
4973  
4974 _
4975 },
4976 dont_uniquify => {
4977 summary => 'Allow showing multiple modules for different dists',
4978 schema => 'true*',
4979 },
4980 authors => {
4981 'x.name.is_plural' => 1,
4982 summary => 'Filter certain author',
4983 schema => ['array*', of=>'str*'],
4984 description => <<'_',
4985  
4986 This can be used to select certain author(s).
4987  
4988 _
4989 completion => \&_complete_cpanid,
4990 tags => ['category:filtering'],
4991 },
4992 authors_arent => {
4993 'x.name.is_plural' => 1,
4994 'x.name.singular' => 'author_isnt',
4995 summary => 'Filter out certain author',
4996 schema => ['array*', of=>'str*'],
4997 description => <<'_',
4998  
4999 This can be used to filter out certain author(s). For example if you want to
5000 know whether a module is being used by another CPAN author instead of just
5001 herself.
5002  
5003 _
5004 completion => \&_complete_cpanid,
5005 tags => ['category:filtering'],
5006 },
5007 %fctime_args,
5008 %fmtime_args,
5009 %fctime_or_mtime_args,
5010 );
5011  
5012 98 our $rdeps_args_rels = {
5013 dep_any => [flatten => ['level']],
5014 };
5015  
5016 98 $SPEC{'rdeps'} = {
5017 v => 1.1,
5018 summary => 'List reverse dependencies',
5019 args => {
5020 %rdeps_args,
5021 },
5022 examples => [
5023 {
5024 summary => 'List what distributions depend on Sah::Schema::filename',
5025 argv => ['Sah::Schema::filename'],
5026 test => 0,
5027 'x.doc.show_result' => 0,
5028 },
5029 {
5030 summary => 'List what distributions depend on one of the modules in Sah-Schemas-Path',
5031 argv => ['--dist', 'Sah-Schemas-Path'],
5032 test => 0,
5033 'x.doc.show_result' => 0,
5034 },
5035 ],
5036 args_rels => {
5037 req_one => ['modules', 'dists'],
5038 dep_any => [flatten => ['level']],
5039 },
5040 };
5041 0 ▶sub rdeps {
Subroutine rdeps: not called CC=13 SCAR=52.0
Pod documented
5042 0 my %args = @_;
5043  
5044 0 my $state = _init(\%args, 'ro');
5045 0 my $dbh = $state->{dbh};
5046  
5047 my $mods =
5048 $args{modules} && !$args{dists} ? $args{modules} :
5049 0 ▶ $args{dists} && !$args{modules} ? _dists2theirmods($dbh, $args{dists}) :
Branch: 2 branches
BranchTrueFalseTotal
$args{'modules'} && !$args{'dists'} ? : 0 0 0
$args{'dists'} && !$args{'modules'} ? : 0 0 0
Condition0%0/6
$args{"modules"} and not $args{"dists"}
!ll&&!rl&&r
000
$args{"dists"} and not $args{"modules"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"modules"} and not $args{"dists"}
$args{"modules"} not $args{"dists"}
MC/DC0%0/2
$args{"dists"} and not $args{"modules"}
$args{"dists"} not $args{"modules"}
Truth table0%0/3
A and not(B)
A= $args{"modules"}B= not $args{"dists"}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $args{"dists"}B= not $args{"modules"}
ABresult
0X0
100
111
5050 (return [400, "Please specify modules OR dists"]);
5051 0 ▶ my $level = $args{level} // 1;
Condition0%0/2
$args{"level"} // 1
l!l
00
MC/DC0%0/1
$args{"level"} // 1
$args{"level"}
Truth table0%0/2
A
A= $args{"level"}
Aresult
11
00
5052 0 ▶ my $authors = $args{authors} ? [map {uc} @{$args{authors}}] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'authors'} ? : 0 0 0
5053 0 ▶ my $authors_arent = $args{authors_arent} ? [map {uc} @{$args{authors_arent}}] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'authors_arent'} ? : 0 0 0
5054  
5055 0 _set_since(\%args, $dbh);
5056 my $filters = {
5057 authors => $authors,
5058 authors_arent => $authors_arent,
5059 added_since => $args{added_since},
5060 updated_since => $args{updated_since},
5061 added_or_updated_since => $args{added_or_updated_since},
5062 0 };
5063  
5064 0 my $res = _get_revdeps($mods, $dbh, {}, {}, 1, $level, $filters, $args{flatten}, $args{dont_uniquify}, $args{phase}, $args{rel});
5065  
5066 0 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
5067 0 for (@{$res->[2]}) {
5068 $_->{dist} = (" " x ($_->{level}-1)) . $_->{dist}
5069 0 ▶ unless $args{flatten};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"flatten"} 0 0 0
5070 0 ▶ delete $_->{module} unless @$mods > 1 || $_->{level} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$mods > 1 or $_->{"level"} > 1 0 0 0
Condition0%0/3
@$mods > 1 or $_->{"level"} > 1
l!l&&r!l&&!r
000
MC/DC0%0/2
@$mods > 1 or $_->{"level"} > 1
@$mods > 1 $_->{"level"} > 1
Truth table0%0/3
A or B
A= @$mods > 1B= $_->{"level"} > 1
ABresult
1X1
011
000
5071 0 delete $_->{level};
5072 }
5073  
5074 0 my $resmeta = {};
5075 0 $resmeta->{'table.fields'} = [qw/dist author dist_version req_version/];
5076 0 $res->[3] = $resmeta;
5077 0 $res;
5078 }
5079  
5080 $SPEC{namespaces} = {
5081 v => 1.1,
5082 summary => 'List namespaces',
5083 args => {
5084 %common_args,
5085 %query_multi_args,
5086 query_type => {
5087 schema => ['str*', in=>[qw/any name exact-name regexp-name/]],
5088 default => 'any',
5089 cmdline_aliases => {
5090 x => {
5091 summary => 'Shortcut --query-type exact-name',
5092 is_flag => 1,
5093 0 ▶ code => sub { $_[0]{query_type} = 'exact-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5094 },
5095 r => {
5096 summary => 'Shortcut --query-type regexp-name',
5097 is_flag => 1,
5098 0 ▶ code => sub { $_[0]{query_type} = 'regexp-name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5099 },
5100 n => {
5101 summary => 'Shortcut --query-type name',
5102 is_flag => 1,
5103 0 ▶ code => sub { $_[0]{query_type} = 'name' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5104 },
5105 },
5106 },
5107 98 from_level => {
5108 schema => ['int*', min=>0],
5109 tags => ['category:filtering'],
5110 },
5111 to_level => {
5112 schema => ['int*', min=>0],
5113 tags => ['category:filtering'],
5114 },
5115 level => {
5116 schema => ['int*', min=>0],
5117 tags => ['category:filtering'],
5118 },
5119 sort => {
5120 schema => ['str*', in=>[qw/name -name num_modules -num_modules/]],
5121 default => 'name',
5122 tags => ['category:sorting'],
5123 },
5124 %fctime_args,
5125 %fmtime_args,
5126 %fctime_or_mtime_args,
5127 },
5128 };
5129 0 ▶sub namespaces {
Subroutine namespaces: not called CC=21 SCAR=61.4
Pod documented
5130 0 my %args = @_;
5131  
5132 0 my $state = _init(\%args, 'ro');
5133 0 my $dbh = $state->{dbh};
5134  
5135 0 my $detail = $args{detail};
5136 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
5137  
5138 0 my @bind;
5139 my @where;
5140 {
5141 0 my @q_where;
5142 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
5143 0 ▶ if ($qt eq 'any' || $qt eq 'name') {
Branch: 3 branches
BranchTrueFalseTotal
if ($qt eq 'any' or $qt eq 'name') { } 0 0 0
elsif ($qt eq 'exact-name') { } 0 0 0
elsif ($qt eq 'regexp-name') { } 0 0 0
Condition0%0/3
$qt eq "any" or $qt eq "name"
l!l&&r!l&&!r
000
MC/DC0%0/2
$qt eq "any" or $qt eq "name"
$qt eq "any" $qt eq "name"
Truth table0%0/3
A or B
A= $qt eq "any"B= $qt eq "name"
ABresult
1X1
011
000
5144 0 ▶ my $q = $q0 =~ /%/ ? $q0 : '%'.$q0.'%';
Branch: 1 branch
BranchTrueFalseTotal
$q0 =~ /%/ ? : 0 0 0
5145 0 push @q_where, "(name LIKE ?)";
5146 0 push @bind, $q;
5147 } elsif ($qt eq 'exact-name') {
5148 0 push @q_where, "(name=?)";
5149 0 push @bind, $q0;
5150 } elsif ($qt eq 'regexp-name') {
5151 0 push @q_where, "(name REGEXP ?)";
5152 0 push @bind, $q0;
5153 }
5154 }
5155 0 ▶ if (@q_where > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@q_where > 1) { } 0 0 0
elsif (@q_where == 1) { } 0 0 0
5156 0 ▶ push @where, "(".join(($args{or} ? " OR " : " AND "), @q_where).")";
Branch: 1 branch
BranchTrueFalseTotal
$args{'or'} ? : 0 0 0
5157 } elsif (@q_where == 1) {
5158 0 push @where, @q_where;
5159 }
5160 }
5161 0 ▶ if (defined $args{from_level}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"from_level"}) 0 0 0
5162 0 push @where, "(num_sep >= ?)";
5163 0 push @bind, $args{from_level}-1;
5164 }
5165 0 ▶ if (defined $args{to_level}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"to_level"}) 0 0 0
5166 0 push @where, "(num_sep <= ?)";
5167 0 push @bind, $args{to_level}-1;
5168 }
5169 0 ▶ if (defined $args{level}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"level"}) 0 0 0
5170 0 push @where, "(num_sep = ?)";
5171 0 push @bind, $args{level}-1;
5172 }
5173  
5174 0 _set_since(\%args, $dbh);
5175 0 _add_since_where_clause(\%args, \@where, "namespace");
5176  
5177 0 my $order = 'name';
5178 0 ▶ if ($args{sort} eq 'num_modules') {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'sort'} eq 'num_modules') { } 0 0 0
elsif ($args{'sort'} eq '-num_modules') { } 0 0 0
5179 0 $order = "num_modules";
5180 } elsif ($args{sort} eq '-num_modules') {
5181 0 $order = "num_modules DESC";
5182 }
5183 0 ▶ my $sql = "SELECT
Branch: 1 branch
BranchTrueFalseTotal
@where ? : 0 0 0
5184 name,
5185 num_modules
5186 FROM namespace".
5187 (@where ? " WHERE ".join(" AND ", @where) : "")."
5188 ORDER BY $order";
5189  
5190 0 my @res;
5191 0 my $sth = $dbh->prepare($sql);
5192 0 $sth->execute(@bind);
5193 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
5194 0 ▶ push @res, $detail ? $row : $row->{name};
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 0 0 0
5195 }
5196 0 my $resmeta = {};
5197 0 ▶ $resmeta->{'table.fields'} = [qw/name num_modules/]
Branch: 1 branch
BranchTrueFalseTotal
if $detail 0 0 0
5198 if $detail;
5199 0 [200, "OK", \@res, $resmeta];
5200 }
5201  
5202 98 1;
5203 # ABSTRACT: Manage your local CPAN mirror
5204  
5205 __END__
↑ Summary App/lcpan/Cmd/mentions.pm »