| 1 | package Getopt::Modular; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | $Getopt::Modular::VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: Modular access to Getopt::Long | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use List::MoreUtils qw(any uniq); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Scalar::Util qw(reftype looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | use Exception::Class | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | 'Getopt::Modular::Exception' => { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | description => 'Exception in commandline parsing/handling', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | fields => [ qw(type option value warning valid expected) ], | ||||||||||||||||||||||||||||||||||||||||||
| 15 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 'Getopt::Modular::Internal' => { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | description => 'Internal Exception in commandline parsing/handling', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | fields => [ qw(type option) ] | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | }; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub import | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | ▶ | while (@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | ▶ | if ($opt eq '-namespace') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | my $ns = shift || die "No namespace given"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || die('No namespace given')
MC/DC0%0/1
shift() || die('No namespace given')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # I could do this without eval, but I'm too lazy today. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | eval qq{ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | package $ns; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | \@${ns}::ISA = List::MoreUtils::uniq('Getopt::Modular', \@${ns}::ISA); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 1; } or die $@; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | elsif ($opt eq '-getOpt') | ||||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | my $package = caller || 'main'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
caller || 'main'
MC/DC0%0/1
caller || 'main'
caller
Truth table50%1/2
A
A= caller
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # again, too lazy right now. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | eval qq{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getOpt: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | package $package; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | sub getOpt { Getopt::Modular->getOpt(\@_) } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 1; } or die $@; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 11 | my $global; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | # do we have a global one yet? | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 9 | ▶ | $global ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$global ||= $self
MC/DC0%0/2
$global ||= $self
$global
$self
Truth table33%1/3
A ||= B
A= $globalB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (any {'global' eq lc} @_) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $global = $self; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | @_ = grep { 'global' ne lc } @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 9 | $self->setBoolHelp(qw(off on)); | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | $self->init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 9 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | sub _self_or_global | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 990 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_self_or_global: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 990 | my $underscore = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 990 | my $self = $underscore->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # is it an object? use it. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 990 | ▶ | eval { ref $self && $self->isa(__PACKAGE__) } && return shift @$underscore; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self && $self->isa(__PACKAGE__)
MC/DC50%1/2
ref $self && $self->isa(__PACKAGE__)
ref $self
$self->isa(__PACKAGE__)
Truth table66%2/3
A && B
A= ref $selfB= $self->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # passed in via class method? skip it. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 126 | ▶ | eval { not ref $self && $self->isa(__PACKAGE__) } && shift @$underscore; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self && $self->isa(__PACKAGE__)
MC/DC0%0/2
ref $self && $self->isa(__PACKAGE__)
ref $self
$self->isa(__PACKAGE__)
Truth table33%1/3
A && B
A= ref $selfB= $self->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # have global? use it. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 126 | ▶ | $global ? $global : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | # otherwise, create new. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | $self->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | sub _accepts_opt | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 83 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_accepts_opt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 83 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 83 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 83 | return exists $self->{accept_opts}{$opt}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | sub _opt | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 561 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_opt: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 561 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 561 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 561 | ▶ | if (@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 39 | $self->{accept_opts}{$opt} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 39 | return; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 522 | ▶ | unless (exists $self->{accept_opts}{$opt}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | Getopt::Modular::Internal->throw( | |||||||||||||||||||||||||||||||||||||||||
| 113 | type => 'unknown-option', | ||||||||||||||||||||||||||||||||||||||||||
| 114 | message => "Unknown option: $opt", | ||||||||||||||||||||||||||||||||||||||||||
| 115 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 522 | return $self->{accept_opts}{$opt}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | ▶ | $self->setMode(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 11 | my %_known_modes = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||
| 131 | strict | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | sub setMode | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setMode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | foreach my $mode (@_) | |||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | ▶ | if ($_known_modes{$mode}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | $self->{mode}{$mode}++; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | else | ||||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | croak "Unknown mode: $@"; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | sub setBoolHelp | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setBoolHelp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 9 | $self->{bool_strings} = [ @_[0,1] ]; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | sub acceptParam | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acceptParam: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 17 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 17 | ▶ | while (@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 42 | my $param = shift; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 42 | my $opts = shift; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 42 | ▶ | my $aliases = exists $opts->{aliases} ? ref $opts->{aliases} ? $opts->{aliases} : [ $opts->{aliases} ] : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 42 | ▶ | if ($param =~ /\|/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | ($param, my @aliases) = split /\|/, $param; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 10 | unshift @$aliases, @aliases; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # if any of the aliases have pipes, split them up. Needed to provide | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # the help screen. | ||||||||||||||||||||||||||||||||||||||||||
| 177 | $opts->{aliases} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 178 | uniq | ||||||||||||||||||||||||||||||||||||||||||
| 179 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 42 | ▶ | my $o = $self->_accepts_opt($param) ? $self->_opt($param) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 42 | ▶ | @{$o->{aliases} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o->{'aliases'} || []
MC/DC100%1/1
$o->{'aliases'} || []
$o->{'aliases'}
Truth table100%2/2
A
A= $o->{'aliases'}
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 42 | map { split /\|/, $_ } @$aliases | |||||||||||||||||||||||||||||||||||||||||
| 184 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # check if this flag already exists (other than as main name) | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 42 | for (@{$opts->{aliases}}) | |||||||||||||||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 24 | ▶ | if (exists $self->{all_opts}{$_} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $self->{"all_opts"}{$_} and $self->{"all_opts"}{$_} ne $param
MC/DC100%2/2
exists $self->{"all_opts"}{$_} and $self->{"all_opts"}{$_} ne $param
exists $self->{"all_opts"}{$_}
$self->{"all_opts"}{$_} ne $param
Truth table100%3/3
A and B
A= exists $self->{"all_opts"}{$_}B= $self->{"all_opts"}{$_} ne $param
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | $self->{all_opts}{$_} ne $param) | ||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | croak "$_ already used by $self->{all_opts}{$_}"; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # save this as the owner | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 23 | $self->{all_opts}{$_} = $param; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 41 | delete $self->{unacceptable}{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 41 | ▶ | if ($self->_accepts_opt($param)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | my $opt = $self->_opt($param); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | @{$self->_opt($param)}{keys %$opts} = values %$opts; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | else | ||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # set some defaults ... | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 39 | ▶ | $opts->{spec} ||= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"spec"} ||= ""
MC/DC100%1/1
$opts->{"spec"} ||= ""
$opts->{"spec"}
Truth table100%2/2
A
A= $opts->{"spec"}
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 39 | $self->_opt($param, $opts); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | sub unacceptParam | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unacceptParam: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | for my $param (@_) | |||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | $self->{unacceptable}{$param} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 221 | my @x = | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | delete @{$self->{all_opts}}{@{$self->{accept_opts}{$param}{aliases}}}; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | sub parseArgs | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parseArgs: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # first, gather up for the call to Getopt::Long. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | my %opts; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | my $accept = $self->{accept_opts}; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my $unaccept = $self->{unacceptable}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | my @params = map { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 15 | my $param = join '|', $_, @{$accept->{$_}{aliases}}; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 15 | ▶ | $param . ($accept->{$_}{spec} || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$accept->{$_}{'spec'} || ''
MC/DC0%0/1
$accept->{$_}{'spec'} || ''
$accept->{$_}{'spec'}
Truth table50%1/2
A
A= $accept->{$_}{'spec'}
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | } grep { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # skip unaccepted parameters | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 5 | ▶ | $unaccept and not $unaccept->{$_} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$unaccept && !$unaccept->{$_}
MC/DC50%1/2
$unaccept && !$unaccept->{$_}
$unaccept
!$unaccept->{$_}
Truth table66%2/3
A && not(B)
A= $unacceptB= !$unaccept->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | } keys %$accept; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # parse them | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | my $warnings; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | my $success = do { | |||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | ▶ | local $SIG{__WARN__} = sub { $warnings .= "@_";}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | Getopt::Long::Configure("bundling"); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 5 | GetOptions(\%opts, @params); | |||||||||||||||||||||||||||||||||||||||||
| 249 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | ▶ | if (not $success) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | Getopt::Modular::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 253 | message => "Bad command-line: $warnings", | ||||||||||||||||||||||||||||||||||||||||||
| 254 | type => 'getopt-long-failure', | ||||||||||||||||||||||||||||||||||||||||||
| 255 | warning => $warnings, | ||||||||||||||||||||||||||||||||||||||||||
| 256 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | # now validate everything that was passed in, and save it. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | for my $opt (keys %$accept) | |||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 11 | ▶ | if (exists $opts{$opt}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 6 | $self->setOpt($opt, $opts{$opt}); | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # if it's mandatory, get it - that will call the default and | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # set it. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | elsif ($accept->{$opt}{mandatory}) | ||||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # setting via default. | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | $self->getOpt($opt); | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | # if passed in a hash ref to populate, fill it. | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | if (@_ && ref $_[0] eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0] eq "HASH"
MC/DC50%1/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | my $opts = shift; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | for my $opt (keys %{$self->{accept_opts}}) | |||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | $opts->{$opt} = $self->getOpt($opt); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | sub getOpt | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 66 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getOpt: called CC=13 SCAR=26.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 66 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 66 | ▶ | my $opt = shift || Getopt::Modular::Exception->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || 'Getopt::Modular::Exception'->throw('message', 'No option given?', 'type', 'dev-error')
MC/DC0%0/2
shift() || 'Getopt::Modular::Exception'->throw('message', 'No option given?', 'type', 'dev-error')
shift()
'Getopt::Modular::Exception'->throw('message', 'No option given?', 'type', 'dev-error')
Truth table33%1/3
A || B
A= shift()B= 'Getopt::Modular::Exception'->throw('message', 'No option given?', 'type', 'dev-error')
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | message => 'No option given?', | ||||||||||||||||||||||||||||||||||||||||||
| 292 | type => 'dev-error', | ||||||||||||||||||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 66 | ▶ | if (not exists $self->{accept_opts}{$opt}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 5 | ▶ | if ($self->{mode}{strict}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 3 | Getopt::Modular::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 300 | message => "No such option: $opt", | ||||||||||||||||||||||||||||||||||||||||||
| 301 | type => 'no-such-option', | ||||||||||||||||||||||||||||||||||||||||||
| 302 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | value => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # If we don't have it yet, check if there's a default. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 63 | ▶ | if (not exists $self->{options}{$opt} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not exists $self->{"options"}{$opt} and exists $self->{"accept_opts"}{$opt} and exists $self->{"accept_opts"}{$opt}{"default"}
not exists $self->{"options"}{$opt} and exists $self->{"accept_opts"}{$opt}
MC/DC100%3/3
not exists $self->{"options"}{$opt} and exists $self->{"accept_opts"}{$opt} and exists $self->{"accept_opts"}{$opt}{"default"}
not exists $self->{"options"}{$opt}
exists $self->{"accept_opts"}{$opt}
exists $self->{"accept_opts"}{$opt}{"default"}
Truth table100%4/4
not(A) and B and C
A= not exists $self->{"options"}{$opt}B= exists $self->{"accept_opts"}{$opt}C= exists $self->{"accept_opts"}{$opt}{"default"}
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | exists $self->{accept_opts}{$opt} and | ||||||||||||||||||||||||||||||||||||||||||
| 311 | exists $self->{accept_opts}{$opt}{default}) | ||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 15 | my @default = $self->{accept_opts}{$opt}{default}; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 15 | ▶ | if (ref $default[0] and ref $default[0] eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $default[0] and ref $default[0] eq "CODE"
MC/DC50%1/2
ref $default[0] and ref $default[0] eq "CODE"
ref $default[0]
ref $default[0] eq "CODE"
Truth table66%2/3
A and B
A= ref $default[0]B= ref $default[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 7 | @default = $default[0]->(); | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 15 | $self->setOpt($opt, @default); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # should have one now ... check and return | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 63 | ▶ | if (exists $self->{options}{$opt}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 51 | ▶ | if (wantarray) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | return | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 8 | ▶ | ref $self->{options}{$opt} eq 'ARRAY' ? @{$self->{options}{$opt}} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ref $self->{options}{$opt} eq 'HASH' ? %{$self->{options}{$opt}} : | |||||||||||||||||||||||||||||||||||||||||
| 329 | 8 | ▶ | $self->{options}{$opt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 43 | return $self->{options}{$opt} | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | sub _getType | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 92 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getType: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 92 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 340 | 92 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 92 | ▶ | unless (exists $self->_opt($opt)->{_GMTYPE}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 32 | my $type = $self->_opt($opt)->{spec}; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 32 | $self->_opt($opt)->{_GMTYPE} = ''; #scalar | |||||||||||||||||||||||||||||||||||||||||
| 346 | 32 | ▶ | if ($type =~ /\@/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | $self->_opt($opt)->{_GMTYPE} = 'ARRAY'; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | elsif ($type =~ /\%/) | ||||||||||||||||||||||||||||||||||||||||||
| 351 | { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | $self->_opt($opt)->{_GMTYPE} = 'HASH'; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | $self->_opt($opt)->{_GMTYPE} | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 92 | } | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | sub _bool_val | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bool_val: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | # technically, perl allows anything to be boolean. | ||||||||||||||||||||||||||||||||||||||||||
| 361 | #my ($opt,$val) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | sub _int_val | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_int_val: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 24 | my ($opt,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 24 | ▶ | if ($val !~ /^[-+]?\d+$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | { | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 4 | Getopt::Modular::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 370 | message => "Trying to set '$opt' (an integer-only parameter) to '$val'", | ||||||||||||||||||||||||||||||||||||||||||
| 371 | type => 'set-int-failure', | ||||||||||||||||||||||||||||||||||||||||||
| 372 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 373 | value => $val | ||||||||||||||||||||||||||||||||||||||||||
| 374 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | sub _real_val | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_real_val: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 17 | my ($opt,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 17 | ▶ | unless (looks_like_number $val) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | { | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 5 | Getopt::Modular::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 385 | message => "Trying to set '$opt' (a real-number parameter) to '$val'", | ||||||||||||||||||||||||||||||||||||||||||
| 386 | type => 'set-real-failure', | ||||||||||||||||||||||||||||||||||||||||||
| 387 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 388 | value => $val | ||||||||||||||||||||||||||||||||||||||||||
| 389 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | my %_valtypes = ( | ||||||||||||||||||||||||||||||||||||||||||
| 394 | '!' => { val => \&_bool_val }, | ||||||||||||||||||||||||||||||||||||||||||
| 395 | '+' => { val => \&_int_val }, | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 46 | ▶ | 's' => { val => sub {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 11 | 'i' => { val => \&_int_val }, | |||||||||||||||||||||||||||||||||||||||||
| 398 | 'o' => { val => \&_int_val }, | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 'f' => { val => \&_real_val }, | ||||||||||||||||||||||||||||||||||||||||||
| 400 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | sub _setOpt | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 67 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setOpt: called CC=18 SCAR=29.9
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 67 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 67 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 67 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | # check known types before passing on to user-specified validation. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 67 | my $type = $self->_opt($opt)->{spec}; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 67 | ▶ | if ($type eq '' || $type eq '!') # boolean | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "" or $type eq "!"
MC/DC50%1/2
$type eq "" or $type eq "!"
$type eq ""
$type eq "!"
Truth table66%2/3
A or B
A= $type eq ""B= $type eq "!"
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | { | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 8 | _bool_val($opt,$val); | |||||||||||||||||||||||||||||||||||||||||
| 414 | # extra information should not be stored in a boolean. | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 8 | $val = !!$val; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | else | ||||||||||||||||||||||||||||||||||||||||||
| 418 | { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 59 | for (split //, $type) | |||||||||||||||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 138 | ▶ | if (my $info = $_valtypes{$_}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 59 | ▶ | if ($type =~ /\@/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | { | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 15 | $info->{val}->($opt,$_) for @$val; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | elsif ($type =~ /\%/) | ||||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 7 | $info->{val}->($opt,$_) for values %$val; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | else | ||||||||||||||||||||||||||||||||||||||||||
| 432 | { | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 37 | $info->{val}->($opt,$val); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 58 | ▶ | if ($self->_opt($opt)->{validate}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | { | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 26 | local $_ = $val; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 26 | ▶ | unless ($self->_opt($opt)->{validate}->()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | { | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 7 | ▶ | if (ref $val) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | { | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 4 | ▶ | $val = join ',', @$val if ref $val eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 4 | ▶ | $val = join ',', map { "$_=$val->{$_}" } sort keys %$val if ref $val eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | Getopt::Modular::Exception->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 7 | message => "'$val' is an invalid value for $opt", | |||||||||||||||||||||||||||||||||||||||||
| 451 | type => 'validate-failure', | ||||||||||||||||||||||||||||||||||||||||||
| 452 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 453 | value => $val, | ||||||||||||||||||||||||||||||||||||||||||
| 454 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 50 | ▶ | if (my $valid = $self->_opt($opt)->{valid_values}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | if (ref $valid eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my @valid = $valid->(); | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $valid = \@valid; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $self->_opt($opt)->{valid_values} = $valid; # cache for next time. | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | ▶ | if (ref $valid eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | { | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | unless (any { $_ eq $val } @$valid) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | { | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | Getopt::Modular::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 472 | message => "'$val' is an invalid value for $opt", | ||||||||||||||||||||||||||||||||||||||||||
| 473 | type => 'validate-failure', | ||||||||||||||||||||||||||||||||||||||||||
| 474 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 475 | value => $val, | ||||||||||||||||||||||||||||||||||||||||||
| 476 | valid => $valid, | ||||||||||||||||||||||||||||||||||||||||||
| 477 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | else | ||||||||||||||||||||||||||||||||||||||||||
| 481 | { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | Getopt::Modular::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 483 | message => "'valid_values requires either an array ref or a code ref to generate the list of valid values.", | ||||||||||||||||||||||||||||||||||||||||||
| 484 | type => 'valid-values-error', | ||||||||||||||||||||||||||||||||||||||||||
| 485 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 486 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 49 | $self->{options}{$opt} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | sub setOpt | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 70 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setOpt: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 70 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 497 | 70 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 70 | my $val = do { | |||||||||||||||||||||||||||||||||||||||||
| 499 | 70 | ▶ | if (ref $_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | { | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 9 | ▶ | Getopt::Modular::Exception->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->_getType($opt) || 'SCALAR'
builtin::reftype($_[0]) || 'SCALAR'
$self->_getType($opt) || 'SCALAR'
MC/DC100%1/1
$self->_getType($opt) || 'SCALAR'
$self->_getType($opt)
MC/DC0%0/1
builtin::reftype($_[0]) || 'SCALAR'
builtin::reftype($_[0])
MC/DC100%1/1
$self->_getType($opt) || 'SCALAR'
$self->_getType($opt)
Truth table100%2/2
A
A= $self->_getType($opt)
Truth table50%1/2
A
A= builtin::reftype($_[0])
Truth table100%2/2
A
A= $self->_getType($opt)
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | type => 'wrong-type', | ||||||||||||||||||||||||||||||||||||||||||
| 503 | message => "Wrong type of data for $opt. Expected: " . | ||||||||||||||||||||||||||||||||||||||||||
| 504 | ($self->_getType($opt) || 'SCALAR') . | ||||||||||||||||||||||||||||||||||||||||||
| 505 | " got: " . (reftype $_[0] || 'SCALAR'), | ||||||||||||||||||||||||||||||||||||||||||
| 506 | expected => ($self->_getType($opt) || 'SCALAR'), | ||||||||||||||||||||||||||||||||||||||||||
| 507 | option => $opt, | ||||||||||||||||||||||||||||||||||||||||||
| 508 | value => $_[0], | ||||||||||||||||||||||||||||||||||||||||||
| 509 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 510 | unless $self->_getType($opt) eq reftype $_[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | # if it's a reference, pass it in unchanged. | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 6 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | else | ||||||||||||||||||||||||||||||||||||||||||
| 516 | { | ||||||||||||||||||||||||||||||||||||||||||
| 517 | # scalars get passed in, but hashes and arrays need to | ||||||||||||||||||||||||||||||||||||||||||
| 518 | # be referencised. | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 61 | ▶ | ! $self->_getType($opt) ? shift : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | $self->_getType($opt) eq 'HASH' ? { @_ } : [ @_ ]; | ||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 67 | $self->_setOpt($opt, $val); | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | sub getHelpRaw | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getHelpRaw: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 7 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | # get the list of parameters ... | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 7 | my $accept = $self->{accept_opts}; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 7 | my $unaccept = $self->{unacceptable}; | |||||||||||||||||||||||||||||||||||||||||
| 536 | my @params = sort grep { | ||||||||||||||||||||||||||||||||||||||||||
| 537 | # skip unaccepted parameters | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 7 | ▶ | $unaccept and not $unaccept->{$_} | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$unaccept && !$unaccept->{$_}
MC/DC0%0/2
$unaccept && !$unaccept->{$_}
$unaccept
!$unaccept->{$_}
Truth table33%1/3
A && not(B)
A= $unacceptB= !$unaccept->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | } keys %$accept; | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | # start figuring it out. | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 7 | my @raw; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 7 | for my $param (@params) | |||||||||||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 22 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 22 | my $param_info = $accept->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 22 | ▶ | my @keys = ($param, @{$param_info->{aliases}||[]}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$param_info->{'aliases'} || []
MC/DC0%0/1
$param_info->{'aliases'} || []
$param_info->{'aliases'}
Truth table50%1/2
A
A= $param_info->{'aliases'}
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | # booleans get the "no" version. | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 22 | ▶ | if ($param_info->{spec} =~ /!/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | { | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 14 | ▶ | @keys = map { length > 1 ? ($_, "no$_") : $_ } @keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | # anything with more than one letter gets a double-dash. | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 22 | ▶ | @keys = map { length > 1 ? "--$_" : "-$_" } @keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 22 | $opt{param} = \@keys; | |||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | $opt{help} = ref $param_info->{help} ? | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 22 | ▶ | $param_info->{help}->() : $param_info->{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | # determine default (or set value) | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 22 | my $default; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 22 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 566 | 22 | $opt{default} = $self->getOpt($param); | |||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 22 | my $type = $self->_opt($param)->{spec}; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 22 | ▶ | if ($type eq '' || $type eq '!') # boolean | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "" or $type eq "!"
MC/DC50%1/2
$type eq "" or $type eq "!"
$type eq ""
$type eq "!"
Truth table66%2/3
A or B
A= $type eq ""B= $type eq "!"
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | { | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 14 | ▶ | my $bools = ( $self->_opt($param)->{help_bool} or $self->{bool_strings} ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->_opt($param)->{'help_bool'} || $self->{'bool_strings'}
MC/DC0%0/2
$self->_opt($param)->{'help_bool'} || $self->{'bool_strings'}
$self->_opt($param)->{'help_bool'}
$self->{'bool_strings'}
Truth table66%2/3
A || B
A= $self->_opt($param)->{'help_bool'}B= $self->{'bool_strings'}
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 14 | ▶ | $opt{default} = $bools->[$opt{default} ? 1 : 0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | # determine valid values. | ||||||||||||||||||||||||||||||||||||||||||
| 578 | 22 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 579 | 22 | $opt{valid_values} = $self->_opt($param)->{valid_values}; | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 11 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | # if it's not a code ref, the eval will exit, but we'll already | ||||||||||||||||||||||||||||||||||||||||||
| 583 | # have what we want anyway. | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 22 | $opt{valid_values} = [ $opt{valid_values}->() ]; | |||||||||||||||||||||||||||||||||||||||||
| 585 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | # is it hidden? It's still part of the raw output. | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 22 | ▶ | $opt{hidden} = $param_info->{hidden} if exists $param_info->{hidden}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 22 | push @raw, \%opt; | |||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | 7 | return @raw; | |||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | sub getHelp | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getHelp: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 3 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 599 | 3 | my @raw = grep { not $_->{hidden} } $self->getHelpRaw; | |||||||||||||||||||||||||||||||||||||||||
| 600 | 3 | ▶ | my $cbs = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 3 | require Text::Table; | |||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 3 | my $tb = Text::Table->new(); | |||||||||||||||||||||||||||||||||||||||||
| 605 | 3 | for my $param (@raw) | |||||||||||||||||||||||||||||||||||||||||
| 606 | { | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 9 | my $opt = join ",\n ", @{$param->{param}}; | |||||||||||||||||||||||||||||||||||||||||
| 608 | 9 | my $txt = $param->{help}; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 11 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 9 | ▶ | $txt .= "\n " . ($cbs->{current_value} || sub { "Current value: [". shift(). "]" })->($param->{default}) if exists $param->{default}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
Condition66%2/3
$cbs->{'current_value'} || sub {
'Current value: [' . (shift()) . ']';
}
MC/DC0%0/2
$cbs->{'current_value'} || sub {
'Current value: [' . (shift()) . ']';
}
$cbs->{'current_value'}
sub {
'Current value: [' . (shift()) . ']';
}
Truth table66%2/3
A || B
A= $cbs->{'current_value'}B= sub {
'Current value: [' . (shift()) . ']';
}
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 9 | ▶ | if ($param->{valid_values}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | { | ||||||||||||||||||||||||||||||||||||||||||
| 615 | # if it's a code ref, de-ref it. If not, ignore the exception. | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 3 | eval { $param->{valid_values} = [ $param->{valid_values}->() ] }; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 3 | ▶ | $txt .= "\n " . ($cbs->{valid_values} || sub { "Valid values: [". join(',', @_). "]" })->(@{$param->{valid_values}}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Condition66%2/3
$cbs->{'valid_values'} || sub {
'Valid values: [' . join(',', @_) . ']';
}
MC/DC0%0/2
$cbs->{'valid_values'} || sub {
'Valid values: [' . join(',', @_) . ']';
}
$cbs->{'valid_values'}
sub {
'Valid values: [' . join(',', @_) . ']';
}
Truth table66%2/3
A || B
A= $cbs->{'valid_values'}B= sub {
'Valid values: [' . join(',', @_) . ']';
}
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 9 | $tb->add($opt, $txt); | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 3 | $tb; | |||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | sub getHelpWrap | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getHelpWrap: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | my $self = _self_or_global(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | ▶ | my $width = (@_ && not ref $_[0]) ? shift : 80; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and not ref $_[0]
MC/DC50%1/2
@_ and not ref $_[0]
@_
not ref $_[0]
Truth table66%2/3
A and not(B)
A= @_B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 2 | ▶ | my $cbs = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 2 | my @raw = grep { not $_->{hidden} } $self->getHelpRaw; | |||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 2 | require Text::Table; | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | my $wrap = eval { | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 2 | require Text::WrapI18N; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 6 | local $Text::WrapI18N::columns = shift; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 6 | local $Text::WrapI18N::unexpand; | |||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 6 | Text::WrapI18N::wrap('', '', @_); | |||||||||||||||||||||||||||||||||||||||||
| 642 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 643 | 2 | ▶ | } || do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
require Text::WrapI18N;
sub {
local $Text::WrapI18N::columns = shift();
local $Text::WrapI18N::unexpand;
Text::WrapI18N::wrap('', '', @_);
}
}
} || do {
require Text::Wrap;
sub {
local $Text::Wrap::columns = shift();
local $Text::Wrap::unexpand;
Text::Wrap::wrap('', '', @_);
}
}
MC/DC0%0/2
eval {
do {
require Text::WrapI18N;
sub {
local $Text::WrapI18N::columns = shift();
local $Text::WrapI18N::unexpand;
Text::WrapI18N::wrap('', '', @_);
}
}
} || do {
require Text::Wrap;
sub {
local $Text::Wrap::columns = shift();
local $Text::Wrap::unexpand;
Text::Wrap::wrap('', '', @_);
}
}
eval {
do {
require Text::WrapI18N;
sub {
local $Text::WrapI18N::columns = shift();
local $Text::WrapI18N::unexpand;
Text::WrapI18N::wrap('', '', @_);
}
}
}
do {
require Text::Wrap;
sub {
local $Text::Wrap::columns = shift();
local $Text::Wrap::unexpand;
Text::Wrap::wrap('', '', @_);
}
}
Truth table33%1/3
A || B
A= eval {
do {
require Text::WrapI18N;
sub {
local $Text::WrapI18N::columns = shift();
local $Text::WrapI18N::unexpand;
Text::WrapI18N::wrap('', '', @_);
}
}
}B= do {
require Text::Wrap;
sub {
local $Text::Wrap::columns = shift();
local $Text::Wrap::unexpand;
Text::Wrap::wrap('', '', @_);
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | require Text::Wrap; | |||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | local $Text::Wrap::columns = shift; | |||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | local $Text::Wrap::unexpand; | |||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | Text::Wrap::wrap('', '', @_); | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | 2 | my $tb = Text::Table->new(); | |||||||||||||||||||||||||||||||||||||||||
| 654 | 12 | ▶ | my $load_data = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 12 | my $tb = shift; | |||||||||||||||||||||||||||||||||||||||||
| 656 | 12 | my $param = shift; | |||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 12 | my $opt = join ",\n ", @{$param->{param}}; | |||||||||||||||||||||||||||||||||||||||||
| 659 | 12 | my $txt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 12 | my $available = shift; | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 11 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 12 | ▶ | $txt .= "\n " . ($cbs->{current_value} || sub { "Current value: [". shift(). "]" })->($param->{default}) if exists $param->{default}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.8
Branch: 1 branch
Condition33%1/3
$cbs->{'current_value'} || sub {
'Current value: [' . (shift()) . ']';
}
MC/DC0%0/2
$cbs->{'current_value'} || sub {
'Current value: [' . (shift()) . ']';
}
$cbs->{'current_value'}
sub {
'Current value: [' . (shift()) . ']';
}
Truth table33%1/3
A || B
A= $cbs->{'current_value'}B= sub {
'Current value: [' . (shift()) . ']';
}
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | 12 | ▶ | $txt .= "\n " . ($cbs->{valid_values} || sub { "Valid values: [". join(',', @_). "]" })->(@{$param->{valid_values}}) if $param->{valid_values}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
Condition33%1/3
$cbs->{'valid_values'} || sub {
'Valid values: [' . join(',', @_) . ']';
}
MC/DC0%0/2
$cbs->{'valid_values'} || sub {
'Valid values: [' . join(',', @_) . ']';
}
$cbs->{'valid_values'}
sub {
'Valid values: [' . join(',', @_) . ']';
}
Truth table33%1/3
A || B
A= $cbs->{'valid_values'}B= sub {
'Valid values: [' . join(',', @_) . ']';
}
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | # wrap all lines | ||||||||||||||||||||||||||||||||||||||||||
| 669 | 12 | ▶ | $txt = $wrap->($available, $txt) if $available; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 12 | $tb->add($opt, $txt); | |||||||||||||||||||||||||||||||||||||||||
| 672 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 2 | for my $param (@raw) | |||||||||||||||||||||||||||||||||||||||||
| 675 | { | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 6 | $load_data->($tb, $param, $param->{help}); | |||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 2 | ▶ | if ($tb->width > $width) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | { | ||||||||||||||||||||||||||||||||||||||||||
| 681 | # rebuild, wrapped. | ||||||||||||||||||||||||||||||||||||||||||
| 682 | 2 | my @colrange = $tb->colrange(0); | |||||||||||||||||||||||||||||||||||||||||
| 683 | 2 | my $available = $width - $colrange[1] - 1; # 1 for extra space between columns | |||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 2 | $tb->clear(); | |||||||||||||||||||||||||||||||||||||||||
| 686 | 2 | for my $param (@raw) | |||||||||||||||||||||||||||||||||||||||||
| 687 | { | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 6 | $load_data->($tb, $param, $param->{help}, $available); | |||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | # if the current value or valid values are a block of text too long, we don't want all | ||||||||||||||||||||||||||||||||||||||||||
| 693 | # lines to be too long, so clobber the extra spaces that Text::Table puts in at the end. | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 2 | (my $txt = "".$tb) =~ s/\s+$//msg; | |||||||||||||||||||||||||||||||||||||||||
| 695 | 2 | $txt .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | $txt; | |||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 11 | 1; # End of Getopt::Modular | |||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | __END__ | ||||||||||||||||||||||||||||||||||||||||||