Commando/Option.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 6 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 92.0% 58 / 63 CC 6 SCAR 9.9
CC
6
Cov
100%
BUILDARGS
5.0
for_get_options
2.0
BEGIN
1.0
CRAP 2.7
« Commando/Command.pm ↑ Summary Commando/Logger.pm »
1 package App::Commando::Option;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 has 'config_key' => ( is => 'ro' );
9 9 has 'description' => ( is => 'ro' );
10 9 has 'long' => ( is => 'ro' );
11 9 has 'short' => ( is => 'ro' );
12 9 has 'spec' => ( is => 'ro' );
13  
14 41 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=5 SCAR=16.1
Pod undocumented
15 41 my ($class, $config_key, @info) = @_;
16  
17 41 my $buildargs = {
18 config_key => $config_key,
19 long => '',
20 short => '',
21 };
22  
23 # Getopt::Long regular expression to match argument specification
24 41 my $spec_re = qr(
25 # Either modifiers ...
26 [!+]
27 |
28 # ... or a value/dest/repeat specification
29 [=:] [ionfs] [@%]? (?: \{\d*,?\d*\} )?
30 |
31 # ... or an optional-with-default spec
32 : (?: -?\d+ | \+ ) [@%]?
33 )x;
34  
35 41 for my $arg (@info) {
36 122 ▶ if ($arg =~ /^-/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg =~ /^-/) { } 78 44 122
elsif ($arg =~ /$spec_re/) { } 4 40 44
37 78 ▶ if ($arg =~ /^--/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^--/) { } 39 39 78
38 39 $buildargs->{long} = $arg;
39 }
40 else {
41 39 $buildargs->{short} = $arg;
42 }
43 }
44 elsif ($arg =~ $spec_re) {
45 4 $buildargs->{spec} = $arg;
46 }
47 else {
48 40 $buildargs->{description} = $arg;
49 }
50 }
51  
52 41 return $buildargs;
53 }
54  
55 69 ▶sub for_get_options {
Subroutine for_get_options: called CC=2 SCAR=6.9
Pod undocumented
56 69 my ($self) = @_;
57  
58 return
59 join('|',
60 138 grep { /\S/ } # Exclude empty strings
61 138 map { s/^-+//; $_ } # Strip off leading dashes
62 69 ▶ map { $self->$_ } qw( short long )) .
Condition100%2/2
$self->spec || ''
l!l
168
MC/DC100%1/1
$self->spec || ''
$self->spec
Truth table100%2/2
A
A= $self->spec
Aresult
11
00
63 ($self->spec || '');
64 }
65  
66 19 ▶sub switches {
Subroutine switches: called CC=1 SCAR=0.0
Pod undocumented
67 19 my ($self) = @_;
68  
69 19 return [ $self->short, $self->long ];
70 }
71  
72 8 ▶sub formatted_switches {
Subroutine formatted_switches: called CC=1 SCAR=0.0
Pod undocumented
73 8 my ($self) = @_;
74  
75 8 my $output = join(', ',
76 sprintf("%10s", $self->switches->[0]),
77 sprintf("%-13s", $self->switches->[-1]));
78 8 $output =~ s/ , / /g;
79 8 $output =~ s/, / /g;
80  
81 8 return $output;
82 }
83  
84 5 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
85 5 my ($self) = @_;
86
87 5 return $self->formatted_switches . ' ' . $self->description;
88 }
89  
90 9 1;
91  
92 __END__
« Commando/Command.pm ↑ Summary Commando/Logger.pm »