Yath/Option/Map.pm

filter: Statementstmt 85.7% 78 / 91 Branchbran 50.0% 11 / 22 Conditioncond 66.6% 8 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 95.2% 20 / 21 Podpod 0.0% 0 / 15 totaltotal 71.2% 119 / 167 CC 21 SCAR 15.2
CC
21
Cov
78%
normalize_value
10.1
get_initial_value
9.5
_example_append
5.0
CRAP 4.6
« Yath/Option/Bool.pm ↑ Summary Yath/Option/List.pm »
1 package Getopt::Yath::Option::Map;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '2.000008';
6  
7 1 ▶use Getopt::Yath::Util qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use parent 'Getopt::Yath::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Getopt::Yath::HashBase qw/<split_on <key_on/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶sub allows_list { 1 }
Subroutine allows_list: called CC=1 SCAR=0.0
Pod undocumented
13 1 ▶sub allows_default { 1 }
Subroutine allows_default: called CC=1 SCAR=0.0
Pod undocumented
14 6 ▶sub allows_arg { 1 }
Subroutine allows_arg: called CC=1 SCAR=0.0
Pod undocumented
15 5 ▶sub requires_arg { 1 }
Subroutine requires_arg: called CC=1 SCAR=0.0
Pod undocumented
16 0 ▶sub allows_autofill { 0 }
Subroutine allows_autofill: not called CC=1 SCAR=6.9
Pod undocumented
17 1 ▶sub requires_autofill { 0 }
Subroutine requires_autofill: called CC=1 SCAR=0.0
Pod undocumented
18  
19 4 ▶sub notes { (shift->SUPER::notes(), 'Can be specified multiple times') }
Subroutine notes: called CC=1 SCAR=0.0
Pod undocumented
20  
21 sub _example_append {
22 4 ▶ my $self = shift;
Subroutine _example_append: called CC=5 SCAR=16.1
23 4 my ($params, @prefixes) = @_;
24  
25 4 ▶ return unless $self->allows_list;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->allows_list 0 4 4
26  
27 4 ▶ my $groups = $params->{groups} // {};
Condition100%2/2
$params->{"groups"} // {}
l!l
22
MC/DC100%1/1
$params->{"groups"} // {}
$params->{"groups"}
Truth table100%2/2
A
A= $params->{"groups"}
Aresult
11
00
28  
29 4 my @out;
30  
31 4 for my $prefix (@prefixes) {
32 10 for my $group (sort keys %$groups) {
33 5 push @out => "${prefix}${group} KEY1 VAL KEY2 ${group} VAL1 VAL2 ... $groups->{$group} ... $groups->{$group}";
34 }
35 }
36  
37 4 return @out;
38 }
39  
40 sub default_long_examples {
41 2 ▶ my $self = shift;
Subroutine default_long_examples: called CC=1 SCAR=0.0
Pod undocumented
42 2 my %params = @_;
43  
44 2 my @append = $self->_example_append(\%params, ' ', '=');
45  
46 2 return [' key=val', '=key=val', qq[ '{"json":"hash"}'], qq[='{"json":"hash"}'], @append];
47 }
48  
49 sub default_short_examples {
50 2 ▶ my $self = shift;
Subroutine default_short_examples: called CC=1 SCAR=0.0
Pod undocumented
51 2 my %params = @_;
52  
53 2 my @append = $self->_example_append(\%params, '', ' ', '=');
54  
55 2 return [' key=val', 'key=value', '=key=val', qq[ '{"json":"hash"}'], qq[='{"json":"hash"}'], @append];
56 }
57  
58 sub init {
59 2 ▶ my $self = shift;
Subroutine init: called CC=2 SCAR=7.1
Pod undocumented
60  
61 2 $self->SUPER::init();
62  
63 2 ▶ $self->{+KEY_ON} //= '=';
Condition50%1/2
$self->{"key_on"} //= "="
l!l
02
MC/DC0%0/1
$self->{"key_on"} //= "="
$self->{"key_on"}
Truth table50%1/2
A
A= $self->{"key_on"}
Aresult
11
00
64 }
65  
66 48 ▶sub is_populated { ${$_[1]} && keys %{${$_[1]}} }
Subroutine is_populated: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
${$_[1];} and keys %{${$_[1];};} 7 41 48
67  
68 sub get_initial_value {
69 54 ▶ my $self = shift;
Subroutine get_initial_value: called CC=7 SCAR=22.5
Pod undocumented
70  
71 54 my %val;
72  
73 54 my $env = $self->from_env_vars;
74 54 ▶ for my $name (@{$env || []}) {
Branch: 1 branch
BranchTrueFalseTotal
$env or [] 54 0 54
75 0 ▶ $val{$name} = $ENV{$name} if defined $ENV{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{$name} 0 0 0
76 }
77  
78 54 ▶ return \%val if keys %val;
Branch: 1 branch
BranchTrueFalseTotal
if keys %val 0 54 54
79  
80 54 ▶ return undef if $self->{+MAYBE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"maybe"} 0 54 54
81  
82 54 ▶ return $self->_get___value(INITIALIZE()) // {};
Condition50%1/2
$self->_get___value("initialize") // {}
l!l
054
MC/DC0%0/1
$self->_get___value("initialize") // {}
$self->_get___value("initialize")
Truth table50%1/2
A
A= $self->_get___value("initialize")
Aresult
11
00
83 }
84  
85 sub get_clear_value {
86 2 ▶ my $self = shift;
Subroutine get_clear_value: called CC=2 SCAR=7.2
Pod undocumented
87 2 ▶ return $self->_get___value(CLEAR(), @_) // {};
Condition50%1/2
$self->_get___value("clear", @_) // {}
l!l
02
MC/DC0%0/1
$self->_get___value("clear", @_) // {}
$self->_get___value("clear", @_)
Truth table50%1/2
A
A= $self->_get___value("clear", @_)
Aresult
11
00
88 }
89  
90 sub add_value {
91 105 ▶ my $self = shift;
Subroutine add_value: called CC=3 SCAR=11.0
Pod undocumented
92 105 my ($ref, %vals) = @_;
93  
94 105 ▶ return unless keys %vals;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %vals 54 51 105
95  
96 51 ▶ $$ref //= {};
Condition100%2/2
$$ref //= {}
l!l
249
MC/DC100%1/1
$$ref //= {}
$$ref
Truth table100%2/2
A
A= $$ref
Aresult
11
00
97  
98 51 %{$$ref} = (
99 51 %{$$ref},
100 %vals,
101 );
102 }
103  
104 sub normalize_value {
105 8 ▶ my $self = shift;
Subroutine normalize_value: called CC=6 SCAR=23.2
Pod undocumented
106 8 my (@input) = @_;
107  
108 8 ▶ return $self->SUPER::normalize_value(@input) if @input > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @input > 1 0 8 8
109  
110 8 ▶ if ($input[0] =~ m/^\s*\{.*\}\s*$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[0] =~ /^\s*\{.*\}\s*$/s) 0 8 8
111 0 my $out;
112 0 local $@;
113 0 ▶ unless (eval { local $SIG{__DIE__}; $out = decode_json($input[0]); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { local $SIG{"__DIE__"}; $out = decode_json($input[0]); 1 } }) 0 0 0
114 0 my ($err) = split /[\n\r]+/, $@;
115 0 $err =~ s{at \Q$INC{'Getopt/Yath/Util/JSON.pm'}\E line \d+\..*$}{};
116 0 die "Could not decode JSON string: $err\n====\n$input[0]\n====\n";
117 }
118 0 return %$out;
119 }
120  
121 8 my @split;
122 8 ▶ if (my $on = $self->split_on) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $on = $self->split_on) { } 8 0 8
123 8 @split = grep { length($_) } map { split($on, $_) } @input;
124 }
125 else {
126 0 @split = @input;
127 }
128  
129 8 ▶ my $key_on = $self->key_on // '=';
Condition50%1/2
$self->key_on // "="
l!l
80
MC/DC0%0/1
$self->key_on // "="
$self->key_on
Truth table50%1/2
A
A= $self->key_on
Aresult
11
00
130 8 my %output = map { my ($k, $v) = split($key_on, $_, 2); $self->SUPER::normalize_value($k, $v) } @split;
131  
132 8 return %output;
133 }
134  
135 1 1;
136  
137 __END__
« Yath/Option/Bool.pm ↑ Summary Yath/Option/List.pm »