Yath/Settings.pm

filter: Statementstmt 54.3% 31 / 57 Branchbran 31.2% 5 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 53.3% 8 / 15 Podpod 55.5% 5 / 9 totaltotal 46.6% 49 / 105 CC 12 SCAR 17.4
CC
12
Cov
46%
maybe
20.0
check_group
6.0
create_group
6.0
CRAP 5.7
« Yath/Option/BoolMap.pm ↑ Summary Yath/Option/Bool.pm »
1 package Getopt::Yath::Settings;
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.000007';
6  
7 1 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Getopt::Yath::Settings::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Getopt::Yath::Util qw/decode_json decode_json_file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 64 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
15 64 ▶ my $self = @_ == 1 ? $_[0] : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 64 0 64
16  
17 64 bless($self, $class);
18  
19 64 Getopt::Yath::Settings::Group->new($_) for values %$self;
20  
21 64 return $self;
22 }
23  
24 sub maybe {
25 0 ▶ my $self = shift;
Subroutine maybe: not called CC=4 SCAR=30.0
Pod documented
26 0 my ($group, $opt, $default) = @_;
27  
28 0 ▶ return $default unless $self->check_group($group);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->check_group($group) 0 0 0
29  
30 0 my $g = $self->$group;
31  
32 0 ▶ return $default unless $g->check_option($opt);
Branch: 1 branch
BranchTrueFalseTotal
unless $g->check_option($opt) 0 0 0
33  
34 0 ▶ return $g->$opt // $default;
Condition0%0/3
$g->$opt // $default
l!l&&r!l&&!r
000
MC/DC0%0/2
$g->$opt // $default
$g->$opt $default
Truth table0%0/3
A // B
A= $g->$optB= $default
ABresult
1X1
011
000
35 }
36  
37 0 ▶sub check_group { $_[0]->{$_[1]} // 0 }
Subroutine check_group: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
$_[0]{$_[1]} // 0
l!l
00
MC/DC0%0/1
$_[0]{$_[1]} // 0
$_[0]{$_[1]}
Truth table0%0/2
A
A= $_[0]{$_[1]}
Aresult
11
00
38  
39 sub group {
40 1426 ▶ my $self = shift;
Subroutine group: called CC=3 SCAR=11.3
Pod documented
41 1426 my ($group, $vivify) = @_;
42  
43 1426 ▶ return $self->{$group} if $self->{$group};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$group} 1364 62 1426
44  
45 62 ▶ return $self->{$group} = Getopt::Yath::Settings::Group->new()
Branch: 1 branch
BranchTrueFalseTotal
if $vivify 62 0 62
46 if $vivify;
47  
48 0 Carp::confess("The '$group' group is not defined");
49 }
50  
51 sub create_group {
52 0 ▶ my $self = shift;
Subroutine create_group: not called CC=2 SCAR=17.9
Pod documented
53 0 my ($name, @vals) = @_;
54  
55 0 ▶ return $self->{$name} = Getopt::Yath::Settings::Group->new(@vals == 1 ? $vals[0] : { @vals });
Branch: 1 branch
BranchTrueFalseTotal
@vals == 1 ? : 0 0 0
56 }
57  
58 sub delete_group {
59 0 ▶ my $self = shift;
Subroutine delete_group: not called CC=1 SCAR=6.9
Pod documented
60 0 my ($name) = @_;
61  
62 0 delete $self->{$name};
63 }
64  
65 1 our $AUTOLOAD;
66 sub AUTOLOAD {
67 64 ▶ my $this = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=14.2
68  
69 64 my $group = $AUTOLOAD;
70 64 $group =~ s/^.*:://g;
71  
72 64 ▶ return if $group eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $group eq "DESTROY" 64 0 64
73  
74 0 ▶ Carp::confess("Method $group() must be called on a blessed instance") unless ref($this);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 0 0
75  
76 0 $this->group($group);
77 }
78  
79 sub FROM_JSON_FILE {
80 0 ▶ my $class = shift;
Subroutine FROM_JSON_FILE: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my ($file, %params) = @_;
82  
83 0 my $data = decode_json_file($file, %params);
84 0 $class->new($data);
85 }
86  
87 sub FROM_JSON {
88 0 ▶ my $class = shift;
Subroutine FROM_JSON: not called CC=1 SCAR=6.9
Pod undocumented
89 0 my ($json) = @_;
90  
91 0 my $data = decode_json($json);
92 0 $class->new($data);
93 }
94  
95 sub TO_JSON {
96 0 ▶ my $self = shift;
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
97 0 return {%$self};
98 }
99  
100 1 1;
101  
102 __END__
« Yath/Option/BoolMap.pm ↑ Summary Yath/Option/Bool.pm »