lib/Rex/Helper/INI.pm

filter: Statementstmt 84.2% 48 / 57 Branchbran 80.0% 16 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 83.9% 73 / 87 CC 19 SCAR 29.1
CC
19
Cov
84%
parse
21.1
BEGIN
1.0
BEGIN
1.0
CRAP 18.4
« lib/Rex/Box/Amazon.pm ↑ Summary blib/lib/Rex/Logger.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Helper::INI;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶BEGIN { String::Escape->use('string2hash'); }
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub parse {
Subroutine parse: called CC=19 SCAR=30.5
Pod undocumented
15 1 my (@lines) = @_;
16 1 my $ini;
17  
18 my $section;
19 1 for (@lines) {
20 39 chomp;
21 39 s/\n|\r//g;
22  
23 39 ▶ (/^#|^;|^\s*$/) && (next);
Branch: 1 branch
BranchTrueFalseTotal
/^#|^;|^\s*$/u and next 12 27 39
24  
25 27 ▶ if ( /^\[(.*)\]/ && !/^\[(\d+((?:,)|(?:\.\.))*)+(\/\d+)*\]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\[(.*)\]/u and not m(^\[(\d+((?:,)|(?:\.\.))*)+(/\d+)*\])u) 9 18 27
Condition100%3/3
/^\[(.*)\]/u and not m(^\[(\d+((?:,)|(?:\.\.))*)+(/\d+)*\])u
!ll&&!rl&&r
1449
MC/DC100%2/2
/^\[(.*)\]/u and not m(^\[(\d+((?:,)|(?:\.\.))*)+(/\d+)*\])u
/^\[(.*)\]/u not m(^\[(\d+((?:,)|(?:\.\.))*)+(/\d+)*\])u
Truth table100%3/3
A and not(B)
A= /^\[(.*)\]/uB= not m(^\[(\d+((?:,)|(?:\.\.))*)+(/\d+)*\])u
ABresult
0X0
100
111
26  
27 # check for inheritance
28 9 $section = $1;
29 9 $ini->{$section} = {};
30  
31 9 ▶ if ( $section =~ /</ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($section =~ /</u) 1 8 9
32 1 delete $ini->{$section};
33 1 my @inherit = split( /</, $section );
34 1 s/^\s*|\s*$//g for @inherit;
35 1 $section = shift @inherit;
36  
37 1 for my $is (@inherit) {
38 1 for my $ik ( keys %{ $ini->{$is} } ) {
39 5 $ini->{$section}->{$ik} = $ini->{$is}->{$ik};
40 }
41 }
42 }
43  
44 9 next;
45 }
46  
47 18 my ( $key, $val ) = split( /[= ]/, $_, 2 );
48 18 ▶ $key =~ s/^\s*|\s*$//g if $key;
Branch: 1 branch
BranchTrueFalseTotal
if $key 18 0 18
49 18 ▶ $val =~ s/^\s*|\s*$//g if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 1 17 18
50  
51 18 my @splitted;
52 18 ▶ if ( !$val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $val) { } 17 1 18
53 17 $val = $key;
54 17 @splitted = ($key);
55 }
56  
57 # commented out due to #184
58 else {
59 #@splitted = split(/\./, $key);
60 1 @splitted = ($key);
61 }
62  
63 18 my $ref = $ini->{$section};
64 18 my $last = pop @splitted;
65 18 for my $sub (@splitted) {
66  
67 0 ▶ unless ( exists $ini->{$section}->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ini->{$section}{$sub}) 0 0 0
68 0 $ini->{$section}->{$sub} = {};
69 }
70  
71 0 $ref = $ini->{$section}->{$sub};
72 }
73  
74 # include other group
75 18 ▶ if ( $key =~ m/^\@(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^\@(.*)/u) 1 17 18
76 1 for my $ik ( keys %{ $ini->{$1} } ) {
77 3 $ini->{$section}->{$ik} = $ini->{$1}->{$ik};
78 }
79 1 next;
80 }
81  
82 17 ▶ if ( $val =~ m/\$\{(.*)\}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /\$\{(.*)\}/u) 0 17 17
83 0 my $var_name = $1;
84 0 my $ref = $ini;
85 0 my @splitted = split( /\./, $var_name );
86 0 for my $s (@splitted) {
87 0 $ref = $ref->{$s};
88 }
89  
90 0 $val = $ref;
91 }
92  
93 17 ▶ if ( $val =~ m/=/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /=/u) 1 16 17
94 1 $val = { string2hash($val) };
95 }
96  
97 17 $ref->{$last} = $val;
98  
99 }
100  
101 1 return $ini;
102 }
103  
104 1 1;
« lib/Rex/Box/Amazon.pm ↑ Summary blib/lib/Rex/Logger.pm »