| 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
| |||||||||||||
| 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 //= ""
MC/DC0%0/1
$prev_items //= ""
$prev_items
Truth table0%0/2
A
A= $prev_items
| |||||||||||||
| 50 | |||||||||||||
| 51 | 0 | my $ans = hashify_answer($xcompletion->(word => $cur_item)); | |||||||||||
| 52 | 0 | ▶ | return unless $ans; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 0 | for my $word (@{ $ans->{words} }) { | |||||||||||
| 54 | # reattach the previous items | ||||||||||||
| 55 | 0 | ▶ | if (ref $word eq 'HASH') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||