blib/lib/Config/Backend/INI.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 87.5% 14 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 92.6% 88 / 95 CC 12 SCAR 11.5
CC
12
Cov
94%
variables
5.0
new
4.2
set
3.0
CRAP 3.1
↑ Summary
1 package Config::Backend::INI;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Config::IniFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION='0.12';
8  
9 1 my $DEFSECT="!!Conf::INI!!default!!";
10  
11 1 ▶sub new {
Subroutine new: called CC=4 SCAR=14.5
Pod documented
12 1 my $class=shift;
13 1 my $file=shift;
14  
15 1 my $self;
16 my $ini;
17  
18 1 ▶ if ((-z $file) or (not -e $file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-z $file or not -e $file) 1 0 1
Condition33%1/3
-z $file or not -e $file
l!l&&r!l&&!r
010
MC/DC0%0/2
-z $file or not -e $file
-z $file not -e $file
Truth table33%1/3
A or not(B)
A= -z $fileB= not -e $file
ABresult
1X1
011
000
19 1 $ini=new Config::IniFiles();
20 1 $ini->newval($DEFSECT,$DEFSECT,1);
21 1 $ini->WriteConfig($file);
22 }
23 1 $ini=new Config::IniFiles(-file => $file);
24 1 ▶ if (not defined $ini) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ini) 0 1 1
25 0 die "Cannot open ini file $file\n";
26 }
27  
28 1 $self->{"ini"}=$ini;
29  
30 1 bless $self,$class;
31  
32 1 return $self;
33 }
34  
35 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
36 1 my $self=shift;
37 1 $self->{"ini"}->RewriteConfig();
38 }
39  
40 5 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
41 5 my $self=shift;
42 5 my $_var=shift;
43 5 my $val=shift;
44  
45 5 my ($section,$var)=split /[.]/,$_var,2;
46 5 ▶ if (not defined $var) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $var) 3 2 5
47 3 $var=$section;
48 3 $section=$DEFSECT;
49 }
50 5 ▶ if (not defined $self->{"ini"}->setval($section,$var,$val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"ini"}->setval($section, $var, $val)) 4 1 5
51 4 $self->{"ini"}->newval($section,$var,$val);
52 }
53  
54 5 $self->{"ini"}->RewriteConfig();
55  
56 }
57  
58 9 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
59 9 my $self=shift;
60 9 my $_var=shift;
61  
62 9 my ($section,$var)=split /[.]/,$_var,2;
63 9 ▶ if (not defined $var) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $var) 4 5 9
64 4 $var=$section;
65 4 $section=$DEFSECT;
66 }
67 9 return $self->{"ini"}->val($section,$var);
68 }
69  
70 2 ▶sub del {
Subroutine del: called CC=2 SCAR=6.9
Pod documented
71 2 my $self=shift;
72 2 my $_var=shift;
73  
74 2 my ($section,$var)=split /[.]/,$_var,2;
75 2 ▶ if (not defined $var) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $var) 1 1 2
76 1 $var=$section;
77 1 $section=$DEFSECT;
78 }
79 2 $self->{"ini"}->delval($section,$var);
80  
81 2 $self->{"ini"}->RewriteConfig();
82  
83 }
84  
85 2 ▶sub variables {
Subroutine variables: called CC=5 SCAR=16.1
Pod documented
86 2 my $self=shift;
87 2 my @vars;
88  
89 2 for my $s ($self->{"ini"}->Sections()) {
90 4 for my $v ($self->{"ini"}->Parameters($s)) {
91 8 ▶ if ($s eq $DEFSECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq $DEFSECT) { } 7 1 8
92 7 ▶ if ($v ne $DEFSECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $DEFSECT) 5 2 7
93 5 push @vars,$v;
94 }
95 }
96 else {
97 1 push @vars,"$s.$v";
98 }
99 }
100 }
101 2 return @vars;
102 }
103  
104 1 1;
105  
106 __END__
↑ Summary