| 1 | package OptArgs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Encode qw/decode/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | use Exporter::Tidy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | default => [qw/opt arg optargs usage subcmd/], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | other => [qw/dispatch class_optargs/]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Getopt::Long qw/GetOptionsFromArray/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use List::Util qw/max/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | our $VERSION = '0.1.21'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | our $COLOUR = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | our $ABBREV = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | our $SORT = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | our $PRINT_DEFAULT = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | our $PRINT_ISA = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | my %seen; # hash of hashes keyed by 'caller', then opt/arg name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | my %opts; # option configuration keyed by 'caller' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | my %args; # argument configuration keyed by 'caller' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | my %caller; # current 'caller' keyed by real caller | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | my %desc; # sub-command descriptions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 11 | my %dispatching; # track optargs() calls from dispatch classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | my %hidden; # subcmd hiding by default | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # internal function for App::optargs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | sub _cmdlist { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmdlist: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | return sort grep { $_ ne 'App::optargs' } keys %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Sub-command definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # This works by faking caller context in opt() and arg() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 11 | my %subcmd_params = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | cmd => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | comment => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | hidden => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # alias => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # ishelp => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 11 | my @subcmd_required = (qw/cmd comment/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 18 | ▶ | sub subcmd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subcmd: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 18 | my $params = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 18 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | ▶ | if ( my @missing = grep { !exists $params->{$_} } @subcmd_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | croak "missing required parameter(s): @missing"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 17 | ▶ | if ( my @invalid = grep { !exists $subcmd_params{$_} } keys %$params ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my @valid = keys %subcmd_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | croak "invalid parameter(s): @invalid (valid: @valid)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # croak "'ishelp' can only be applied to Bool opts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # if $params->{ishelp} and $params->{isa} ne 'Bool'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | my @cmd = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ref $params->{cmd} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | ? @{ $params->{cmd} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 17 | ▶ | : ( $params->{cmd} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 17 | ▶ | croak 'missing cmd elements' unless @cmd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 17 | my $name = pop @cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 17 | my $parent = join( '::', $caller, @cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 17 | $parent =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 17 | ▶ | croak "parent command not found: @cmd" unless $seen{$parent}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | my $package = $parent . '::' . $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | $package =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | ▶ | croak "sub command already defined: @cmd $name" if $seen{$package}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | $caller{$caller} = $package; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | $desc{$package} = $params->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 15 | $seen{$package} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | $opts{$package} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | $args{$package} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | $hidden{$package} = $params->{hidden}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | my $parent_arg = ( grep { $_->{isa} eq 'SubCmd' } @{ $args{$parent} } )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 15 | push( @{ $parent_arg->{subcommands} }, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Option definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | my %opt_params = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | isa => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | isa_name => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | comment => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | default => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | alias => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ishelp => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | hidden => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 11 | my @opt_required = (qw/isa comment/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 11 | my %opt_isa = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 'Bool' => '!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 'Counter' => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 'Str' => '=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 'Int' => '=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 'Num' => '=f', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 'ArrayRef' => '=s@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 'HashRef' => '=s%', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 43 | ▶ | sub opt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opt: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 43 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 43 | my $params = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 43 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 43 | ▶ | my $package = $caller{$caller} || $caller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$caller{$caller} || $caller
MC/DC0%0/2
$caller{$caller} || $caller
$caller{$caller}
$caller
Truth table66%2/3
A || B
A= $caller{$caller}B= $caller
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 43 | ▶ | croak 'usage: opt $name => (%parameters)' unless $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 39 | ▶ | croak "'$name' already defined" if $seen{$package}->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 37 | ▶ | if ( my @missing = grep { !exists $params->{$_} } @opt_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | croak "missing required parameter(s): @missing"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 35 | ▶ | if ( my @invalid = grep { !exists $opt_params{$_} } keys %$params ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my @valid = keys %opt_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | croak "invalid parameter(s): @invalid (valid: @valid)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | croak "'ishelp' can only be applied to Bool opts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 34 | ▶ | if $params->{ishelp} and $params->{isa} ne 'Bool'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$params->{"ishelp"} and $params->{"isa"} ne "Bool"
MC/DC100%2/2
$params->{"ishelp"} and $params->{"isa"} ne "Bool"
$params->{"ishelp"}
$params->{"isa"} ne "Bool"
Truth table100%3/3
A and B
A= $params->{"ishelp"}B= $params->{"isa"} ne "Bool"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | croak "unknown type: $params->{isa}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 33 | ▶ | unless exists $opt_isa{ $params->{isa} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 32 | $params = { %opt_params, %$params }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 32 | $params->{package} = $package; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 32 | $params->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 32 | $params->{length} = length $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 32 | $params->{acount} = do { my @tmp = split( '|', $params->{alias} ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 32 | $params->{type} = 'opt'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 32 | $params->{ISA} = $params->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 32 | ▶ | if ( ( my $dashed = $params->{name} ) =~ s/_/-/g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | $params->{dashed} = $dashed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | $params->{ISA} .= '|' . $dashed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 32 | ▶ | $params->{ISA} .= '|' . $params->{alias} if $params->{alias}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 32 | $params->{ISA} .= $opt_isa{ $params->{isa} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 32 | push( @{ $opts{$package} }, $params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 32 | ▶ | $args{$package} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{$package} ||= []
MC/DC100%1/1
$args{$package} ||= []
$args{$package}
Truth table100%2/2
A
A= $args{$package}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 32 | $seen{$package}->{$name}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 32 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Argument definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | my %arg_params = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | isa => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | comment => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | required => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | default => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | greedy => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | fallback => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 11 | my @arg_required = (qw/isa comment/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 11 | my %arg_isa = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 'Str' => '=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 'Int' => '=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 'Num' => '=f', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 'ArrayRef' => '=s@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 'HashRef' => '=s%', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 'SubCmd' => '=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 32 | ▶ | sub arg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arg: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 32 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 32 | my $params = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 32 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 32 | ▶ | my $package = $caller{$caller} || $caller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$caller{$caller} || $caller
MC/DC0%0/2
$caller{$caller} || $caller
$caller{$caller}
$caller
Truth table66%2/3
A || B
A= $caller{$caller}B= $caller
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 32 | ▶ | croak 'usage: arg $name => (%parameters)' unless $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 28 | ▶ | croak "'$name' already defined" if $seen{$package}->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 26 | ▶ | if ( my @missing = grep { !exists $params->{$_} } @arg_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | croak "missing required parameter(s): @missing"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 24 | ▶ | if ( my @invalid = grep { !exists $arg_params{$_} } keys %$params ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | my @valid = keys %arg_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | croak "invalid parameter(s): @invalid (valid: @valid)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | croak "unknown type: $params->{isa}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 23 | ▶ | unless exists $arg_isa{ $params->{isa} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | croak "'default' and 'required' cannot be used together" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 22 | ▶ | if defined $params->{default} and defined $params->{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params->{"default"} and defined $params->{"required"}
MC/DC100%2/2
defined $params->{"default"} and defined $params->{"required"}
defined $params->{"default"}
defined $params->{"required"}
Truth table100%3/3
A and B
A= defined $params->{"default"}B= defined $params->{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | croak "'fallback' only valid with isa 'SubCmd'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 21 | ▶ | if $params->{fallback} and $params->{isa} ne 'SubCmd'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$params->{"fallback"} and $params->{"isa"} ne "SubCmd"
MC/DC100%2/2
$params->{"fallback"} and $params->{"isa"} ne "SubCmd"
$params->{"fallback"}
$params->{"isa"} ne "SubCmd"
Truth table100%3/3
A and B
A= $params->{"fallback"}B= $params->{"isa"} ne "SubCmd"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | croak "fallback must be a hashref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 20 | ▶ | if defined $params->{fallback} && ref $params->{fallback} ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params->{"fallback"} and ref $params->{"fallback"} ne "HASH"
MC/DC100%2/2
defined $params->{"fallback"} and ref $params->{"fallback"} ne "HASH"
defined $params->{"fallback"}
ref $params->{"fallback"} ne "HASH"
Truth table100%3/3
A and B
A= defined $params->{"fallback"}B= ref $params->{"fallback"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 19 | $params->{package} = $package; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 19 | $params->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 19 | $params->{length} = length $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 19 | $params->{acount} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 19 | $params->{type} = 'arg'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 19 | $params->{ISA} = $params->{name} . $arg_isa{ $params->{isa} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 19 | push( @{ $args{$package} }, $params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 19 | ▶ | $opts{$package} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{$package} ||= []
MC/DC100%1/1
$opts{$package} ||= []
$opts{$package}
Truth table100%2/2
A
A= $opts{$package}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 19 | $seen{$package}->{$name}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 19 | ▶ | if ( $params->{fallback} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | my $p = $package . '::' . uc $params->{fallback}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $p =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | $opts{$p} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | $args{$p} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | $desc{$p} = $params->{fallback}->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # Usage message generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 7 | ▶ | sub _usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: called CC=59 SCAR=50.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 7 | my $ishelp = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 7 | my $terminal = -t STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 7 | ▶ | my $red = ( $COLOUR && $terminal ) ? "\e[0;31m" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$OptArgs::COLOUR and $terminal
MC/DC0%0/2
$OptArgs::COLOUR and $terminal
$OptArgs::COLOUR
$terminal
Truth table66%2/3
A and B
A= $OptArgs::COLOURB= $terminal
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 7 | my $yellow = ''; #( $COLOUR && $terminal ) ? "\e[0;33m" : ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | my $grey = ''; #( $COLOUR && $terminal ) ? "\e[1;30m" : ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | ▶ | my $reset = ( $COLOUR && $terminal ) ? "\e[0m" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$OptArgs::COLOUR and $terminal
MC/DC0%0/2
$OptArgs::COLOUR and $terminal
$OptArgs::COLOUR
$terminal
Truth table66%2/3
A and B
A= $OptArgs::COLOURB= $terminal
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 7 | my $parent = $caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | my @args = @{ $args{$caller} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 7 | my @opts = @{ $opts{$caller} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 7 | my @parents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | my @usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 7 | my @uargs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 7 | my @uopts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 7 | my $usage; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | require File::Basename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 7 | ▶ | my $me = File::Basename::basename( defined &static::list ? $^X : $0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 7 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | $usage .= "${red}error:$reset $error\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 7 | ▶ | $usage .= $yellow . ( $ishelp ? 'help:' : 'usage:' ) . $reset . ' ' . $me; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 7 | ▶ | while ( $parent =~ s/(.*)::(.*)/$1/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 8 | ▶ | last unless $seen{$parent}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | ( my $name = $2 ) =~ s/_/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | unshift( @parents, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | unshift( @opts, @{ $opts{$parent} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 7 | ▶ | $usage .= ' ' . join( ' ', @parents ) if @parents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | my $last = $args[$#args]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 7 | ▶ | if ($last) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 6 | foreach my $def (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 6 | $usage .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 6 | ▶ | $usage .= '[' unless $def->{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 6 | $usage .= uc $def->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 6 | ▶ | $usage .= '...' if $def->{greedy}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 6 | ▶ | $usage .= ']' unless $def->{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | push( @uargs, [ uc $def->{name}, $def->{comment} ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | ▶ | $usage .= ' [OPTIONS...]' if @opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 7 | $usage .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | $usage .= "\n ${grey}Synopsis:$reset\n $desc{$caller}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 7 | ▶ | if $ishelp and $desc{$caller}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ishelp and $desc{$caller}
MC/DC50%1/2
$ishelp and $desc{$caller}
$ishelp
$desc{$caller}
Truth table66%2/3
A and B
A= $ishelpB= $desc{$caller}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 7 | ▶ | if ( $ishelp and my $version = $caller->VERSION ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ishelp and my $version = $caller->VERSION
MC/DC0%0/2
$ishelp and my $version = $caller->VERSION
$ishelp
my $version = $caller->VERSION
Truth table66%2/3
A and B
A= $ishelpB= my $version = $caller->VERSION
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $usage .= "\n ${grey}Version:$reset\n $version\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 7 | ▶ | if ( $last && $last->{isa} eq 'SubCmd' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$last and $last->{"isa"} eq "SubCmd"
MC/DC100%2/2
$last and $last->{"isa"} eq "SubCmd"
$last
$last->{"isa"} eq "SubCmd"
Truth table100%3/3
A and B
A= $lastB= $last->{"isa"} eq "SubCmd"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 4 | $usage .= "\n ${grey}" . ucfirst( $last->{name} ) . ":$reset\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | my @subcommands = @{ $last->{subcommands} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | push( @subcommands, uc $last->{fallback}->{name} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | exists $last->{fallback} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | && ( $ishelp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | or !$last->{fallback}->{hidden} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
exists $last->{"fallback"} and $ishelp || !$last->{"fallback"}{"hidden"}
$ishelp or not $last->{"fallback"}{"hidden"}
MC/DC0%0/3
exists $last->{"fallback"} and $ishelp || !$last->{"fallback"}{"hidden"}
exists $last->{"fallback"}
$ishelp
not $last->{"fallback"}{"hidden"}
Truth table25%1/4
A and B or not(C)
A= exists $last->{"fallback"}B= $ishelpC= not $last->{"fallback"}{"hidden"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | @subcommands = sort @subcommands if $SORT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | foreach my $subcommand (@subcommands) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 10 | my $pkg = $last->{package} . '::' . $subcommand; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 10 | $pkg =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 10 | ▶ | next if $hidden{$pkg} and !$ishelp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$hidden{$pkg} and not $ishelp
MC/DC0%0/2
$hidden{$pkg} and not $ishelp
$hidden{$pkg}
not $ishelp
Truth table66%2/3
A and not(B)
A= $hidden{$pkg}B= not $ishelp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 10 | push( @usage, [ $subcommand, $desc{$pkg} ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 7 | ▶ | @opts = sort { $a->{name} cmp $b->{name} } @opts if $SORT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 7 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 18 | ▶ | next if $opt->{hidden} and !$ishelp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"hidden"} and not $ishelp
MC/DC0%0/2
$opt->{"hidden"} and not $ishelp
$opt->{"hidden"}
not $ishelp
Truth table33%1/3
A and not(B)
A= $opt->{"hidden"}B= not $ishelp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 18 | ( my $name = $opt->{name} ) =~ s/_/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 18 | ▶ | if ( $opt->{isa} eq 'Bool' and $opt->{default} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->{"isa"} eq "Bool" and $opt->{"default"}
MC/DC0%0/2
$opt->{"isa"} eq "Bool" and $opt->{"default"}
$opt->{"isa"} eq "Bool"
$opt->{"default"}
Truth table66%2/3
A and B
A= $opt->{"isa"} eq "Bool"B= $opt->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $name = 'no-' . $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 18 | my $default = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 18 | ▶ | if ( $PRINT_DEFAULT && defined $opt->{default} and !$opt->{ishelp} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$OptArgs::PRINT_DEFAULT and defined $opt->{"default"} and not $opt->{"ishelp"}
$OptArgs::PRINT_DEFAULT and defined $opt->{"default"}
MC/DC0%0/3
$OptArgs::PRINT_DEFAULT and defined $opt->{"default"} and not $opt->{"ishelp"}
$OptArgs::PRINT_DEFAULT
defined $opt->{"default"}
not $opt->{"ishelp"}
Truth table25%1/4
A and B and not(C)
A= $OptArgs::PRINT_DEFAULTB= defined $opt->{"default"}C= not $opt->{"ishelp"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | my $value = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | ref $opt->{default} eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | ? $opt->{default}->( {%$opt} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | : $opt->{default}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ( $opt->{isa} eq 'Bool' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $value = $value ? 'true' : 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $default = " [default: $value]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 18 | ▶ | if ($PRINT_ISA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if ( $opt->{isa_name} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $name .= '=' . uc $opt->{isa_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ▶ | elsif ($opt->{isa} eq 'Str' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$opt->{"isa"} eq "Str" or $opt->{"isa"} eq "HashRef" or $opt->{"isa"} eq "ArrayRef"
$opt->{"isa"} eq "Str" or $opt->{"isa"} eq "HashRef"
MC/DC0%0/3
$opt->{"isa"} eq "Str" or $opt->{"isa"} eq "HashRef" or $opt->{"isa"} eq "ArrayRef"
$opt->{"isa"} eq "Str"
$opt->{"isa"} eq "HashRef"
$opt->{"isa"} eq "ArrayRef"
Truth table0%0/4
A or B or C
A= $opt->{"isa"} eq "Str"B= $opt->{"isa"} eq "HashRef"C= $opt->{"isa"} eq "ArrayRef"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | || $opt->{isa} eq 'HashRef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | || $opt->{isa} eq 'ArrayRef' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $name .= '=STR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | elsif ( $opt->{isa} eq 'Int' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $name .= '=INT'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | elsif ( $opt->{isa} eq 'Num' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $name .= '=NUM'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 18 | ▶ | $name .= ',' if $opt->{alias}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | @uopts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | '--' . $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | $opt->{alias} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ? '-' . $opt->{alias} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 18 | ▶ | $opt->{comment} . $default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 7 | ▶ | if (@uopts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 7 | my $w1 = max( map { length $_->[0] } @uopts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 7 | my $fmt = '%-' . $w1 . "s %s"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 7 | @uopts = map { [ sprintf( $fmt, $_->[0], $_->[1] ), $_->[2] ] } @uopts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 7 | my $w1 = max( map { length $_->[0] } @usage, @uargs, @uopts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 7 | my $format = ' %-' . $w1 . "s %s\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 7 | ▶ | if (@usage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 4 | foreach my $row (@usage) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 10 | $usage .= sprintf( $format, @$row ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 7 | ▶ | if ( @uargs and $last->{isa} ne 'SubCmd' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@uargs and $last->{"isa"} ne "SubCmd"
MC/DC100%2/2
@uargs and $last->{"isa"} ne "SubCmd"
@uargs
$last->{"isa"} ne "SubCmd"
Truth table100%3/3
A and B
A= @uargsB= $last->{"isa"} ne "SubCmd"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | $usage .= "\n ${grey}Arguments:$reset\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 2 | foreach my $row (@uargs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | $usage .= sprintf( $format, @$row ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 7 | ▶ | if (@uopts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 7 | $usage .= "\n ${grey}Options:$reset\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 7 | foreach my $row (@uopts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 18 | $usage .= sprintf( $format, @$row ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 7 | $usage .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 7 | return bless( \$usage, 'OptArgs::Usage' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 32 | ▶ | sub _synopsis { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_synopsis: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 32 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 32 | my $parent = $caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 32 | my @args = @{ $args{$caller} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 32 | my @parents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 32 | require File::Basename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 32 | my $usage = File::Basename::basename($0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 32 | ▶ | while ( $parent =~ s/(.*)::(.*)/$1/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 88 | ▶ | last unless $seen{$parent}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 56 | ( my $name = $2 ) =~ s/_/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 56 | unshift( @parents, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 32 | ▶ | $usage .= ' ' . join( ' ', @parents ) if @parents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 32 | ▶ | if ( my $last = $args[$#args] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 12 | foreach my $def (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 12 | $usage .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 12 | ▶ | $usage .= '[' unless $def->{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 12 | $usage .= uc $def->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 12 | ▶ | $usage .= '...' if $def->{greedy}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 12 | ▶ | $usage .= ']' unless $def->{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 32 | return 'usage: ' . $usage . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return _usage( $caller, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # Option/Argument processing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 50 | ▶ | sub _optargs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_optargs: called CC=47 SCAR=40.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 50 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 50 | my $source = \@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 50 | my $source_hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 50 | my $package = $caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 50 | ▶ | if ( !@_ and @ARGV ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @_ and @ARGV
MC/DC100%2/2
not @_ and @ARGV
not @_
@ARGV
Truth table100%3/3
not(A) and B
A= not @_B= @ARGV
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | my $CODESET = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 27 | eval { require I18N::Langinfo; I18N::Langinfo::CODESET() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 27 | ▶ | if ($CODESET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 27 | my $codeset = I18N::Langinfo::langinfo($CODESET); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 27 | $_ = decode( $codeset, $_ ) for @ARGV; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 27 | $source = \@ARGV; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $source_hash = { map { %$_ } grep { ref $_ eq 'HASH' } @$source }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 23 | $source = [ grep { ref $_ ne 'HASH' } @$source ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 50 | ▶ | map { Carp::croak('_optargs argument undefined!') if !defined $_ } @$source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | croak "no option or argument defined for $caller" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | unless exists $opts{$package} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 50 | ▶ | or exists $args{$package}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{$package} or exists $args{$package}
MC/DC50%1/2
exists $opts{$package} or exists $args{$package}
exists $opts{$package}
exists $args{$package}
Truth table66%2/3
A or B
A= exists $opts{$package}B= exists $args{$package}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 49 | Getopt::Long::Configure(qw/pass_through no_auto_abbrev no_ignore_case/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 49 | my @config = ( @{ $opts{$package} }, @{ $args{$package} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 49 | my $ishelp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | my $missing_required; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 49 | my $optargs = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 49 | my @coderef_default_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 49 | ▶ | while ( my $try = shift @config ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 210 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 210 | ▶ | if ( $try->{type} eq 'opt' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 155 | ▶ | if ( exists $source_hash->{ $try->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $result = delete $source_hash->{ $try->{name} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 155 | GetOptionsFromArray( $source, $try->{ISA} => \$result ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | elsif ( $try->{type} eq 'arg' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 55 | ▶ | if (@$source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 34 | ▶ | die _usage( $package, qq{Unknown option "$source->[0]"} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | if $source->[0] =~ m/^--\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | die _usage( $package, qq{Unknown option "$source->[0]"} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | if $source->[0] =~ m/^-\S/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | and !( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | $source->[0] =~ m/^-\d/ and ( $try->{isa} ne 'Num' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 34 | ▶ | or $try->{isa} ne 'Int' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition11%1/9
$source->[0] =~ /^-\S/ and not $source->[0] =~ /^-\d/ && ($try->{"isa"} ne "Num" || $try->{"isa"} ne "Int")
$source->[0] =~ /^-\d/ && ($try->{'isa'} ne 'Num' || $try->{'isa'} ne 'Int')
$try->{"isa"} ne "Num" or $try->{"isa"} ne "Int"
MC/DC0%0/4
$source->[0] =~ /^-\S/ and not $source->[0] =~ /^-\d/ && ($try->{"isa"} ne "Num" || $try->{"isa"} ne "Int")
$source->[0] =~ /^-\S/
$source->[0] =~ /^-\d/
$try->{"isa"} ne "Num"
$try->{"isa"} ne "Int"
Truth table20%1/5
A and not(B && C or D)
A= $source->[0] =~ /^-\S/B= $source->[0] =~ /^-\d/C= $try->{"isa"} ne "Num"D= $try->{"isa"} ne "Int"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 34 | ▶ | if ( $try->{greedy} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 2 | my @later; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | ▶ | if ( @config and @$source > @config ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@config and @$source > @config
MC/DC0%0/2
@config and @$source > @config
@config
@$source > @config
Truth table33%1/3
A and B
A= @configB= @$source > @config
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | push( @later, pop @$source ) for @config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | ▶ | if ( $try->{isa} eq 'ArrayRef' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $result = [@$source]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | elsif ( $try->{isa} eq 'HashRef' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | $result = { map { split /=/, $_ } @$source }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | $result = "@$source"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 2 | ▶ | shift @$source while @$source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 2 | push( @$source, @later ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 32 | ▶ | if ( $try->{isa} eq 'ArrayRef' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | $result = [ shift @$source ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | elsif ( $try->{isa} eq 'HashRef' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | $result = { split /=/, shift @$source }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 30 | $result = shift @$source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # TODO: type check using Param::Utils? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | elsif ( exists $source_hash->{ $try->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $result = delete $source_hash->{ $try->{name} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | ▶ | elsif ( $try->{required} and !$ishelp ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$try->{"required"} and not $ishelp
MC/DC100%2/2
$try->{"required"} and not $ishelp
$try->{"required"}
not $ishelp
Truth table100%3/3
A and not(B)
A= $try->{"required"}B= not $ishelp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | $missing_required++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 53 | ▶ | if ( $try->{isa} eq 'SubCmd' and $result ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$try->{"isa"} eq "SubCmd" and $result
MC/DC100%2/2
$try->{"isa"} eq "SubCmd" and $result
$try->{"isa"} eq "SubCmd"
$result
Truth table100%3/3
A and B
A= $try->{"isa"} eq "SubCmd"B= $result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # look up abbreviated words | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 10 | ▶ | if ($ABBREV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 6 | require Text::Abbrev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | my %words = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 13 | map { m/^$package\:\:(\w+)$/; $1 => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 6 | grep { m/^$package\:\:(\w+)$/ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | keys %seen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 6 | my %abbrev = Text::Abbrev::abbrev( keys %words ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 6 | ▶ | $result = $abbrev{$result} if defined $abbrev{$result}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 10 | my $newpackage = $package . '::' . $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 10 | $newpackage =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 10 | ▶ | if ( exists $seen{$newpackage} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 8 | $package = $newpackage; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | @config = grep { $_->{type} eq 'opt' } @config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 8 | push( @config, @{ $opts{$package} }, @{ $args{$package} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | elsif ( !$ishelp ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | ▶ | if ( $try->{fallback} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | unshift @$source, $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | $try->{fallback}->{type} = 'arg'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | unshift( @config, $try->{fallback} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | die _usage( $package, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 1 | "Unknown " . uc( $try->{name} ) . qq{ "$result"} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 8 | $result = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 206 | ▶ | if ( defined $result ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 51 | $optargs->{ $try->{name} } = $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | elsif ( defined $try->{default} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | push( @coderef_default_keys, $try->{name} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 16 | ▶ | if ref $try->{default} eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 16 | $optargs->{ $try->{name} } = $result = $try->{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 206 | ▶ | $ishelp = 1 if $result and $try->{ishelp}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$result and $try->{"ishelp"}
MC/DC100%2/2
$result and $try->{"ishelp"}
$result
$try->{"ishelp"}
Truth table100%3/3
A and B
A= $resultB= $try->{"ishelp"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 48 | ▶ | if ($ishelp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 2 | die _usage( $package, undef, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | elsif ($missing_required) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 2 | die _usage($package); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | elsif (@$source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 2 | die _usage( $package, "Unexpected options or arguments: @$source" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | elsif ( my @unexpected = keys %$source_hash ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | die _usage( $package, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | "Unexpected HASH options or arguments: @unexpected" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # Re-calculate the default if it was a subref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 42 | foreach my $key (@coderef_default_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 8 | $optargs->{$key} = $optargs->{$key}->( {%$optargs} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 42 | return ( $package, $optargs ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 37 | ▶ | sub optargs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optargs: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 37 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | carp "optargs() called from dispatch handler" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 37 | ▶ | if $dispatching{$caller}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 37 | my ( $package, $optargs ) = _optargs( $caller, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 34 | return $optargs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 13 | ▶ | sub class_optargs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_optargs: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 13 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 13 | ▶ | croak 'dispatch($class, [@argv])' unless $caller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | carp "optargs_class() called from dispatch handler" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 13 | ▶ | if $dispatching{$caller}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 13 | ▶ | die $@ unless eval "require $caller;"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 13 | my ( $class, $optargs ) = _optargs( $caller, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 8 | ▶ | croak $@ unless eval "require $class;1;"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 8 | return ( $class, $optargs ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 16 | ▶ | sub dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispatch: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 16 | my $method = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 16 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 16 | ▶ | croak 'dispatch($method, $class, [@argv])' unless $method and $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$method and $class
MC/DC100%2/2
$method and $class
$method
$class
Truth table100%3/3
A and B
A= $methodB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 14 | ▶ | croak $@ unless eval "require $class;1;"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 13 | my ( $package, $optargs ) = class_optargs( $class, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 8 | my $sub = $package->can($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 8 | ▶ | die "Can't find method $method via package $package" unless $sub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 8 | $dispatching{$class}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 8 | my @results = $sub->($optargs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 8 | $dispatching{$class}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 8 | ▶ | return @results if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 4 | return $results[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | package OptArgs::Usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 7 | ▶ | bool => sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 7 | ▶ | '""' => sub { ${ $_[0] } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 11 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||