| 1 | package Complete::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | our $DATE = '2021-02-02'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $DIST = 'Complete-Path'; # DIST | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.251'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Complete::Common qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | our $COMPLETE_PATH_TRACE = $ENV{COMPLETE_PATH_TRACE} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"COMPLETE_PATH_TRACE"} // 0
MC/DC0%0/1
$ENV{"COMPLETE_PATH_TRACE"} // 0
$ENV{"COMPLETE_PATH_TRACE"}
Truth table50%1/2
A
A= $ENV{"COMPLETE_PATH_TRACE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | complete_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub _dig_leaf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dig_leaf: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ($p, $list_func, $is_dir_func, $filter_func, $path_sep) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $num_dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $listres = $list_func->($p, '', 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return $p unless ref($listres) eq 'ARRAY' && @$listres; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $listres eq "ARRAY" and @$listres
MC/DC0%0/2
ref $listres eq "ARRAY" and @$listres
ref $listres eq "ARRAY"
@$listres
Truth table0%0/3
A and B
A= ref $listres eq "ARRAY"B= @$listres
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my @candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | L1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | for my $e (@$listres) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $p2 = $p =~ m!\Q$path_sep\E\z! ? "$p$e" : "$p$path_sep$e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | local $_ = $p2; # convenience for filter func | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | next L1 if $filter_func && !$filter_func->($p2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter_func and not &$filter_func($p2)
MC/DC0%0/2
$filter_func and not &$filter_func($p2)
$filter_func
not &$filter_func($p2)
Truth table0%0/3
A and not(B)
A= $filter_funcB= not &$filter_func($p2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | push @candidates, $p2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return $p unless @candidates == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $p2 = $candidates[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $is_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($p2 =~ m!\Q$path_sep\E\z!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $is_dir++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $is_dir = $is_dir_func && $is_dir_func->($p2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$is_dir_func && &$is_dir_func($p2)
MC/DC0%0/2
$is_dir_func && &$is_dir_func($p2)
$is_dir_func
&$is_dir_func($p2)
Truth table0%0/3
A && B
A= $is_dir_funcB= &$is_dir_func($p2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return _dig_leaf($p2, $list_func, $is_dir_func, $filter_func, $path_sep) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | if $is_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $p2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | our %SPEC; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $SPEC{complete_path} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | summary => 'Complete path', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | description => <<'_', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | Complete path, for anything path-like. Meant to be used as backend for other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | functions like `Complete::File::complete_file` or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | `Complete::Module::complete_module`. Provides features like case-insensitive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | matching, expanding intermediate paths, and case mapping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | Algorithm is to split path into path elements, then list items (using the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | supplied `list_func`) and perform filtering (using the supplied `filter_func`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | at every level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | _ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | args => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | %arg_word, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | list_func => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | summary => 'Function to list the content of intermediate "dirs"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | schema => 'code*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | req => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | description => <<'_', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | Code will be called with arguments: ($path, $cur_path_elem, $is_intermediate). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | Code should return an arrayref containing list of elements. "Directories" can be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | marked by ending the name with the path separator (see `path_sep`). Or, you can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | also provide an `is_dir_func` function that will be consulted after filtering. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | If an item is a "directory" then its name will be suffixed with a path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | separator by `complete_path()`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | _ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | is_dir_func => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | summary => 'Function to check whether a path is a "dir"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | schema => 'code*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | description => <<'_', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Optional. You can provide this function to determine if an item is a "directory" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | (so its name can be suffixed with path separator). You do not need to do this if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | you already suffix names of "directories" with path separator in `list_func`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | One reason you might want to provide this and not mark "directories" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | `list_func` is when you want to do extra filtering with `filter_func`. Sometimes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | you do not want to suffix the names first (example: see `complete_file` in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | `Complete::File`). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | _ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | starting_path => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | schema => 'str*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | req => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | default => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | filter_func => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | schema => 'code*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | description => <<'_', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | Provide extra filtering. Code will be given path and should return 1 if the item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | should be included in the final result or 0 if the item should be excluded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | _ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | path_sep => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | schema => 'str*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | default => '/', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | #result_prefix => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # summary => 'Prefix each result with this string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # schema => 'str*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | #}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | recurse => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | schema => 'bool*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | cmdline_aliases => {r=>{}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | recurse_matching => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | schema => ['str*', in=>['level-by-level', 'all-at-once']], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | default => 'level-by-level', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | exclude_leaf => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | schema => 'bool*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | exclude_dir => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | schema => 'bool*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | args_rels => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | dep_all => [recurse_matching => ['recurse']], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | result_naked => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | result => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | schema => 'array', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub complete_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete_path: not called CC=65 SCAR=83.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | require Complete::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $word = $args{word} // ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"word"} // ""
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | my $path_sep = $args{path_sep} // '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"path_sep"} // "/"
MC/DC0%0/1
$args{"path_sep"} // "/"
$args{"path_sep"}
Truth table0%0/2
A
A= $args{"path_sep"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $list_func = $args{list_func}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $is_dir_func = $args{is_dir_func}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $filter_func = $args{filter_func}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $result_prefix = $args{result_prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my $starting_path = $args{starting_path} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"starting_path"} // ""
MC/DC0%0/1
$args{"starting_path"} // ""
$args{"starting_path"}
Truth table0%0/2
A
A= $args{"starting_path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $recurse = $args{recurse}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $recurse_matching = $args{recurse_matching} // 'level-by-level'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"recurse_matching"} // "level-by-level"
MC/DC0%0/1
$args{"recurse_matching"} // "level-by-level"
$args{"recurse_matching"}
Truth table0%0/2
A
A= $args{"recurse_matching"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $exclude_leaf = $args{exclude_leaf}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $exclude_dir = $args{exclude_dir}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $ci = $Complete::Common::OPT_CI; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $word_mode = $Complete::Common::OPT_WORD_MODE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $fuzzy = $Complete::Common::OPT_FUZZY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $map_case = $Complete::Common::OPT_MAP_CASE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $exp_im_path = $Complete::Common::OPT_EXP_IM_PATH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $dig_leaf = $Complete::Common::OPT_DIG_LEAF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $re_ends_with_path_sep = qr!\A\z|\Q$path_sep\E\z!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | my $cut_chars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (defined $args{_cut_chars}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $cut_chars = $args{_cut_chars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $cut_chars = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if (length($starting_path)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $cut_chars += length($starting_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | unless ($starting_path =~ /\Q$path_sep\E\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $cut_chars += length($path_sep); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | RECURSE_MATCHING_ALL_AT_ONCE: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # recurse matching all-at-once is way simpler, we just need to collect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # all the nodes, then complate against it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | last unless $recurse && $recurse_matching eq 'all-at-once'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$recurse and $recurse_matching eq "all-at-once"
MC/DC0%0/2
$recurse and $recurse_matching eq "all-at-once"
$recurse
$recurse_matching eq "all-at-once"
Truth table0%0/3
A and B
A= $recurseB= $recurse_matching eq "all-at-once"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my @dirs = ($starting_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | while (@dirs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $dir = shift @dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $listres = $list_func->($dir, '', 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | next unless $listres && @$listres; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$listres and @$listres
MC/DC0%0/2
$listres and @$listres
$listres
@$listres
Truth table0%0/3
A and B
A= $listresB= @$listres
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | L1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | for my $e (@$listres) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $p = $dir =~ $re_ends_with_path_sep ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | "$dir$e" : "$dir$path_sep$e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | local $_ = $p; # convenience for filter func | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | next L1 if $filter_func && !$filter_func->($p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter_func and not &$filter_func($p)
MC/DC0%0/2
$filter_func and not &$filter_func($p)
$filter_func
not &$filter_func($p)
Truth table0%0/3
A and not(B)
A= $filter_funcB= not &$filter_func($p)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $is_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($e =~ $re_ends_with_path_sep) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $is_dir = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | local $_ = $p; # convenience for is_dir_func | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $is_dir = $is_dir_func->($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ($is_dir) { push @dirs, $p } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # format result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | $p = "$result_prefix$p" if length($result_prefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | substr($p, 0, $cut_chars) = '' if $cut_chars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | unless ($p =~ /\Q$path_sep\E\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $p .= $path_sep if $is_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | push @res, $p unless ($is_dir && $exclude_dir) || (!$is_dir && $exclude_leaf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$is_dir and $exclude_dir or not $is_dir and $exclude_leaf
$is_dir and $exclude_dir
not $is_dir and $exclude_leaf
MC/DC0%0/4
$is_dir and $exclude_dir or not $is_dir and $exclude_leaf
$is_dir
$exclude_dir
not $is_dir
$exclude_leaf
Truth table0%0/7
A and B or not(C) and D
A= $is_dirB= $exclude_dirC= not $is_dirD= $exclude_leaf
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } # entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } # while dirs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | @res = @{ Complete::Util::complete_array_elem( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | array => \@res, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | word => $word, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | goto RETURN_RESULT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # split word by into path elements, as we want to dig level by level (needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # when doing case-insensitive search on a case-sensitive tree). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my @intermediate_dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | @intermediate_dirs = split qr/\Q$path_sep/, $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | @intermediate_dirs = ('') if !@intermediate_dirs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | push @intermediate_dirs, '' if $word =~ $re_ends_with_path_sep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # extract leaf path, because this one is treated differently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $leaf = pop @intermediate_dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | @intermediate_dirs = ('') if !@intermediate_dirs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | #say "D:starting_path=<$starting_path>"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | #say "D:intermediate_dirs=[",join(", ", map{"<$_>"} @intermediate_dirs),"]"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | #say "D:leaf=<$leaf>"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # candidate for intermediate paths. when doing case-insensitive search, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # there maybe multiple candidate paths for each dir, for example if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # word='../foo/s' and there is '../foo/Surya', '../Foo/sri', '../FOO/SUPER' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # then candidate paths would be ['../foo', '../Foo', '../FOO'] and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # filename should be searched inside all those dirs. everytime we drill down | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # to deeper subdirectories, we adjust this list by removing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # no-longer-eligible candidates. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my @candidate_paths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | for my $i (0..$#intermediate_dirs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $intdir = $intermediate_dirs[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $intdir_with_path_sep = "$intdir$path_sep"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my @dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($i == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # first path elem, we search starting_path first since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # candidate_paths is still empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | @dirs = ($starting_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # subsequent path elem, we search all candidate_paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | @dirs = @candidate_paths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ($i == $#intermediate_dirs && $intdir eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i == $#intermediate_dirs and $intdir eq ""
MC/DC0%0/2
$i == $#intermediate_dirs and $intdir eq ""
$i == $#intermediate_dirs
$intdir eq ""
Truth table0%0/3
A and B
A= $i == $#intermediate_dirsB= $intdir eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | @candidate_paths = @dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my @new_candidate_paths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | for my $dir (@dirs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | #say "D: intdir list($dir)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $listres = $list_func->($dir, $intdir, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | next unless $listres && @$listres; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$listres and @$listres
MC/DC0%0/2
$listres and @$listres
$listres
@$listres
Truth table0%0/3
A and B
A= $listresB= @$listres
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | #use DD; say "D: list res=", DD::dump($listres); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $matches = Complete::Util::complete_array_elem( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | word => $intdir, array => $listres, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | my $exact_matches = [grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | $_ eq $intdir || $_ eq $intdir_with_path_sep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ eq $intdir || $_ eq $intdir_with_path_sep
MC/DC0%0/2
$_ eq $intdir || $_ eq $intdir_with_path_sep
$_ eq $intdir
$_ eq $intdir_with_path_sep
Truth table0%0/3
A || B
A= $_ eq $intdirB= $_ eq $intdir_with_path_sep
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } @$matches]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | #use Data::Dmp; say "D: word=<$intdir>, matches=", dmp($matches), ", exact_matches=", dmp($exact_matches); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # when doing exp_im_path, check if we have a single exact match. in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # that case, don't use all the candidates because that can be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # annoying, e.g. you have 'a/foo' and 'and/food', you won't be able | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # to complete 'a/f' because bash (e.g.) will always cut the answer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # to 'a' because the candidates are 'a/foo' and 'and/foo' (it will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # use the shortest common string which is 'a'). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | #say "D: num_exact_matches: ", scalar @$exact_matches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if (!$exp_im_path || @$exact_matches == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $exp_im_path or @$exact_matches == 1
MC/DC0%0/2
not $exp_im_path or @$exact_matches == 1
not $exp_im_path
@$exact_matches == 1
Truth table0%0/3
not(A) or B
A= not $exp_im_pathB= @$exact_matches == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $matches = $exact_matches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | for (@$matches) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | my $p = $dir =~ $re_ends_with_path_sep ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | "$dir$_" : "$dir$path_sep$_"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | push @new_candidate_paths, $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | #say "D: candidate_paths=[",join(", ", map{"<$_>"} @new_candidate_paths),"]"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | return [] unless @new_candidate_paths; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | @candidate_paths = @new_candidate_paths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | log_trace "[comppath] candidate paths: %s", \@candidate_paths if $ENV{COMPLETE_PATH_TRACE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | for my $dir (@candidate_paths) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | #say "D:opendir($dir)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my $listres = $list_func->($dir, $leaf, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | next unless $listres && @$listres; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$listres and @$listres
MC/DC0%0/2
$listres and @$listres
$listres
@$listres
Truth table0%0/3
A and B
A= $listresB= @$listres
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $matches = Complete::Util::complete_array_elem( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | word => $leaf, array => $listres, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | #use DD; dd $matches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | L1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | for my $e (@$matches) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | my $p = $dir =~ $re_ends_with_path_sep ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | "$dir$e" : "$dir$path_sep$e"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | local $_ = $p; # convenience for filter func | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | next L1 if $filter_func && !$filter_func->($p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter_func and not &$filter_func($p)
MC/DC0%0/2
$filter_func and not &$filter_func($p)
$filter_func
not &$filter_func($p)
Truth table0%0/3
A and not(B)
A= $filter_funcB= not &$filter_func($p)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $is_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ($e =~ $re_ends_with_path_sep) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $is_dir = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | local $_ = $p; # convenience for is_dir_func | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $is_dir = $is_dir_func->($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my @subres; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ($is_dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($recurse) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | @subres = @{complete_path( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | %args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | starting_path => $p, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | word => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | _cut_chars => $cut_chars, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | )}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } elsif ($dig_leaf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | DIG_LEAF: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $p2 = _dig_leaf($p, $list_func, $is_dir_func, $filter_func, $path_sep); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | last DIG_LEAF if $p2 eq $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $p = $p2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | #say "D:p=$p (dig_leaf)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # check again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ($p =~ $re_ends_with_path_sep) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $is_dir = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | local $_ = $p; # convenience for is_dir_func | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $is_dir = $is_dir_func->($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } # DIG_LEAF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # process into final result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $p0 = $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | substr($p, 0, $cut_chars) = '' if $cut_chars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | $p = "$result_prefix$p" if length($result_prefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | unless ($p =~ /\Q$path_sep\E\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | $p .= $path_sep if $is_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | push @res, $p unless ($is_dir && $exclude_dir) || (!$is_dir && $exclude_leaf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$is_dir and $exclude_dir or not $is_dir and $exclude_leaf
$is_dir and $exclude_dir
not $is_dir and $exclude_leaf
MC/DC0%0/4
$is_dir and $exclude_dir or not $is_dir and $exclude_leaf
$is_dir
$exclude_dir
not $is_dir
$exclude_leaf
Truth table0%0/7
A and B or not(C) and D
A= $is_dirB= $exclude_dirC= not $is_dirD= $exclude_leaf
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | push @res, @subres; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | RETURN_RESULT: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | \@res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # ABSTRACT: Complete path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||