Pad.pm

filter: Statementstmt 77.6% 52 / 67 Branchbran 21.4% 3 / 14 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 65.1% 71 / 109 CC 11 SCAR 31.6
CC
11
Cov
63%
GetOptions
50.3
BEGIN
1.0
BEGIN
1.0
CRAP 23.6
↑ Summary Pad/Completion.pm »
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
BranchTrueFalseTotal
if @pairs % 2 0 32 32
25  
26 32 my %raw = @pairs;
27 32 ▶ my $rawArgv = delete $raw{argv} // [@ARGV];
Condition50%1/2
delete $raw{"argv"} // [@ARGV]
l!l
320
MC/DC0%0/1
delete $raw{"argv"} // [@ARGV]
delete $raw{"argv"}
Truth table50%1/2
A
A= delete $raw{"argv"}
Aresult
11
00
28 32 ▶ Getopt::Pad::Util::specError("'argv' must be an array reference") if ref $rawArgv ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rawArgv ne "ARRAY" 0 32 32
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
BranchTrueFalseTotal
if (defined $ENV{"Getopt::Pad::Completion"->SHELL_VARIABLE}) 0 31 31
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
BranchTrueFalseTotal
if (builtin::blessed($error) and $error->isa("Getopt::Pad::ExitRequest")) 0 0 0
Condition0%0/3
builtin::blessed($error) and $error->isa("Getopt::Pad::ExitRequest")
!ll&&!rl&&r
000
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless builtin::blessed($error) and $error->isa("Getopt::Pad::Error") 0 0 0
Condition0%0/3
builtin::blessed($error) and $error->isa("Getopt::Pad::Error")
!ll&&!rl&&r
000
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")
ABresult
0X0
100
111
52  
53 0 ▶ my $errorTag = Getopt::Pad::Util::useColor(\*STDERR) ? "\e[1;31mERROR\e[0m" : 'ERROR';
Branch: 1 branch
BranchTrueFalseTotal
Getopt::Pad::Util::useColor(\*STDERR) ? : 0 0 0
54 0 print {*STDERR} Getopt::Pad::Util::encodedFor(\*STDERR, sprintf("%s: %s\n", $errorTag, $error));
55 0 ▶ if (defined $error->level) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error->level) 0 0 0
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__
↑ Summary Pad/Completion.pm »