| 1 | 11 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use Object::Pad; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | class Getopt::Pad::Completion :strict(params) { | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use constant SHELLS => ['bash', 'zsh']; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use constant SHELL_VARIABLE => 'GETOPT_PAD_COMPLETE'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use constant INDEX_VARIABLE => 'GETOPT_PAD_COMPLETE_INDEX'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # The answer to one request starts with a directive line telling the | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # shell which of its own completions to add (files, dirs or none), | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # followed by one candidate per line. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use constant NO_DIRECTIVE => 'none'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | field $spec :param; | |||||||||||||||||||||||||||||||||||||||||
| 21 | field $programName :param = undef; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ADJUST { | |||||||||||||||||||||||||||||||||||||||||
| 24 | $programName //= basename($0); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # The shell scripts are thin: on every tab they run the program with | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # SHELL_VARIABLE set, the index of the word under the cursor in | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # INDEX_VARIABLE, and the words after the program name as arguments, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # and print what comes back. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | my %scriptTemplate = ( | |||||||||||||||||||||||||||||||||||||||||
| 32 | bash => <<'BASH', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # bash completion for {{prog}}, generated by Getopt::Pad. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # Install it as ~/.local/share/bash-completion/completions/{{prog}} or | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # source it from your ~/.bashrc: | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # {{prog}} --create-completions bash > ~/.local/share/bash-completion/completions/{{prog}} | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | _{{ident}}_completion() { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | local -a words=() | ||||||||||||||||||||||||||||||||||||||||||
| 40 | local cword=0 index word join=0 | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Bash splits words at '=' (COMP_WORDBREAKS); glue --name=value back together. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | for ((index = 0; index < ${#COMP_WORDS[@]}; index++)); do | ||||||||||||||||||||||||||||||||||||||||||
| 44 | word=${COMP_WORDS[index]} | ||||||||||||||||||||||||||||||||||||||||||
| 45 | if [[ $word == '=' && ${#words[@]} -gt 0 ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| 46 | words[${#words[@]}-1]+='=' | ||||||||||||||||||||||||||||||||||||||||||
| 47 | join=1 | ||||||||||||||||||||||||||||||||||||||||||
| 48 | elif (( join )); then | ||||||||||||||||||||||||||||||||||||||||||
| 49 | words[${#words[@]}-1]+=$word | ||||||||||||||||||||||||||||||||||||||||||
| 50 | join=0 | ||||||||||||||||||||||||||||||||||||||||||
| 51 | else | ||||||||||||||||||||||||||||||||||||||||||
| 52 | words+=("$word") | ||||||||||||||||||||||||||||||||||||||||||
| 53 | fi | ||||||||||||||||||||||||||||||||||||||||||
| 54 | (( index == COMP_CWORD )) && cword=$(( ${#words[@]} - 1 )) | ||||||||||||||||||||||||||||||||||||||||||
| 55 | done | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # A read loop: bash 3.2 has no builtin that reads lines into an array. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | local -a lines=() | ||||||||||||||||||||||||||||||||||||||||||
| 59 | local line | ||||||||||||||||||||||||||||||||||||||||||
| 60 | while IFS= read -r line; do | ||||||||||||||||||||||||||||||||||||||||||
| 61 | lines+=("$line") | ||||||||||||||||||||||||||||||||||||||||||
| 62 | done < <({{shellVariable}}=bash {{indexVariable}}=$(( cword - 1 )) "${words[0]}" "${words[@]:1}" 2>/dev/null) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # The program answers with whole words; bash only replaces the part | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # after the last '=', so strip what it keeps. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | local directive=${lines[0]} | ||||||||||||||||||||||||||||||||||||||||||
| 67 | local cur=${COMP_WORDS[COMP_CWORD]} | ||||||||||||||||||||||||||||||||||||||||||
| 68 | local prefix=${words[cword]%"$cur"} | ||||||||||||||||||||||||||||||||||||||||||
| 69 | COMPREPLY=("${lines[@]:1}") | ||||||||||||||||||||||||||||||||||||||||||
| 70 | COMPREPLY=("${COMPREPLY[@]#"$prefix"}") | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # Set only now: bash 3.2 joins the quoted array expansions above | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # into one word when IFS lacks a space. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | local IFS=$'\n' | ||||||||||||||||||||||||||||||||||||||||||
| 75 | case $directive in | ||||||||||||||||||||||||||||||||||||||||||
| 76 | files) compopt -o filenames 2>/dev/null; COMPREPLY+=($(compgen -f -- "$cur")) ;; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | dirs) compopt -o filenames 2>/dev/null; COMPREPLY+=($(compgen -d -- "$cur")) ;; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | esac | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | complete -F _{{ident}}_completion {{prog}} | ||||||||||||||||||||||||||||||||||||||||||
| 82 | BASH | ||||||||||||||||||||||||||||||||||||||||||
| 83 | zsh => <<'ZSH', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | #compdef {{prog}} | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # zsh completion for {{prog}}, generated by Getopt::Pad. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # Install it as _{{prog}} in a directory on your $fpath or source it from | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # your ~/.zshrc: | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # {{prog}} --create-completions zsh > ~/.zsh/completions/_{{prog}} | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | _{{ident}}_completion() { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | local -a lines | ||||||||||||||||||||||||||||||||||||||||||
| 92 | lines=("${(@f)$({{shellVariable}}=zsh {{indexVariable}}=$(( CURRENT - 2 )) "${words[1]}" "${(@)words[2,-1]}" 2>/dev/null)}") | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | local directive=${lines[1]} | ||||||||||||||||||||||||||||||||||||||||||
| 95 | shift lines | ||||||||||||||||||||||||||||||||||||||||||
| 96 | (( ${#lines} )) && compadd -- "${lines[@]}" | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | case $directive in | ||||||||||||||||||||||||||||||||||||||||||
| 99 | files) compset -P '*='; _files ;; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | dirs) compset -P '*='; _files -/ ;; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | esac | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | if [[ $zsh_eval_context[-1] == loadautofunc ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| 105 | _{{ident}}_completion "$@" | ||||||||||||||||||||||||||||||||||||||||||
| 106 | else | ||||||||||||||||||||||||||||||||||||||||||
| 107 | compdef _{{ident}}_completion {{prog}} | ||||||||||||||||||||||||||||||||||||||||||
| 108 | fi | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ZSH | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | ▶ | method renderScript($shell) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
renderScript: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | my $template = $scriptTemplate{$shell // ''} // croak(sprintf("Getopt::Pad: no completion script for shell '%s'", $shell // '')); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$scriptTemplate{$shell // ""} // croak(sprintf("Getopt::Pad: no completion script for shell '%s'", $shell // ""))
$shell // ""
$shell // ""
MC/DC100%1/1
$scriptTemplate{$shell // ""} // croak(sprintf("Getopt::Pad: no completion script for shell '%s'", $shell // ""))
$scriptTemplate{$shell // ""}
MC/DC0%0/1
$shell // ""
$shell
MC/DC0%0/1
$shell // ""
$shell
Truth table100%2/2
A
A= $scriptTemplate{$shell // ""}
Truth table50%1/2
A
A= $shell
Truth table50%1/2
A
A= $shell
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | my %vars = ( | |||||||||||||||||||||||||||||||||||||||||
| 115 | prog => $programName, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ident => $programName =~ s/\W/_/gr, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | shellVariable => SHELL_VARIABLE, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | indexVariable => INDEX_VARIABLE, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | return $template =~ s/\{\{(\w+)\}\}/$vars{$1}/gr; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | method renderCandidates($words, $index) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
renderCandidates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | return join("\n", $self->candidates($words, $index)) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # The directive and the candidates for the word at $index of the | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # command line $words (the words after the program name). The word | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # under the cursor may be partial or missing; the words before it | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # decide the Level, and whether an Option is waiting for its value. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 33 | ▶ | method candidates($words, $index) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
candidates: called CC=22 SCAR=31.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 33 | ▶ | croak(sprintf('Getopt::Pad: the completion index must be a non-negative integer, not %s', $index // 'undef')) if ($index // '') !~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$index // ""
$index // "undef"
MC/DC0%0/1
$index // ""
$index
MC/DC0%0/1
$index // "undef"
$index
Truth table50%1/2
A
A= $index
Truth table50%1/2
A
A= $index
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 32 | ▶ | my $current = $words->[$index] // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$words->[$index] // ""
MC/DC0%0/1
$words->[$index] // ""
$words->[$index]
Truth table50%1/2
A
A= $words->[$index]
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 32 | ▶ | my $state = $self->walk([$words->@[0 .. min($index, scalar $words->@*) - 1]]) // return (NO_DIRECTIVE); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->walk([@$words[0 .. &min($index, scalar @$words) - 1]]) // (return "none")
MC/DC100%1/1
$self->walk([@$words[0 .. &min($index, scalar @$words) - 1]]) // (return "none")
$self->walk([@$words[0 .. &min($index, scalar @$words) - 1]])
Truth table100%2/2
A
A= $self->walk([@$words[0 .. &min($index, scalar @$words) - 1]])
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 31 | my $level = $state->{level}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 31 | my $pending = $state->{valueOption}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 31 | ▶ | return $self->valueCandidates($pending, $current, '') if defined $pending && !($pending->optionalValue && $current =~ /^-/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $pending and not $pending->optionalValue && $current =~ /^-/u
$pending->optionalValue && $current =~ /^-/u
MC/DC33%1/3
defined $pending and not $pending->optionalValue && $current =~ /^-/u
defined $pending
$pending->optionalValue
$current =~ /^-/u
Truth table50%2/4
A and not(B && C)
A= defined $pendingB= $pending->optionalValueC= $current =~ /^-/u
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 17 | ▶ | if (!$state->{optionsEnded} && $current =~ /^(--[^=]+)=(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $state->{"optionsEnded"} and $current =~ /^(--[^=]+)=(.*)$/su
MC/DC100%2/2
not $state->{"optionsEnded"} and $current =~ /^(--[^=]+)=(.*)$/su
not $state->{"optionsEnded"}
$current =~ /^(--[^=]+)=(.*)$/su
Truth table100%3/3
not(A) and B
A= not $state->{"optionsEnded"}B= $current =~ /^(--[^=]+)=(.*)$/su
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my ($spelling, $partial) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | my $option = $self->longOption($level, $spelling) // return (NO_DIRECTIVE); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->longOption($level, $spelling) // (return "none")
MC/DC0%0/1
$self->longOption($level, $spelling) // (return "none")
$self->longOption($level, $spelling)
Truth table50%1/2
A
A= $self->longOption($level, $spelling)
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | return (NO_DIRECTIVE) if !$option->type->takesValue; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | return $self->valueCandidates($option, $partial, $spelling . '='); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | ▶ | return $self->optionCandidates($level, $current) if !$state->{optionsEnded} && $current =~ /^-/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $state->{"optionsEnded"} and $current =~ /^-/u
MC/DC100%2/2
not $state->{"optionsEnded"} and $current =~ /^-/u
not $state->{"optionsEnded"}
$current =~ /^-/u
Truth table100%3/3
not(A) and B
A= not $state->{"optionsEnded"}B= $current =~ /^-/u
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 10 | ▶ | return (NO_DIRECTIVE, grep { $self->startsWith($_, $current) } $level->commandNames) if $level->hasCommands; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | my @args = $level->args; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | ▶ | my $arg = $args[$state->{positionals}] // (@args && $args[-1]->multiple ? $args[-1] : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$args[$state->{"positionals"}] // (@args && $args[-1]->multiple ? $args[-1] : undef)
@args and $args[-1]->multiple
MC/DC66%2/3
$args[$state->{"positionals"}] // (@args && $args[-1]->multiple ? $args[-1] : undef)
$args[$state->{"positionals"}]
@args
$args[-1]->multiple
Truth table75%3/4
A // B and C
A= $args[$state->{"positionals"}]B= @argsC= $args[-1]->multiple
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | ▶ | return ($arg->type->completes // NO_DIRECTIVE) if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$arg->type->completes // "none"
MC/DC100%1/1
$arg->type->completes // "none"
$arg->type->completes
Truth table100%2/2
A
A= $arg->type->completes
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | ▶ | return $state->{optionsEnded} ? (NO_DIRECTIVE) : $self->optionCandidates($level, $current); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # Replay the finished words: descend into the named commands, count the | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # positionals, and remember an Option that still waits for its value. | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # Returns undef when the words name an unknown command. | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 32 | ▶ | method walk($words) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walk: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 32 | my %state = (level => $spec->root, positionals => 0, optionsEnded => 0, valueOption => undef); | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 32 | foreach my $word ($words->@*) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 47 | my $pending = delete $state{valueOption}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 47 | ▶ | next if defined $pending && !($pending->optionalValue && $word =~ /^-/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $pending and not $pending->optionalValue && $word =~ /^-/u
$pending->optionalValue && $word =~ /^-/u
MC/DC33%1/3
defined $pending and not $pending->optionalValue && $word =~ /^-/u
defined $pending
$pending->optionalValue
$word =~ /^-/u
Truth table50%2/4
A and not(B && C)
A= defined $pendingB= $pending->optionalValueC= $word =~ /^-/u
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 46 | ▶ | if (!$state{optionsEnded} && $word eq '--') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $state{"optionsEnded"} and $word eq "--"
MC/DC50%1/2
not $state{"optionsEnded"} and $word eq "--"
not $state{"optionsEnded"}
$word eq "--"
Truth table66%2/3
not(A) and B
A= not $state{"optionsEnded"}B= $word eq "--"
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $state{optionsEnded} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 45 | ▶ | if (!$state{optionsEnded} && $word =~ /^-/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $state{"optionsEnded"} and $word =~ /^-/u
MC/DC50%1/2
not $state{"optionsEnded"} and $word =~ /^-/u
not $state{"optionsEnded"}
$word =~ /^-/u
Truth table66%2/3
not(A) and B
A= not $state{"optionsEnded"}B= $word =~ /^-/u
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 17 | $state{valueOption} = $self->optionAwaitingValue($state{level}, $word); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 17 | next; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 28 | ▶ | if ($state{level}->hasCommands) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 24 | ▶ | $state{level} = $state{level}->command($word) // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state{"level"}->command($word) // (return undef)
MC/DC100%1/1
$state{"level"}->command($word) // (return undef)
$state{"level"}->command($word)
Truth table100%2/2
A
A= $state{"level"}->command($word)
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 23 | next; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | $state{positionals}++; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 31 | return \%state; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # The Option that takes the word after $word as its value, or undef when | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # the word carries its value itself, is a flag, or is unknown. | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 17 | ▶ | method optionAwaitingValue($level, $word) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optionAwaitingValue: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 17 | ▶ | return undef if $word =~ /^--[^=]+=/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 17 | ▶ | if ($word =~ /^--/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 14 | ▶ | my $option = $self->longOption($level, $word) // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->longOption($level, $word) // (return undef)
MC/DC0%0/1
$self->longOption($level, $word) // (return undef)
$self->longOption($level, $word)
Truth table50%1/2
A
A= $self->longOption($level, $word)
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 14 | ▶ | return $option->type->takesValue ? $option : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | # A cluster of single-letter names: the first one taking a value | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # swallows the rest of the cluster, or the next word if none is left. | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | my @letters = split //, substr($word, 1); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | foreach my $position (0 .. $#letters) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | ▶ | my $option = $self->optionBySpelling($level, $letters[$position]) // next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->optionBySpelling($level, $letters[$position]) // (next)
MC/DC0%0/1
$self->optionBySpelling($level, $letters[$position]) // (next)
$self->optionBySpelling($level, $letters[$position])
Truth table50%1/2
A
A= $self->optionBySpelling($level, $letters[$position])
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | next if !$option->type->takesValue; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | return $position == $#letters ? $option : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 16 | ▶ | method longOption($level, $spelling) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
longOption: called CC=4 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 16 | my $name = $spelling =~ s/^--//r; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 16 | ▶ | return $self->optionBySpelling($level, $name) // do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->optionBySpelling($level, $name) // do {
my $negated = $name =~ s/^no-//ru;
my $option = $self->optionBySpelling($level, $negated);
defined $option && $option->negatable ? $option : undef
}
MC/DC0%0/2
$self->optionBySpelling($level, $name) // do {
my $negated = $name =~ s/^no-//ru;
my $option = $self->optionBySpelling($level, $negated);
defined $option && $option->negatable ? $option : undef
}
$self->optionBySpelling($level, $name)
do {
my $negated = $name =~ s/^no-//ru;
my $option = $self->optionBySpelling($level, $negated);
defined $option && $option->negatable ? $option : undef
}
Truth table33%1/3
A // B
A= $self->optionBySpelling($level, $name)B= do {
my $negated = $name =~ s/^no-//ru;
my $option = $self->optionBySpelling($level, $negated);
defined $option && $option->negatable ? $option : undef
}
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $negated = $name =~ s/^no-//r; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $option = $self->optionBySpelling($level, $negated); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | defined $option && $option->negatable ? $option : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $option and $option->negatable
MC/DC0%0/2
defined $option and $option->negatable
defined $option
$option->negatable
Truth table0%0/3
A and B
A= defined $optionB= $option->negatable
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 20 | ▶ | method optionBySpelling($level, $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optionBySpelling: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 20 | foreach my $option ($level->options) { | |||||||||||||||||||||||||||||||||||||||||
| 215 | 74 | ▶ | return $option if grep { $_ eq $name } $option->name, $option->aliases; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | ▶ | method optionCandidates($level, $partial) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optionCandidates: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | my @spellings; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 8 | foreach my $option (grep { !$_->hidden } $level->options) { | |||||||||||||||||||||||||||||||||||||||||
| 223 | 35 | foreach my $name ($option->name, $option->aliases) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 50 | ▶ | push @spellings, length $name == 1 ? "-$name" : "--$name"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 50 | ▶ | push @spellings, "--no-$name" if $option->negatable && length $name > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$option->negatable and length $name > 1
MC/DC100%2/2
$option->negatable and length $name > 1
$option->negatable
length $name > 1
Truth table100%3/3
A and B
A= $option->negatableB= length $name > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | return (NO_DIRECTIVE, sort grep { $self->startsWith($_, $partial) } @spellings); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # A pair-taking option's value is key=value, a csv option's a,b,...; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # the candidates fill in the value behind what the user has typed. | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 16 | ▶ | method valueCandidates($option, $partial, $prefix) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valueCandidates: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 16 | ▶ | if ($option->takesPairs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 4 | ▶ | return (NO_DIRECTIVE) if $partial !~ /^([^=]*=)(.*)$/s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | ($prefix, $partial) = ($prefix . $1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 15 | ▶ | if ($option->csv && $partial =~ /^(.*,)(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$option->csv and $partial =~ /^(.*,)(.*)$/su
MC/DC100%2/2
$option->csv and $partial =~ /^(.*,)(.*)$/su
$option->csv
$partial =~ /^(.*,)(.*)$/su
Truth table100%3/3
A and B
A= $option->csvB= $partial =~ /^(.*,)(.*)$/su
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ($prefix, $partial) = ($prefix . $1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 15 | ▶ | my $directive = $option->type->completes // NO_DIRECTIVE; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option->type->completes // "none"
MC/DC100%1/1
$option->type->completes // "none"
$option->type->completes
Truth table100%2/2
A
A= $option->type->completes
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 15 | return ($directive, map { $prefix . $_ } sort grep { $self->startsWith($_, $partial) } $option->validValues); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 93 | ▶ | method startsWith($string, $prefix) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startsWith: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 93 | ▶ | return index($string, $prefix) == 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 11 | } | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | __END__ | ||||||||||||||||||||||||||||||||||||||||||