| 1 | # Prefer numeric version for backwards compatibility | ||||||||||||||||||||||||||||
| 2 | 16 | ▶ | BEGIN { require 5.010000 }; ## no critic ( RequireUseStrict, RequireUseWarnings ) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | my $croakf = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | @_ = ( ( @_ == 1 ? shift : sprintf shift, @_ ) . ', stopped' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 8 | 12 | require Carp; | |||||||||||||||||||||||||||
| 9 | 12 | goto &Carp::croak | |||||||||||||||||||||||||||
| 10 | 16 | }; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 18 | ▶ | my $program_name = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 18 | require File::Basename; | |||||||||||||||||||||||||||
| 14 | 18 | File::Basename::basename( $0 ) | |||||||||||||||||||||||||||
| 15 | 16 | }; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #<<< | ||||||||||||||||||||||||||||
| 18 | package Getopt::Guided; | ||||||||||||||||||||||||||||
| 19 | # ABSTRACT: getopts implementation that follows POSIX utility guidelines | ||||||||||||||||||||||||||||
| 20 | 16 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 16 | our $VERSION = 'v3.3.2'; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | #>>> | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Options Delimiter constant | ||||||||||||||||||||||||||||
| 26 | sub OD () { '-' } | ||||||||||||||||||||||||||||
| 27 | # End Of Options Delimiter constant | ||||||||||||||||||||||||||||
| 28 | sub EOOD () { '--' } | ||||||||||||||||||||||||||||
| 29 | # Flag Indicator Character Class constant | ||||||||||||||||||||||||||||
| 30 | sub FICC () { '[!+]' } | ||||||||||||||||||||||||||||
| 31 | # Option-Argument Indicator Character Class constant | ||||||||||||||||||||||||||||
| 32 | sub OAICC () { '[,:=]' } | ||||||||||||||||||||||||||||
| 33 | # Perl boolean true constant ( IV == 1 ) | ||||||||||||||||||||||||||||
| 34 | sub TRUE () { !!1 } | ||||||||||||||||||||||||||||
| 35 | # Perl boolean false constant | ||||||||||||||||||||||||||||
| 36 | sub FALSE () { !!0 } | ||||||||||||||||||||||||||||
| 37 | # Common exit status constants | ||||||||||||||||||||||||||||
| 38 | sub EXIT_SUCCESS () { 0 } | ||||||||||||||||||||||||||||
| 39 | sub EXIT_FAILURE () { 1 } | ||||||||||||||||||||||||||||
| 40 | sub EXIT_USAGE () { 2 } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 16 | @Getopt::Guided::EXPORT_OK = | |||||||||||||||||||||||||||
| 43 | qw( EOOD EXIT_SUCCESS EXIT_FAILURE EXIT_USAGE getopts processopts readopts print_version_info ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 16 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 46 | 16 | my $module = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 16 | my $target = caller; | |||||||||||||||||||||||||||
| 49 | 16 | our @EXPORT_OK; | |||||||||||||||||||||||||||
| 50 | 16 | ▶ | @_ = @EXPORT_OK if @_ == 1 and $_[ 0 ] eq ':all'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 and $_[0] eq ":all"
MC/DC100%2/2
@_ == 1 and $_[0] eq ":all"
@_ == 1
$_[0] eq ":all"
Truth table100%3/3
A and B
A= @_ == 1B= $_[0] eq ":all"
| |||||||||||||||||||||||||||||
| 51 | 16 | for my $function ( @_ ) { | |||||||||||||||||||||||||||
| 52 | $croakf->( "%s: '%s' is not exported", $module, $function ) | ||||||||||||||||||||||||||||
| 53 | 41 | ▶ | unless grep { $function eq $_ } @EXPORT_OK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 16 | ▶ | no strict 'refs'; ## no critic ( ProhibitNoStrict ) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 40 | *{ "$target\::$function" } = $module->can( $function ) | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Implementation is based on m//gc with \G | ||||||||||||||||||||||||||||
| 60 | 79 | ▶ | sub parse_spec ( $;\%$ ) { | ||||||||||||||||||||||||||
|
Subroutine
parse_spec: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 79 | my ( $spec, $spec_as_hash, $spec_length_expected ) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 79 | ▶ | $spec_as_hash = {} unless defined $spec_as_hash; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 79 | my $spec_length_got; | |||||||||||||||||||||||||||
| 66 | 16 | ▶ | no warnings qw( uninitialized ); ## no critic ( ProhibitNoWarnings ) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 79 | ▶ | while ( $spec =~ m/\G ( [[:alnum:]] ) ( ${ \( FICC ) } | ${ \( OAICC ) } | )/gcox ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 147 | my ( $name, $indicator ) = ( $1, $2 ); | |||||||||||||||||||||||||||
| 69 | $croakf->( "%s parameter contains option '%s' multiple times", '$spec', $name ) | ||||||||||||||||||||||||||||
| 70 | 147 | ▶ | if exists $spec_as_hash->{ $name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 146 | $spec_as_hash->{ $name } = $indicator; | |||||||||||||||||||||||||||
| 72 | 146 | ++$spec_length_got | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 78 | my $offset = pos $spec; | |||||||||||||||||||||||||||
| 75 | 78 | ▶ | $croakf->( "%s parameter isn't a non-empty string of alphanumeric characters", '$spec' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $offset and $offset == length $spec
MC/DC100%2/2
defined $offset and $offset == length $spec
defined $offset
$offset == length $spec
Truth table100%3/3
A and B
A= defined $offsetB= $offset == length $spec
| |||||||||||||||||||||||||||||
| 76 | unless defined $offset and $offset == length $spec; | ||||||||||||||||||||||||||||
| 77 | 72 | ▶ | $croakf->( '%s parameter specifies %d options (expected: %d)', '$spec', $spec_length_got, $spec_length_expected ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $spec_length_expected and $spec_length_got != $spec_length_expected
MC/DC100%2/2
defined $spec_length_expected and $spec_length_got != $spec_length_expected
defined $spec_length_expected
$spec_length_got != $spec_length_expected
Truth table100%3/3
A and B
A= defined $spec_length_expectedB= $spec_length_got != $spec_length_expected
| |||||||||||||||||||||||||||||
| 78 | if defined $spec_length_expected and $spec_length_got != $spec_length_expected; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 71 | $spec_as_hash | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02> | ||||||||||||||||||||||||||||
| 84 | 61 | ▶ | sub getopts ( $\%;\@ ) { | ||||||||||||||||||||||||||
|
Subroutine
getopts: called CC=22 SCAR=30.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 61 | my ( $spec, $opts, $argv ) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 61 | ▶ | my $spec_as_hash = ref $spec eq 'HASH' ? $spec : parse_spec $spec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 55 | ▶ | $croakf->( "%s parameter isn't an empty hash", '%$opts' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | if %$opts; | ||||||||||||||||||||||||||||
| 90 | 54 | ▶ | $argv = \@ARGV unless defined $argv; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 54 | my @argv_backup = @$argv; | |||||||||||||||||||||||||||
| 93 | 54 | my @error; | |||||||||||||||||||||||||||
| 94 | # Guideline 4, Guideline 9 | ||||||||||||||||||||||||||||
| 95 | 54 | ▶ | while ( @$argv and my ( $name, $rest ) = ( $argv->[ 0 ] =~ m/\A ${ \( OD ) } (.) (.*)/ox ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$argv and () = $argv->[0] =~ /\A ${\"-";} (.) (.*)/ox
MC/DC100%2/2
@$argv and () = $argv->[0] =~ /\A ${\"-";} (.) (.*)/ox
@$argv
() = $argv->[0] =~ /\A ${\"-";} (.) (.*)/ox
Truth table100%3/3
A and B
A= @$argvB= () = $argv->[0] =~ /\A ${\"-";} (.) (.*)/ox
| |||||||||||||||||||||||||||||
| 96 | # Guideline 10 | ||||||||||||||||||||||||||||
| 97 | 171 | ▶ | shift @$argv, last | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | if $argv->[ 0 ] eq EOOD; | ||||||||||||||||||||||||||||
| 99 | @error = ( 'illegal option', $name ), last | ||||||||||||||||||||||||||||
| 100 | 170 | ▶ | unless exists $spec_as_hash->{ $name }; ## no critic ( ProhibitNegativeExpressionsInUnlessAndUntilConditions ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 166 | my $indicator = $spec_as_hash->{ $name }; | |||||||||||||||||||||||||||
| 103 | 166 | ▶ | if ( $indicator =~ m/\A ${ \( OAICC ) } \z/ox ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | # Case: Option has an option-argument | ||||||||||||||||||||||||||||
| 105 | # Shift delimeted option name | ||||||||||||||||||||||||||||
| 106 | 89 | shift @$argv; | |||||||||||||||||||||||||||
| 107 | # Extract option-argument value | ||||||||||||||||||||||||||||
| 108 | 89 | my $value; | |||||||||||||||||||||||||||
| 109 | 89 | ▶ | if ( $rest ne '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 14 | $value = $rest; | |||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | # Guideline 7 | ||||||||||||||||||||||||||||
| 113 | 75 | ▶ | @error = ( 'option requires an argument', $name ), last | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | unless @$argv; | ||||||||||||||||||||||||||||
| 115 | # Guideline 6, Guideline 8 | ||||||||||||||||||||||||||||
| 116 | 73 | ▶ | @error = ( 'option requires an argument', $name ), last | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | unless defined( $value = shift @$argv ); | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | # Store option-argument value | ||||||||||||||||||||||||||||
| 120 | 86 | ▶ | if ( $indicator eq ':' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 121 | # Standard behaviour: Overwrite option-argument | ||||||||||||||||||||||||||||
| 122 | 38 | $opts->{ $name } = $value | |||||||||||||||||||||||||||
| 123 | } elsif ( $indicator eq ',' ) { | ||||||||||||||||||||||||||||
| 124 | # Create and fill list of option-arguments | ||||||||||||||||||||||||||||
| 125 | 25 | ▶ | $opts->{ $name } = [] unless exists $opts->{ $name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 25 | push @{ $opts->{ $name } }, $value | |||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||
| 128 | # Create and fill list of option-arguments ( $indicator eq '=' ) | ||||||||||||||||||||||||||||
| 129 | 23 | ▶ | $opts->{ $name } = {} unless exists $opts->{ $name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 23 | ▶ | if ( $value =~ m/\A ([^=]*) = (.*) \z/x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 22 | $opts->{ $name }->{ $1 } = $2 | |||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | 1 | @error = ( 'option requires a key=value argument', $name ), last | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||
| 137 | # Case: Option is a flag | ||||||||||||||||||||||||||||
| 138 | 77 | ▶ | if ( not exists $opts->{ $name } ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 139 | # Initialisation | ||||||||||||||||||||||||||||
| 140 | 55 | $opts->{ $name } = TRUE | |||||||||||||||||||||||||||
| 141 | } elsif ( $indicator eq '!' ) { | ||||||||||||||||||||||||||||
| 142 | # Negate logically | ||||||||||||||||||||||||||||
| 143 | 1 | $opts->{ $name } = not $opts->{ $name } | |||||||||||||||||||||||||||
| 144 | } elsif ( $indicator eq '+' ) { | ||||||||||||||||||||||||||||
| 145 | # Increment | ||||||||||||||||||||||||||||
| 146 | 18 | ++$opts->{ $name } | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | # Guideline 5 | ||||||||||||||||||||||||||||
| 149 | 77 | ▶ | if ( $rest eq '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | # Shift delimeted option name | ||||||||||||||||||||||||||||
| 151 | 60 | shift @$argv | |||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||
| 153 | 17 | $argv->[ 0 ] = OD . $rest ## no critic ( RequireLocalizedPunctuationVars ) | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 54 | ▶ | if ( @error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | # Restore to avoid side effects | ||||||||||||||||||||||||||||
| 161 | 8 | @$argv = @argv_backup; ## no critic ( RequireLocalizedPunctuationVars ) | |||||||||||||||||||||||||||
| 162 | 8 | %$opts = (); | |||||||||||||||||||||||||||
| 163 | # Prepare and print warning message: | ||||||||||||||||||||||||||||
| 164 | # Program name, type of error, and invalid option character | ||||||||||||||||||||||||||||
| 165 | 8 | warn sprintf( "%s: %s -- %s\n", $program_name->(), @error ) ## no critic ( RequireCarping ) | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 54 | @error == 0 | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Prepare and print version info message: | ||||||||||||||||||||||||||||
| 172 | # - Program name and version (first line) | ||||||||||||||||||||||||||||
| 173 | # - Interpreter name ("perl") and version (second line) | ||||||||||||||||||||||||||||
| 174 | 3 | ▶ | sub print_version_info { | ||||||||||||||||||||||||||
|
Subroutine
print_version_info: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | # call frame 0: processopts() (the caller) calls print_version_info() | ||||||||||||||||||||||||||||
| 176 | # the caller's package name is Getopt::Guided | ||||||||||||||||||||||||||||
| 177 | # call frame 1: a run() function/method (the caller) usually calls processopts() | ||||||||||||||||||||||||||||
| 178 | # the caller's package name is whatever it is (could be "main") | ||||||||||||||||||||||||||||
| 179 | 3 | ▶ | printf STDOUT "%s %s\nperl v%vd\n", $program_name->(), ( caller( 2 ) // 'main' )->VERSION, $^V; | ||||||||||||||||||||||||||
|
Condition100%2/2
caller 2 // "main"
MC/DC100%1/1
caller 2 // "main"
caller 2
Truth table100%2/2
A
A= caller 2
| |||||||||||||||||||||||||||||
| 180 | 3 | EOOD | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 21 | ▶ | sub processopts ( \@@ ) { | ||||||||||||||||||||||||||
|
Subroutine
processopts: called CC=17 SCAR=28.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 184 | 21 | my $argv = shift; | |||||||||||||||||||||||||||
| 185 | 21 | my $spec_as_array = do { my $t = 0; [ grep $t ^= 1, @_ ] }; ## no critic ( RequireBlockGrep ) | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # Check each option specification individually (1) | ||||||||||||||||||||||||||||
| 188 | 21 | my $spec_as_hash; | |||||||||||||||||||||||||||
| 189 | 21 | parse_spec $_, %$spec_as_hash, 1 for @$spec_as_array; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 19 | my @argv_backup = @$argv; | |||||||||||||||||||||||||||
| 192 | 19 | ▶ | return FALSE unless getopts $spec_as_hash, my %opts, @$argv; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 17 | my @error; | |||||||||||||||||||||||||||
| 195 | # This ordered processing is a feature! | ||||||||||||||||||||||||||||
| 196 | 17 | ▶ | for ( my $i = 0 ; $i < @_ and not @error ; $i += 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i < @_ and not @error
MC/DC50%1/2
$i < @_ and not @error
$i < @_
not @error
Truth table66%2/3
A and not(B)
A= $i < @_B= not @error
| |||||||||||||||||||||||||||||
| 197 | # If $_[ $i ] refers to a flag with no indicator, the split still returns | ||||||||||||||||||||||||||||
| 198 | # the empty string (not undef!) as the value for the indicator | ||||||||||||||||||||||||||||
| 199 | 26 | my ( $name, $indicator ) = split //, $_[ $i ]; | |||||||||||||||||||||||||||
| 200 | 26 | ▶ | if ( exists $opts{ $name } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 24 | my $value = delete $opts{ $name }; | |||||||||||||||||||||||||||
| 202 | 24 | my $dest = $_[ $i + 1 ]; | |||||||||||||||||||||||||||
| 203 | # Do not use $_ on purpose | ||||||||||||||||||||||||||||
| 204 | # https://dev.to/matthewpersico/yet-another-perl-switch-statement-54h3 | ||||||||||||||||||||||||||||
| 205 | 24 | for my $dest_ref_type ( ref $dest ) { | |||||||||||||||||||||||||||
| 206 | 24 | ▶ | $dest_ref_type eq 'SCALAR' and ${ $dest } = $value, last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 17 | ▶ | $dest_ref_type eq 'ARRAY' and $indicator eq ',' and @{ $dest } = @$value, last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dest_ref_type eq "ARRAY" and $indicator eq ","
MC/DC100%2/2
$dest_ref_type eq "ARRAY" and $indicator eq ","
$dest_ref_type eq "ARRAY"
$indicator eq ","
Truth table100%3/3
A and B
A= $dest_ref_type eq "ARRAY"B= $indicator eq ","
| |||||||||||||||||||||||||||||
| 208 | 16 | ▶ | $dest_ref_type eq 'HASH' and $indicator eq '=' and %{ $dest } = %$value, last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dest_ref_type eq "HASH" and $indicator eq "="
MC/DC50%1/2
$dest_ref_type eq "HASH" and $indicator eq "="
$dest_ref_type eq "HASH"
$indicator eq "="
Truth table66%2/3
A and B
A= $dest_ref_type eq "HASH"B= $indicator eq "="
| |||||||||||||||||||||||||||||
| 209 | 15 | ▶ | if ( $dest_ref_type eq 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 14 | local $@; ## no critic ( RequireInitializationForLocalVars ) | |||||||||||||||||||||||||||
| 211 | 14 | ▶ | my $rv = eval { $dest->( $value, $name, $indicator ) // '' }; | ||||||||||||||||||||||||||
|
Condition100%2/2
&$dest($value, $name, $indicator) // ""
MC/DC100%1/1
&$dest($value, $name, $indicator) // ""
&$dest($value, $name, $indicator)
Truth table100%2/2
A
A= &$dest($value, $name, $indicator)
| |||||||||||||||||||||||||||||
| 212 | 14 | ▶ | @error = ( 'option callback destination throws an exception', $name, $@ ), last | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | unless defined $rv; | ||||||||||||||||||||||||||||
| 214 | # Callbacks are called in scalar context | ||||||||||||||||||||||||||||
| 215 | # If EOOD is the return value of the callback, | ||||||||||||||||||||||||||||
| 216 | # processopts() will terminate early. The return value will be | ||||||||||||||||||||||||||||
| 217 | # a special TRUE value. Using $name is not sufficient because 0 and 1 | ||||||||||||||||||||||||||||
| 218 | # are posible values for $name. | ||||||||||||||||||||||||||||
| 219 | 13 | ▶ | $rv eq EOOD ? return ( OD . $name ) : last | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | 1 | $croakf->( "'%s' is an unsupported destination reference type for the '%s' indicator", $dest_ref_type, $indicator ) | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 12 | ▶ | if ( @error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 1 | chomp @error; | |||||||||||||||||||||||||||
| 228 | # Restore to avoid side effects | ||||||||||||||||||||||||||||
| 229 | 1 | @$argv = @argv_backup; ## no critic ( RequireLocalizedPunctuationVars ) | |||||||||||||||||||||||||||
| 230 | # Prepare and print warning message: | ||||||||||||||||||||||||||||
| 231 | # Program name, eval error, and option character | ||||||||||||||||||||||||||||
| 232 | 1 | warn sprintf( "%s: %s -- %s\n%s\n", $program_name->(), @error ) ## no critic ( RequireCarping ) | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 12 | @error == 0 | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 6 | ▶ | sub readopts ( \@;@ ) { | ||||||||||||||||||||||||||
|
Subroutine
readopts: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 239 | 6 | my $argv = shift; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 6 | require File::Spec::Functions; | |||||||||||||||||||||||||||
| 242 | 6 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ENV{"XDG_CONFIG_HOME"} // File::Spec::Functions::catdir($ENV{"HOME"}, ".config")
MC/DC0%0/2
$ENV{"XDG_CONFIG_HOME"} // File::Spec::Functions::catdir($ENV{"HOME"}, ".config")
$ENV{"XDG_CONFIG_HOME"}
File::Spec::Functions::catdir($ENV{"HOME"}, ".config")
Truth table66%2/3
A // B
A= $ENV{"XDG_CONFIG_HOME"}B= File::Spec::Functions::catdir($ENV{"HOME"}, ".config")
| |||||||||||||||||||||||||||||
| 243 | -f ( | ||||||||||||||||||||||||||||
| 244 | my $file = File::Spec::Functions::catfile( | ||||||||||||||||||||||||||||
| 245 | $ENV{ XDG_CONFIG_HOME } // File::Spec::Functions::catdir( $ENV{ HOME }, '.config' ), | ||||||||||||||||||||||||||||
| 246 | $program_name->() . 'rc' | ||||||||||||||||||||||||||||
| 247 | ) | ||||||||||||||||||||||||||||
| 248 | ) | ||||||||||||||||||||||||||||
| 249 | ) | ||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||
| 251 | 4 | ▶ | open my $fh, '<:encoding(UTF-8)', $file ## no critic ( RequireBriefOpen ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | or $croakf->( "Cannot open file '%s' for reading (%s)", $file, $! ); | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 4 | ▶ | while ( <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 7 | chomp; | |||||||||||||||||||||||||||
| 256 | 7 | ▶ | next if m/\A (?: \#.* | ) \z/x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 7 | ▶ | if ( m/\A ( [[:alnum:]] ) (?: \ ( .+ ) )? \z/x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 6 | ▶ | unshift @$argv, ( OD . $1, defined $2 ? $2 : () ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | next | ||||||||||||||||||||||||||||
| 260 | 6 | } | |||||||||||||||||||||||||||
| 261 | 1 | $croakf->( "File '%s' contains the invalid line '%s'", $file, $_ ) | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | # Prepend hard defaults | ||||||||||||||||||||||||||||
| 266 | 5 | unshift @$argv, @_; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | return | ||||||||||||||||||||||||||||
| 269 | 5 | } | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 16 | 1 | |||||||||||||||||||||||||||