| 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.06'; | |||||||||||||||||||||||||||
| 21 | 6 | our @EXPORT = qw(GetOptions); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 32 | ▶ | sub GetOptions(@pairs) { | ||||||||||||||||||||||||||
|
Subroutine
GetOptions: called CC=11 SCAR=39.2
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 32 | ▶ | Getopt::Pad::Util::specError('GetOptions expects key/value pairs') if @pairs % 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 32 | my %raw = @pairs; | |||||||||||||||||||||||||||
| 27 | 32 | ▶ | my $rawArgv = 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"}
| |||||||||||||||||||||||||||||
| 28 | 32 | ▶ | Getopt::Pad::Util::specError("'argv' must be an array reference") if ref $rawArgv ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 32 | my $argv = [map { Getopt::Pad::Util::decodedWord($_) } $rawArgv->@*]; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 32 | my $spec = Getopt::Pad::Spec->new(raw => \%raw); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # A generated completion script asking for candidates: answer it | ||||||||||||||||||||||||||||
| 34 | # instead of parsing. | ||||||||||||||||||||||||||||
| 35 | 31 | ▶ | if (defined $ENV{Getopt::Pad::Completion->SHELL_VARIABLE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | my $candidates = Getopt::Pad::Completion->new(spec => $spec)->renderCandidates($argv, $ENV{Getopt::Pad::Completion->INDEX_VARIABLE}); | |||||||||||||||||||||||||||
| 37 | 0 | print Getopt::Pad::Util::encodedFor(\*STDOUT, $candidates); | |||||||||||||||||||||||||||
| 38 | 0 | exit 0; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 31 | my $parser = Getopt::Pad::Parser->new(spec => $spec, argv => $argv); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 31 | try { | |||||||||||||||||||||||||||
| 44 | 31 | return $parser->parse; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | catch ($error) { | ||||||||||||||||||||||||||||
| 47 | 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")
| |||||||||||||||||||||||||||||
| 48 | 0 | print Getopt::Pad::Util::encodedFor(\*STDOUT, $error->output); | |||||||||||||||||||||||||||
| 49 | 0 | exit 0; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 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")
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $errorTag = Getopt::Pad::Util::useColor(\*STDERR) ? "\e[1;31mERROR\e[0m" : 'ERROR'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | print {*STDERR} Getopt::Pad::Util::encodedFor(\*STDERR, sprintf("%s: %s\n", $errorTag, $error)); | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (defined $error->level) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | print {*STDERR} "\n"; | |||||||||||||||||||||||||||
| 57 | 0 | $spec->helperFor($error->level, handle => \*STDERR)->printHelp; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | exit 2; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 6 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||