| 1 | package Getopt::Pad; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Feature::Compat::Try; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Getopt::Pad::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Getopt::Pad::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Getopt::Pad::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use Getopt::Pad::Completion; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use Getopt::Pad::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use Getopt::Pad::ExitRequest; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 6 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 21 | 6 | our @EXPORT = qw(GetOptions); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 32 | ▶ | sub GetOptions(%raw) { | ||||||||||||||||||||||||||
|
Subroutine
GetOptions: called CC=10 SCAR=39.7
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 32 | ▶ | my $argv = delete $raw{argv} // [@ARGV]; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $raw{"argv"} // [@ARGV]
MC/DC0%0/1
delete $raw{"argv"} // [@ARGV]
delete $raw{"argv"}
Truth table50%1/2
A
A= delete $raw{"argv"}
| |||||||||||||||||||||||||||||
| 25 | 32 | ▶ | Getopt::Pad::Util::specError("'argv' must be an array reference") if ref $argv ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 32 | my $spec = Getopt::Pad::Spec->new(raw => \%raw); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # A generated completion script asking for candidates: answer it | ||||||||||||||||||||||||||||
| 30 | # instead of parsing. | ||||||||||||||||||||||||||||
| 31 | 31 | ▶ | if (defined $ENV{Getopt::Pad::Completion->SHELL_VARIABLE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | print Getopt::Pad::Completion->new(spec => $spec)->renderCandidates($argv, $ENV{Getopt::Pad::Completion->INDEX_VARIABLE}); | |||||||||||||||||||||||||||
| 33 | 0 | exit 0; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 31 | my $parser = Getopt::Pad::Parser->new(spec => $spec, argv => $argv); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 31 | try { | |||||||||||||||||||||||||||
| 39 | 31 | return $parser->parse; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | catch ($error) { | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (blessed($error) && $error->isa('Getopt::Pad::ExitRequest')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($error) and $error->isa("Getopt::Pad::ExitRequest")
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Getopt::Pad::ExitRequest")
builtin::blessed($error)
$error->isa("Getopt::Pad::ExitRequest")
Truth table0%0/3
A and B
A= builtin::blessed($error)B= $error->isa("Getopt::Pad::ExitRequest")
| |||||||||||||||||||||||||||||
| 43 | 0 | print $error->output; | |||||||||||||||||||||||||||
| 44 | 0 | exit 0; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | die $error if !blessed($error) || !$error->isa('Getopt::Pad::Error'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($error) and $error->isa("Getopt::Pad::Error")
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Getopt::Pad::Error")
builtin::blessed($error)
$error->isa("Getopt::Pad::Error")
Truth table0%0/3
A and B
A= builtin::blessed($error)B= $error->isa("Getopt::Pad::Error")
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $errorTag = Getopt::Pad::Util::useColor(\*STDERR) ? "\e[1;31mERROR\e[0m" : 'ERROR'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | print {*STDERR} sprintf("%s: %s\n", $errorTag, $error); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (defined $error->level) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | print {*STDERR} "\n"; | |||||||||||||||||||||||||||
| 52 | 0 | $spec->helperFor($error->level, handle => \*STDERR)->printHelp; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | exit 2; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 6 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||