| 1 | package Getopt::Pad::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | our @EXPORT_OK = qw(camelize specError expandTilde useColor isValidName); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | sub useColor($handle) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
useColor: called CC=6 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | return (-t $handle) && !length($ENV{NO_COLOR} // '') && (($ENV{TERM} // '') ne 'dumb') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%2/10
-t $handle and not length($ENV{"NO_COLOR"} // "") and ($ENV{"TERM"} // "") ne "dumb"
-t $handle and not length($ENV{"NO_COLOR"} // "")
$ENV{"NO_COLOR"} // ""
$ENV{"TERM"} // ""
MC/DC0%0/3
-t $handle and not length($ENV{"NO_COLOR"} // "") and ($ENV{"TERM"} // "") ne "dumb"
-t $handle
$ENV{"NO_COLOR"}
$ENV{"TERM"}
Truth table25%1/4
A and not(B) and C
A= -t $handleB= $ENV{"NO_COLOR"}C= $ENV{"TERM"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 95 | ▶ | sub expandTilde($path) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expandTilde: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 95 | ▶ | return $path if !defined $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 95 | return $path =~ s{^~(?=/|$)}{$ENV{HOME}}r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # The one shape an option name, an alias, an arg short name and a command | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # name share: a letter, then word characters or dashes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1303 | ▶ | sub isValidName($name) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isValidName: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1303 | ▶ | return defined $name && $name =~ /\A[a-zA-Z][\w-]*\z/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $name and $name =~ /\A[a-zA-Z][\w-]*\z/u
MC/DC100%2/2
defined $name and $name =~ /\A[a-zA-Z][\w-]*\z/u
defined $name
$name =~ /\A[a-zA-Z][\w-]*\z/u
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /\A[a-zA-Z][\w-]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1171 | ▶ | sub camelize($name) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
camelize: called CC=6 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1171 | ▶ | my ($first, @rest) = split /[-_]+/, $name // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$name // ""
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1171 | ▶ | specError("cannot derive a reader name from '%s'", $name // '') if !defined $first || $first eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
not defined $first or $first eq ""
$name // ""
MC/DC0%0/2
not defined $first or $first eq ""
not defined $first
$first eq ""
MC/DC0%0/1
$name // ""
$name
Truth table33%1/3
not(A) or B
A= not defined $firstB= $first eq ""
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1171 | my $reader = $first . join('', map { ucfirst } @rest); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1171 | ▶ | specError("derived reader name '%s' (from '%s') is not a valid identifier", $reader, $name) if $reader !~ /^[a-zA-Z_]\w*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1171 | return $reader; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Spec mistakes are programmer errors: report them at the first caller | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # outside Getopt::Pad, normally the GetOptions call, not at the library | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # frame that noticed them. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 54 | ▶ | sub specError($format, @args) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
specError: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 54 | my $frame = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 54 | ▶ | $frame++ while (caller($frame + 1))[0] && (caller($frame))[0] =~ /\AGetopt::Pad(?:::|\z)/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
(caller $frame + 1)[0] and (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
MC/DC100%2/2
(caller $frame + 1)[0] and (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
(caller $frame + 1)[0]
(caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
Truth table100%3/3
A and B
A= (caller $frame + 1)[0]B= (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 54 | my (undef, $file, $line) = caller($frame); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 54 | die sprintf("Getopt::Pad spec: %s at %s line %d.\n", sprintf($format, @args), $file, $line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||