| 1 | package Zoidberg::Utils::GetOpt; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 63 | our $VERSION = '0.981'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 63 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 63 | ▶ | use Zoidberg::Utils::Error qw/error bug/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 63 | ▶ | use Zoidberg::Utils::Output qw/output debug/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | use Exporter::Tidy | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 63 | ▶ | default => ['getopt'], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 63 | other => [qw/help usage version path2hashref/] ; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 63 | our $ERROR_CALLER = 1; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 273 | ▶ | sub getopt { # hic sunt leones | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getopt: called CC=69 SCAR=44.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 273 | my ($conf, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 273 | my (%conf, @opts, %opts, $args); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 273 | ▶ | if (ref $conf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | %conf = %$conf; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | goto PARSE_OPTS; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # parse config | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 272 | ▶ | $conf{_args} = $1 if $conf =~ s/(?<!\S)([\@\%\*])\s*$//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 272 | ▶ | goto PARSE_ARGS unless $conf and $args[0] =~ /^[+-]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$conf and $args[0] =~ /^[+-]/
MC/DC100%2/2
$conf and $args[0] =~ /^[+-]/
$conf
$args[0] =~ /^[+-]/
Truth table100%3/3
A and B
A= $confB= $args[0] =~ /^[+-]/
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 60 | for (split /\s+/, $conf) { | |||||||||||||||||||||||||||||||||||||||||
| 26 | 908 | ▶ | my $arg = s/([\$\@\%])$// ? $1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 908 | my ($opt, @al) = split ',', $_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 908 | ▶ | unless ($opt =~ s/\*$//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 726 | $conf{$opt} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 726 | $conf{_alias}{$_} = $opt for @al; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 182 | ▶ | error 'config syntax error' if @al || ! length $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@al or not length $_
MC/DC0%0/2
@al or not length $_
@al
not length $_
Truth table33%1/3
A or not(B)
A= @alB= not length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 182 | $conf{$opt} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 182 | ▶ | $conf{_glob} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$conf{"_glob"} ||= []
MC/DC100%1/1
$conf{"_glob"} ||= []
$conf{"_glob"}
Truth table100%2/2
A
A= $conf{"_glob"}
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 182 | push @{$conf{_glob}}, $opt; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 60 | ▶ | $conf{_glob} = '^('.join('|', map {s/^\+/\\+/; $_} @{$conf{_glob}}).')(?!-)' if $conf{_glob}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | #use Data::Dumper; print STDERR 'conf: ', Dumper \%conf; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | PARSE_OPTS: | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 61 | for ( # set default options | |||||||||||||||||||||||||||||||||||||||||
| 44 | [qw/h help/, \&help ], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | [qw/u usage/, \&usage ], | ||||||||||||||||||||||||||||||||||||||||||
| 46 | [qw/v version/, \&version] | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 183 | ▶ | next if exists $conf{$$_[1]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 93 | $conf{$$_[1]} = $$_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 50 | $conf{_alias}{'-'.$$_[0]} = $$_[1] | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 93 | ▶ | unless exists $conf{_alias}{'-'.$$_[0]} or exists $conf{_alias}{$$_[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $conf{"_alias"}{'-' . $_->[0]} or exists $conf{"_alias"}{$_->[0]}
MC/DC50%1/2
exists $conf{"_alias"}{'-' . $_->[0]} or exists $conf{"_alias"}{$_->[0]}
exists $conf{"_alias"}{'-' . $_->[0]}
exists $conf{"_alias"}{$_->[0]}
Truth table66%2/3
A or B
A= exists $conf{"_alias"}{'-' . $_->[0]}B= exists $conf{"_alias"}{$_->[0]}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 61 | my $delim = 0; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 61 | ▶ | while (@args) { # parse opts | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 124 | ▶ | last unless $args[0] =~ /^(-|\+.)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 118 | $_ = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 118 | /^(--|-|\+)(.*)/; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 118 | ▶ | ++$delim and last unless length $2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
length $2 || ++$delim && (last)
++$delim and last
MC/DC0%0/2
length $2 || ++$delim && (last)
length $2
++$delim
Truth table66%2/3
A || B
A= length $2B= ++$delim
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 117 | my ($pre, $opt, $arg) = ($1, split '=', $2, 2); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 117 | my (@chars, $type); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 117 | my $raw = $pre.$opt; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 117 | ▶ | if (exists $conf{_alias}{$raw} or exists $conf{$raw}) { $opt = $raw } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
exists $conf{"_alias"}{$raw} or exists $conf{$raw}
MC/DC100%2/2
exists $conf{"_alias"}{$raw} or exists $conf{$raw}
exists $conf{"_alias"}{$raw}
exists $conf{$raw}
Truth table100%3/3
A or B
A= exists $conf{"_alias"}{$raw}B= exists $conf{$raw}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | ▶ | elsif (exists $conf{_glob} and $raw =~ /$conf{_glob}/) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
exists $conf{"_glob"} and $raw =~ /$conf{"_glob"}/
MC/DC50%1/2
exists $conf{"_glob"} and $raw =~ /$conf{"_glob"}/
exists $conf{"_glob"}
$raw =~ /$conf{"_glob"}/
Truth table66%2/3
A and B
A= exists $conf{"_glob"}B= $raw =~ /$conf{"_glob"}/
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | $opt = $raw; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | $type = $conf{$1}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ▶ | elsif ($pre ne '--' and length $opt > 1) { # try short options | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$pre ne "--" and length $opt > 1
MC/DC100%2/2
$pre ne "--" and length $opt > 1
$pre ne "--"
length $opt > 1
Truth table100%3/3
A and B
A= $pre ne "--"B= length $opt > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | @chars = split '', $opt; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | PARSE_OPT: | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 120 | ▶ | $opt = shift @chars if @chars; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 120 | ▶ | $opt = $conf{_alias}{$opt} if exists $conf{_alias}{$opt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 120 | ▶ | unless (defined $type) { # type is set if glob | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 117 | ▶ | if (exists $conf{$opt}) { $type = $conf{$opt} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | else { error "unrecognized option '$opt'" } | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 119 | push @opts, $opt; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 119 | ▶ | if (! $type) { # no arg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 18 | ▶ | error "option '$opt' doesn't take an argument" if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 18 | ▶ | $opts{$opt} = ($pre eq '+') ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | elsif (ref $type) { # CODE ... for default opts | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | output $type->( (caller(1))[3], (caller)[0] ); # subroutine, package | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | error {silent => 1, exit_status => 0}, 'getopt needed to pop stack'; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 101 | ▶ | $arg = defined($arg) ? $arg : shift(@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 101 | ▶ | error "option '$opt' requires an argument" unless defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 101 | ▶ | if ($type eq '$') { $opts{$opt} = $arg } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | elsif ($type eq '@') { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 97 | ▶ | if (ref $arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | error 'argument is not a ARRAY reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | if ref($arg) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($opts{$opt}) { push @{$opts{$opt}}, @$arg } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | else { $opts{$opt} = $arg } | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 96 | ▶ | $opts{$opt} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{$opt} ||= []
MC/DC100%1/1
$opts{$opt} ||= []
$opts{$opt}
Truth table100%2/2
A
A= $opts{$opt}
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 96 | push @{$opts{$opt}}, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 119 | $arg = $type = undef; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 119 | ▶ | goto PARSE_OPT if @chars; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 60 | ▶ | error @opts | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not $delim and grep /^-/, @args
MC/DC100%2/2
not $delim and grep /^-/, @args
not $delim
grep /^-/, @args
Truth table100%3/3
not(A) and B
A= not $delimB= grep /^-/, @args
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | ? "option '$opts[-1]' doesn't take an argument" | ||||||||||||||||||||||||||||||||||||||||||
| 113 | : 'options found after first argument' if !$delim and grep /^-/, @args; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 59 | ▶ | $opts{_opts} = \@opts if @opts; # keep %opts empty unless there are opts | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | PARSE_ARGS: # parse args | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 271 | ▶ | unless ($conf{_args}) { $args = [@args] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ($conf{_args} eq '@') { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | error "argument should be a ARRAY reference" | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 175 | ▶ | if grep {ref($_) and ref($_) ne 'ARRAY'} @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_ && ref $_ ne 'ARRAY'
MC/DC0%0/2
ref $_ && ref $_ ne 'ARRAY'
ref $_
ref $_ ne 'ARRAY'
Truth table33%1/3
A && B
A= ref $_B= ref $_ ne 'ARRAY'
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if (ref $args[0] and @args == 1) { $args = $args[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args[0] and @args == 1
MC/DC0%0/2
ref $args[0] and @args == 1
ref $args[0]
@args == 1
Truth table33%1/3
A and B
A= ref $args[0]B= @args == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 175 | ▶ | else { $args = [ map {ref($_) ? @$_ : $_} @args] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | elsif ($conf{_args} eq '%') { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | error "argument should be a HASH reference" | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 66 | ▶ | if grep {ref($_) and ref($_) ne 'HASH'} @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_ && ref $_ ne 'HASH'
MC/DC0%0/2
ref $_ && ref $_ ne 'HASH'
ref $_
ref $_ ne 'HASH'
Truth table66%2/3
A && B
A= ref $_B= ref $_ ne 'HASH'
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 66 | ▶ | if (ref $args[0] and @args == 1) { $args = $args[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $args[0] and @args == 1
MC/DC50%1/2
ref $args[0] and @args == 1
ref $args[0]
@args == 1
Truth table66%2/3
A and B
A= ref $args[0]B= @args == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 130 | $args = { map { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (ref $_) { (%$_) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | m/(.*?)=(.*)/ or $error++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | ($1 => $2) | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } @args }; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | error 'syntax error, should be \'key=value\'' if $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif ($conf{_args} eq '*') { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 21 | my (@keys, %vals); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 21 | for (@args) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 28 | ▶ | if (ref $_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | my $t = ref $_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | if ($t eq 'ARRAY') { push @keys, @$_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | elsif ($t eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | push @keys, keys %$_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | %vals = (%vals, %$_); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | else { error "can't handle $t reference argument" } | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif (m/(.*?)=(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 12 | push @keys, $1; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 12 | $vals{$1} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 14 | else { push @keys, $_ } | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 21 | return \%opts, \@keys, \%vals; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 250 | return \%opts, $args; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $_[2] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | goto &help; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my ($cmd, $file, $usage) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $cmd ||= (caller(1))[3]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cmd ||= (caller 1)[3]
MC/DC0%0/2
$cmd ||= (caller 1)[3]
$cmd
(caller 1)[3]
Truth table0%0/3
A ||= B
A= $cmdB= (caller 1)[3]
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $file = $1 if $cmd =~ s/(.*):://; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $file =~ s/::/\//g; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $file =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | ($file) = grep {-e $_} map {("$_/$file.pod", "$_/$file.pm")} @INC | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | unless $file =~ m#^/#; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | open POD, $file || error "Could not read $file"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$file || error("Could not read $file")
MC/DC0%0/2
$file || error("Could not read $file")
$file
error("Could not read $file")
Truth table0%0/3
A || B
A= $fileB= error("Could not read $file")
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ($help, $p, $o) = ('', 0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | while (<POD>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($p) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if (/^=over/) { $o++ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | elsif (/^=back/) { $o-- } | |||||||||||||||||||||||||||||||||||||||||
| 185 | elsif (/^=(item(?!\s+$cmd)|back|cut)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | last unless $o; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $help .= $_ unless $usage and ! $o and ! /^=item\s+$cmd/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$usage and not $o and not /^=item\s+$cmd/
$usage and not $o
MC/DC0%0/3
$usage and not $o and not /^=item\s+$cmd/
$usage
not $o
not /^=item\s+$cmd/
Truth table0%0/4
A and not(B) and not(C)
A= $usageB= not $oC= not /^=item\s+$cmd/
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | # only return 'item' lines if short format | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | elsif (/^=item\s+$cmd/) { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $p = 1; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $help = $_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | close POD; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $help =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ($usage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $help =~ s/^=item\s+/ /gm; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $help = "usage:\n".$help; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | else { $help =~ s/^=\w+\s+/= /gm } | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $help =~ s/(\w)<<(.*?)>>|\w<(.*?)>/ | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | ($1 eq 'B') ? "\"$2$3\"" : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | ($1 eq 'C') ? "`$2$3`" : "'$2$3'" | ||||||||||||||||||||||||||||||||||||||||||
| 207 | /ge; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return $help; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my (undef, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 63 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return ${$class.'::LONG_VERSION'} || $class.' '.${$class.'::VERSION'}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
${$class . '::LONG_VERSION';} || $class . ' ' . ${$class . '::VERSION';}
MC/DC0%0/1
${$class . '::LONG_VERSION';} || $class . ' ' . ${$class . '::VERSION';}
${$class . '::LONG_VERSION';}
Truth table0%0/2
A
A= ${$class . '::LONG_VERSION';}
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 10 | ▶ | sub path2hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path2hashref: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 10 | my ($hash, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 10 | my $path = '/'; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 10 | ▶ | while ($key =~ s#^/*(.+?)/##) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 10 | $path .= $1 . '/'; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 10 | ▶ | if (! defined $$hash{$1}) { $$hash{$1} = {} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | elsif (ref($$hash{$1}) ne 'HASH') { return undef, undef, $path } # bail out | |||||||||||||||||||||||||||||||||||||||||
| 224 | 10 | $hash = $$hash{$1}; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 10 | return $hash, $key, $path; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 63 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | __END__ | ||||||||||||||||||||||||||||||||||||||||||