| 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::Help :strict(params) { | ||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Feature::Compat::Try; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Getopt::Pad::Util qw(useColor optionSpelling encodedFor); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Text::Wrap (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 11 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 11 | field $level :param; | |||||||||||||||||||||||||||||||
| 14 | field $version :param = undef; | ||||||||||||||||||||||||||||||||
| 15 | 11 | field $programName :param = undef; | |||||||||||||||||||||||||||||||
| 16 | 11 | field $width :param = undef; | |||||||||||||||||||||||||||||||
| 17 | 11 | field $color :param = undef; | |||||||||||||||||||||||||||||||
| 18 | 11 | field $handle :param = \*STDOUT; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 11 | field @commandPath; | |||||||||||||||||||||||||||||||
| 21 | 11 | field $labelWidth; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | ADJUST { | ||||||||||||||||||||||||||||||||
| 24 | $programName //= basename($0); | ||||||||||||||||||||||||||||||||
| 25 | @commandPath = split ' ', $level->path; | ||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | # The terminal is consulted when something is rendered, not when the | ||||||||||||||||||||||||||||||||
| 29 | # Helper is built: a parse builds one per Level without printing, and | ||||||||||||||||||||||||||||||||
| 30 | # $result->help may run much later, on a terminal of another size. | ||||||||||||||||||||||||||||||||
| 31 | 77 | ▶ | method width() { return $width //= $self->detectWidth } | ||||||||||||||||||||||||||||||
|
Subroutine
width: called CC=2 SCAR=7.0
Pod
documented
Condition66%2/3
$width //= $self->detectWidth
MC/DC0%0/2
$width //= $self->detectWidth
$width
$self->detectWidth
Truth table66%2/3
A //= B
A= $widthB= $self->detectWidth
| |||||||||||||||||||||||||||||||||
| 32 | 338 | ▶ | method color() { return $color //= useColor($handle) } | ||||||||||||||||||||||||||||||
|
Subroutine
color: called CC=2 SCAR=7.0
Pod
documented
Condition66%2/3
$color //= useColor($handle)
MC/DC0%0/2
$color //= useColor($handle)
$color
useColor($handle)
Truth table66%2/3
A //= B
A= $colorB= useColor($handle)
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 357 | ▶ | method labelWidth() { | ||||||||||||||||||||||||||||||
|
Subroutine
labelWidth: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 35 | 357 | ▶ | return $labelWidth //= do { | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$labelWidth //= do {
my(@labels) = (map({$self->optionLabel($_);} grep({not $_->hidden;} $level->options)), map({$self->argLabel($_);} $level->args), $level->commandNames);
3 + &max(0, map({length $_;} @labels)) + 5
}
MC/DC0%0/2
$labelWidth //= do {
my(@labels) = (map({$self->optionLabel($_);} grep({not $_->hidden;} $level->options)), map({$self->argLabel($_);} $level->args), $level->commandNames);
3 + &max(0, map({length $_;} @labels)) + 5
}
$labelWidth
do {
my(@labels) = (map({$self->optionLabel($_);} grep({not $_->hidden;} $level->options)), map({$self->argLabel($_);} $level->args), $level->commandNames);
3 + &max(0, map({length $_;} @labels)) + 5
}
Truth table66%2/3
A //= B
A= $labelWidthB= do {
my(@labels) = (map({$self->optionLabel($_);} grep({not $_->hidden;} $level->options)), map({$self->argLabel($_);} $level->args), $level->commandNames);
3 + &max(0, map({length $_;} @labels)) + 5
}
| |||||||||||||||||||||||||||||||||
| 36 | 21 | my @labels = ((map { $self->optionLabel($_) } grep { !$_->hidden } $level->options), (map { $self->argLabel($_) } $level->args), $level->commandNames); | |||||||||||||||||||||||||||||||
| 37 | 21 | 3 + max(0, map { length } @labels) + 5; | |||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||
| 39 | 11 | } | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | method detectWidth() { | ||||||||||||||||||||||||||||||
|
Subroutine
detectWidth: called CC=6 SCAR=21.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | return $ENV{COLUMNS} if ($ENV{COLUMNS} // '') =~ /^\d+$/ && $ENV{COLUMNS} > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
($ENV{"COLUMNS"} // "") =~ /^\d+$/u and $ENV{"COLUMNS"} > 0
$ENV{"COLUMNS"} // ""
MC/DC50%1/2
($ENV{"COLUMNS"} // "") =~ /^\d+$/u and $ENV{"COLUMNS"} > 0
$ENV{"COLUMNS"}
$ENV{"COLUMNS"} > 0
Truth table66%2/3
A and B
A= $ENV{"COLUMNS"}B= $ENV{"COLUMNS"} > 0
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | if (-t $handle) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | try { | |||||||||||||||||||||||||||||||
| 46 | 0 | require Term::ReadKey; | |||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | local $SIG{__WARN__} = sub { }; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 48 | 0 | my ($columns) = Term::ReadKey::GetTerminalSize($handle); | |||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $columns if $columns; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | catch ($error) { } | ||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 2 | return 100; | |||||||||||||||||||||||||||||||
| 55 | 11 | } | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 230 | ▶ | method paint($text, $ansiCode) { | ||||||||||||||||||||||||||||||
|
Subroutine
paint: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 58 | 230 | ▶ | return $self->color ? sprintf("\e[%sm%s\e[0m", $ansiCode, $text) : $text; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 11 | } | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | method printHelp() { | ||||||||||||||||||||||||||||||
|
Subroutine
printHelp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 62 | 0 | print {$handle} encodedFor($handle, $self->renderHelp); | |||||||||||||||||||||||||||||||
| 63 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 64 | 11 | } | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | method printVersion() { | ||||||||||||||||||||||||||||||
|
Subroutine
printVersion: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 67 | 0 | print {$handle} encodedFor($handle, $self->renderVersion . "\n"); | |||||||||||||||||||||||||||||||
| 68 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 69 | 11 | } | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 3 | ▶ | method renderVersion() { | ||||||||||||||||||||||||||||||
|
Subroutine
renderVersion: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | my $shown = $version // $main::VERSION // 'unknown'; | ||||||||||||||||||||||||||||||
|
Condition80%4/5
($version // $main::VERSION) // "unknown"
$version // $main::VERSION
MC/DC50%1/2
($version // $main::VERSION) // "unknown"
$version
$main::VERSION
Truth table66%2/3
A // B
A= $versionB= $main::VERSION
| |||||||||||||||||||||||||||||||||
| 73 | 3 | return sprintf('%s %s', $programName, $shown); | |||||||||||||||||||||||||||||||
| 74 | 11 | } | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 23 | ▶ | method renderHelp() { | ||||||||||||||||||||||||||||||
|
Subroutine
renderHelp: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 77 | 23 | my @visibleOptions = grep { !$_->hidden } $level->options; | |||||||||||||||||||||||||||||||
| 78 | 23 | my @args = $level->args; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 23 | my @blocks = ($self->headerBlock(\@visibleOptions, \@args)); | |||||||||||||||||||||||||||||||
| 81 | 23 | ▶ | push @blocks, $self->argsBlock(\@args) if @args; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | 23 | ▶ | push @blocks, $self->optionBlocks(\@visibleOptions) if @visibleOptions; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 23 | ▶ | push @blocks, $self->commandsBlock if $level->hasCommands; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 23 | ▶ | push @blocks, $self->examplesBlock if $level->examples; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 23 | return join("\n\n", @blocks) . "\n"; | |||||||||||||||||||||||||||||||
| 87 | 11 | } | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 11 | my %palette = ( | |||||||||||||||||||||||||||||||
| 90 | usage => '1;31', | ||||||||||||||||||||||||||||||||
| 91 | description => '94', | ||||||||||||||||||||||||||||||||
| 92 | section => '92', | ||||||||||||||||||||||||||||||||
| 93 | annotation => '31', | ||||||||||||||||||||||||||||||||
| 94 | typeLabel => '90', | ||||||||||||||||||||||||||||||||
| 95 | subKey => '33', | ||||||||||||||||||||||||||||||||
| 96 | validValue => '36', | ||||||||||||||||||||||||||||||||
| 97 | defaultValue => '35', | ||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 23 | ▶ | method headerBlock($options, $args) { | ||||||||||||||||||||||||||||||
|
Subroutine
headerBlock: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 101 | 23 | my @tokens = ($programName, @commandPath); | |||||||||||||||||||||||||||||||
| 102 | 23 | ▶ | push @tokens, '[options]' if $options->@*; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | 23 | ▶ | push @tokens, '<command>' if $level->hasCommands; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | 23 | foreach my $arg ($args->@*) { | |||||||||||||||||||||||||||||||
| 105 | 9 | my $token = $arg->short; | |||||||||||||||||||||||||||||||
| 106 | 9 | ▶ | $token .= '...' if $arg->multiple; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 9 | ▶ | $token = sprintf('[%s]', $token) if !$arg->required; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | 9 | push @tokens, $token; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 23 | my $block = $self->paint('# ' . join(' ', @tokens), $palette{usage}); | |||||||||||||||||||||||||||||||
| 112 | 23 | ▶ | $block .= "\n" . $self->paint('# ' . $level->description, $palette{description}) if $level->description ne ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 23 | return $block; | |||||||||||||||||||||||||||||||
| 114 | 11 | } | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 57 | ▶ | method sectionHeader($title) { | ||||||||||||||||||||||||||||||
|
Subroutine
sectionHeader: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 117 | 57 | return $self->paint('## ' . $title, $palette{section}); | |||||||||||||||||||||||||||||||
| 118 | 11 | } | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | method argsBlock($args) { | ||||||||||||||||||||||||||||||
|
Subroutine
argsBlock: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 121 | 6 | my @lines = ($self->sectionHeader('Arguments')); | |||||||||||||||||||||||||||||||
| 122 | 6 | foreach my $arg ($args->@*) { | |||||||||||||||||||||||||||||||
| 123 | 9 | my @parts; | |||||||||||||||||||||||||||||||
| 124 | 9 | ▶ | push @parts, ['[REQ]', $palette{annotation}] if $arg->required; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | 9 | push @parts, map { [sprintf('[%s]', $_), $palette{annotation}] } $arg->type->constraintNotes; | |||||||||||||||||||||||||||||||
| 126 | 9 | ▶ | push @parts, [$arg->help, undef] if $arg->help ne ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 127 | 9 | ▶ | push @parts, [sprintf('[%s]', $arg->typeLabel), $palette{typeLabel}] if defined $arg->typeLabel; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 9 | push @lines, $self->entryLines($self->argLabel($arg), \@parts); | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | 6 | return join("\n", @lines); | |||||||||||||||||||||||||||||||
| 131 | 11 | } | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 23 | ▶ | method optionBlocks($options) { | ||||||||||||||||||||||||||||||
|
Subroutine
optionBlocks: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 134 | 23 | my %grouped; | |||||||||||||||||||||||||||||||
| 135 | 23 | push $grouped{$_->group}->@*, $_ foreach $options->@*; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 23 | my @blocks; | |||||||||||||||||||||||||||||||
| 138 | 23 | foreach my $group (sort keys %grouped) { | |||||||||||||||||||||||||||||||
| 139 | 49 | my @lines = ($self->sectionHeader($group)); | |||||||||||||||||||||||||||||||
| 140 | 49 | foreach my $option ($grouped{$group}->@*) { | |||||||||||||||||||||||||||||||
| 141 | 95 | my @parts; | |||||||||||||||||||||||||||||||
| 142 | 95 | ▶ | push @parts, ['[REQ]', $palette{annotation}] if $option->required; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 95 | push @parts, map { [sprintf('[%s]', $_), $palette{annotation}] } $option->type->constraintNotes; | |||||||||||||||||||||||||||||||
| 144 | 95 | ▶ | push @parts, [$option->help, undef] if $option->help ne ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | 95 | ▶ | push @parts, [sprintf('[%s]', $option->typeLabel), $palette{typeLabel}] if defined $option->typeLabel; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | 95 | push @lines, $self->entryLines($self->optionLabel($option), \@parts); | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 95 | my $subIndent = ' ' x ($self->labelWidth + 4); | |||||||||||||||||||||||||||||||
| 149 | push @lines, $subIndent . $self->paint('Valid', $palette{subKey}) | ||||||||||||||||||||||||||||||||
| 150 | 95 | ▶ | . ' = [ ' . join(', ', map { $self->paint($_, $palette{validValue}) } $option->valid->@*) . ' ]' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | if ref $option->valid eq 'ARRAY'; | ||||||||||||||||||||||||||||||||
| 152 | push @lines, $subIndent . $self->paint('Default', $palette{subKey}) | ||||||||||||||||||||||||||||||||
| 153 | . ' = ' . $self->paint($self->stringifyDefault($option->presentedDefault), $palette{defaultValue}) | ||||||||||||||||||||||||||||||||
| 154 | 95 | ▶ | if $self->showsDefault($option); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | 49 | push @blocks, join("\n", @lines); | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | 23 | return @blocks; | |||||||||||||||||||||||||||||||
| 159 | 11 | } | |||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | method commandsBlock() { | ||||||||||||||||||||||||||||||
|
Subroutine
commandsBlock: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 162 | 2 | my @lines = ($self->sectionHeader('Commands')); | |||||||||||||||||||||||||||||||
| 163 | 2 | foreach my $name ($level->commandNames) { | |||||||||||||||||||||||||||||||
| 164 | 4 | push @lines, $self->entryLines($name, [[$level->command($name)->description, undef]]); | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | 2 | return join("\n", @lines); | |||||||||||||||||||||||||||||||
| 167 | 11 | } | |||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | method examplesBlock() { | ||||||||||||||||||||||||||||||
|
Subroutine
examplesBlock: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 170 | 3 | my @lines = ($self->paint('# Examples:', $palette{usage})); | |||||||||||||||||||||||||||||||
| 171 | 3 | foreach my $example ($level->examples) { | |||||||||||||||||||||||||||||||
| 172 | 3 | push @lines, $self->paint('## ' . $example->{text}, $palette{section}); | |||||||||||||||||||||||||||||||
| 173 | 3 | push @lines, $self->paint('##', $palette{section}) . ' ' . join(' ', $programName, @commandPath, $example->{args}); | |||||||||||||||||||||||||||||||
| 174 | 3 | push @lines, ''; | |||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | pop @lines while @lines && $lines[-1] eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@lines and $lines[-1] eq ""
MC/DC50%1/2
@lines and $lines[-1] eq ""
@lines
$lines[-1] eq ""
Truth table66%2/3
A and B
A= @linesB= $lines[-1] eq ""
| |||||||||||||||||||||||||||||||||
| 177 | 3 | return join("\n", @lines); | |||||||||||||||||||||||||||||||
| 178 | 11 | } | |||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | # An undefined default, or an empty list or mapping, is the same as none | ||||||||||||||||||||||||||||||||
| 181 | # to the reader of the help. | ||||||||||||||||||||||||||||||||
| 182 | 95 | ▶ | method showsDefault($option) { | ||||||||||||||||||||||||||||||
|
Subroutine
showsDefault: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 183 | 95 | ▶ | return 0 if !$option->hasDefault; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 22 | my $default = $option->presentedDefault; | |||||||||||||||||||||||||||||||
| 186 | 22 | ▶ | return 0 if !defined $default; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 19 | ▶ | return 0 if ref $default eq 'ARRAY' && !$default->@*; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $default eq "ARRAY" and not @$default
MC/DC100%2/2
ref $default eq "ARRAY" and not @$default
ref $default eq "ARRAY"
not @$default
Truth table100%3/3
A and not(B)
A= ref $default eq "ARRAY"B= not @$default
| |||||||||||||||||||||||||||||||||
| 188 | 18 | ▶ | return 0 if ref $default eq 'HASH' && !$default->%*; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $default eq "HASH" and not %$default
MC/DC100%2/2
ref $default eq "HASH" and not %$default
ref $default eq "HASH"
not %$default
Truth table100%3/3
A and not(B)
A= ref $default eq "HASH"B= not %$default
| |||||||||||||||||||||||||||||||||
| 189 | 17 | return 1; | |||||||||||||||||||||||||||||||
| 190 | 11 | } | |||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 184 | ▶ | method optionLabel($option) { | ||||||||||||||||||||||||||||||
|
Subroutine
optionLabel: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 193 | 184 | my $label = join(', ', $self->optionSpellings($option)); | |||||||||||||||||||||||||||||||
| 194 | 184 | ▶ | return $label . ' <key=value>' if $option->hash; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 195 | 170 | ▶ | return $label . ' <N.key=value>' if $option->objectlist; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 196 | 164 | ▶ | return $label . ' <a,b,...>' if $option->csv; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | 158 | ▶ | return $label . ' <>' if $option->type->takesValue; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | 24 | return $label; | |||||||||||||||||||||||||||||||
| 199 | 11 | } | |||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | # Every name of $option as it is typed, the Primary name first. A | ||||||||||||||||||||||||||||||||
| 202 | # negatable option shows its negation on the first long name, or after | ||||||||||||||||||||||||||||||||
| 203 | # the names when all of them are single letters. | ||||||||||||||||||||||||||||||||
| 204 | 184 | ▶ | method optionSpellings($option) { | ||||||||||||||||||||||||||||||
|
Subroutine
optionSpellings: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 205 | 184 | my @names = ($option->name, $option->aliases); | |||||||||||||||||||||||||||||||
| 206 | 184 | ▶ | return map { optionSpelling($_) } @names if !$option->negatable; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 14 | my ($negatedName) = grep { length > 1 } @names; | |||||||||||||||||||||||||||||||
| 209 | 14 | ▶ | my @spellings = map { defined $negatedName && $_ eq $negatedName ? '--[no-]' . $_ : optionSpelling($_) } @names; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $negatedName and $_ eq $negatedName
MC/DC100%2/2
defined $negatedName and $_ eq $negatedName
defined $negatedName
$_ eq $negatedName
Truth table100%3/3
A and B
A= defined $negatedNameB= $_ eq $negatedName
| |||||||||||||||||||||||||||||||||
| 210 | 14 | ▶ | push @spellings, '--no-' . $option->name if !defined $negatedName; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 211 | 14 | return @spellings; | |||||||||||||||||||||||||||||||
| 212 | 11 | } | |||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | 18 | ▶ | method argLabel($arg) { | ||||||||||||||||||||||||||||||
|
Subroutine
argLabel: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 215 | 18 | return sprintf('<%s>', $arg->short); | |||||||||||||||||||||||||||||||
| 216 | 11 | } | |||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | # $parts is an arrayref of [text, ansiCode] pairs; wrapping happens on the | ||||||||||||||||||||||||||||||||
| 219 | # plain text and colors are substituted in afterwards, so escape codes | ||||||||||||||||||||||||||||||||
| 220 | # never distort the width computation or the column alignment. | ||||||||||||||||||||||||||||||||
| 221 | 108 | ▶ | method entryLines($label, $parts) { | ||||||||||||||||||||||||||||||
|
Subroutine
entryLines: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 222 | 108 | my $text = join(' ', grep { length } map { $_->[0] } $parts->@*); | |||||||||||||||||||||||||||||||
| 223 | 108 | my $padded = sprintf(' %-*s', $self->labelWidth - 3, $label); | |||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | 108 | my $block; | |||||||||||||||||||||||||||||||
| 226 | 108 | ▶ | if ($text eq '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | 31 | $block = $padded =~ s/\s+$//r; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||||||
| 230 | # Text::Wrap widens its columns to fit the indent itself, with a | ||||||||||||||||||||||||||||||||
| 231 | # warning; do it up front so narrow terminals stay quiet. | ||||||||||||||||||||||||||||||||
| 232 | 77 | local $Text::Wrap::columns = max($self->width, $self->labelWidth + 2); | |||||||||||||||||||||||||||||||
| 233 | 77 | local $Text::Wrap::huge = 'overflow'; | |||||||||||||||||||||||||||||||
| 234 | 77 | local $Text::Wrap::unexpand = 0; | |||||||||||||||||||||||||||||||
| 235 | 77 | $block = Text::Wrap::wrap($padded, ' ' x $self->labelWidth, $text); | |||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 108 | ▶ | return $block if !$self->color; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 239 | 16 | return $self->paintParts($block, $parts, length $padded); | |||||||||||||||||||||||||||||||
| 240 | 11 | } | |||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | # Parts are painted in occurrence order, each searched only past the previous | ||||||||||||||||||||||||||||||||
| 243 | # one, so a part whose text also appears in an earlier part never steals the | ||||||||||||||||||||||||||||||||
| 244 | # paint. A part the wrapping broke across lines is painted word by word. | ||||||||||||||||||||||||||||||||
| 245 | 16 | ▶ | method paintParts($block, $parts, $searchFrom) { | ||||||||||||||||||||||||||||||
|
Subroutine
paintParts: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 246 | 16 | foreach my $part (grep { length $_->[0] } $parts->@*) { | |||||||||||||||||||||||||||||||
| 247 | 26 | ▶ | my @pieces = index($block, $part->[0], $searchFrom) < 0 ? grep { length } split(/\s+/, $part->[0]) : ($part->[0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 248 | 26 | foreach my $piece (@pieces) { | |||||||||||||||||||||||||||||||
| 249 | 42 | my $at = index($block, $piece, $searchFrom); | |||||||||||||||||||||||||||||||
| 250 | 42 | ▶ | next if $at < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 251 | 42 | ▶ | my $painted = defined $part->[1] ? $self->paint($piece, $part->[1]) : $piece; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 252 | 42 | substr($block, $at, length $piece) = $painted; | |||||||||||||||||||||||||||||||
| 253 | 42 | $searchFrom = $at + length $painted; | |||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||
| 256 | 16 | return $block; | |||||||||||||||||||||||||||||||
| 257 | 11 | } | |||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 23 | ▶ | method stringifyDefault($default) { | ||||||||||||||||||||||||||||||
|
Subroutine
stringifyDefault: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 260 | 23 | ▶ | return $default if !ref $default; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 261 | 12 | ▶ | return join(', ', map { sprintf('%s=%s', $_, $default->{$_}) } sort keys $default->%*) if ref $default eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 262 | 3 | return join(', ', map { $self->stringifyEntry($default->[$_], $_) } 0 .. $#$default); | |||||||||||||||||||||||||||||||
| 263 | 11 | } | |||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | # A list entry: the value itself, or for an objectlist the entry's pairs | ||||||||||||||||||||||||||||||||
| 266 | # prefixed with its index. | ||||||||||||||||||||||||||||||||
| 267 | 6 | ▶ | method stringifyEntry($entry, $index) { | ||||||||||||||||||||||||||||||
|
Subroutine
stringifyEntry: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 268 | 6 | ▶ | return $entry if ref $entry ne 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 269 | 6 | return $self->stringifyDefault({ map { (sprintf('%d.%s', $index, $_) => $entry->{$_}) } keys $entry->%* }); | |||||||||||||||||||||||||||||||
| 270 | 11 | } | |||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 11 | 1; | |||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | __END__ | ||||||||||||||||||||||||||||||||