XCompletion/comma_sep.pm

filter: Statementstmt 44.6% 21 / 47 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 62.5% 5 / 8 Podpod 100% 1 / 1 totaltotal 41.5% 27 / 65 CC 6 SCAR 25.4
CC
6
Cov
38%
__ANON__
30.0
_gen
4.1
gen_completion
2.0
CRAP 12.7
« XCompletion/pathname_curdir.pm ↑ Summary XCompletion/dirname.pm »
1 package Perinci::Sub::XCompletion::comma_sep;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Complete::Util qw(hashify_answer);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 1 our $DATE = '2023-11-18'; # DATE
11 1 our $DIST = 'Perinci-Sub-XCompletion'; # DIST
12 1 our $VERSION = '0.106'; # VERSION
13  
14 1 our %SPEC;
15  
16 0 ▶sub _gen {
Subroutine _gen: not called CC=2 SCAR=14.2
17 0 my ($submod) = @_;
18 0 my $xcargs;
19  
20 0 ▶ if (ref $submod eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $submod eq 'ARRAY') { } 0 0 0
21 0 $xcargs = $submod->[1];
22 0 $submod = $submod->[0];
23 } else {
24 0 $xcargs = {};
25 }
26  
27 1 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
28 0 my $mod = "Perinci::Sub::XCompletion::$submod";
29 0 (my $mod_pm = "$mod.pm") =~ s!::!/!g;
30 0 require $mod_pm;
31  
32 0 &{"$mod\::gen_completion"}(%$xcargs);
33 }
34  
35 $SPEC{gen_completion} = {
36 1 v => 1.1,
37 # XXX parameter 'uniq'
38 };
39 0 ▶sub gen_completion {
Subroutine gen_completion: not called CC=1 SCAR=6.9
Pod documented
40 0 my %fargs = @_;
41 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
42 0 my %cargs = @_;
43 0 my $word = $cargs{word};
44  
45 0 my $xcompletion = _gen($fargs{xcompletion});
46  
47 # XXX grok backslash escape
48 0 my ($prev_items, $cur_item) = $word =~ /\A(.*,)?(.*)/;
49 0 ▶ $prev_items //= "";
Condition0%0/2
$prev_items //= ""
l!l
00
MC/DC0%0/1
$prev_items //= ""
$prev_items
Truth table0%0/2
A
A= $prev_items
Aresult
11
00
50  
51 0 my $ans = hashify_answer($xcompletion->(word => $cur_item));
52 0 ▶ return unless $ans;
Branch: 1 branch
BranchTrueFalseTotal
unless $ans 0 0 0
53 0 for my $word (@{ $ans->{words} }) {
54 # reattach the previous items
55 0 ▶ if (ref $word eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $word eq 'HASH') { } 0 0 0
56 0 $word->{word} = $prev_items . $word->{word};
57 } else {
58 0 $word = $prev_items . $word;
59 }
60 }
61 0 $ans;
62 0 };
63 }
64  
65 1 1;
66 # ABSTRACT: Generate completion for completing a comma-separated list of other completion
67  
68 __END__
« XCompletion/pathname_curdir.pm ↑ Summary XCompletion/dirname.pm »