| 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
Condition33%1/3
-z $file or not -e $file
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 47 | 3 | $var=$section; | |||||||||||||||||||||||||||
| 48 | 3 | $section=$DEFSECT; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 5 | ▶ | if (not defined $self->{"ini"}->setval($section,$var,$val)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 92 | 7 | ▶ | if ($v ne $DEFSECT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||