lib/Rex/File/Parser/Ini.pm

filter: Statementstmt 22.2% 10 / 45 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 4 totaltotal 17.1% 13 / 76 CC 9 SCAR 29.5
CC
9
Cov
16%
_read_file
42.0
get
12.0
new
6.0
CRAP 19.2
« lib/Rex/Virtualization/LibVirt/hypervisor.pm ↑ Summary lib/Rex/Box/Amazon.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::File::Parser::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 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my $that = shift;
16 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
17 0 my $self = {@_};
18  
19 0 bless( $self, $proto );
20  
21 0 return $self;
22 }
23  
24 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod undocumented
25 0 my ( $self, $section, $key ) = @_;
26  
27 0 ▶ unless ( exists $self->{"__data"}->{$section} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__data"}{$section}) 0 0 0
28 0 die("$section not found");
29 }
30  
31 0 ▶ unless ( exists $self->{"__data"}->{$section}->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__data"}{$section}{$key}) 0 0 0
32 0 die("$key not found in $section");
33 }
34  
35 0 return $self->{"__data"}->{$section}->{$key};
36 }
37  
38 0 ▶sub get_sections {
Subroutine get_sections: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my ($self) = @_;
40 0 return keys %{ $self->{"__data"} };
41 }
42  
43 0 ▶sub read {
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my ($self) = @_;
45 0 $self->{"__data"} = $self->_read_file;
46 }
47  
48 0 ▶sub _read_file {
Subroutine _read_file: not called CC=6 SCAR=37.4
49 0 my ($self) = @_;
50  
51 0 my $data = {};
52  
53 0 my $section;
54 0 open( my $fh, "<", $self->{"file"} );
55 0 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
56 0 chomp $line;
57 0 ▶ next if ( $line =~ m/^\s*?;/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*?;/u 0 0 0
58 0 ▶ next if ( $line =~ m/^\s*?$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*?$/u 0 0 0
59  
60 0 ▶ if ( $line =~ m/^\[(.+)\]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\[(.+)\]$/u) 0 0 0
61 0 $section = $1;
62 0 $data->{$section} = {};
63 0 next;
64 }
65  
66 0 ▶ if ($section) {
Branch: 1 branch
BranchTrueFalseTotal
if ($section) 0 0 0
67 0 my ( $key, $val ) = split( /=/, $line, 2 );
68 0 $val =~ s/^\s+|\s+$//g;
69 0 $key =~ s/^\s+|\s+$//g;
70  
71 0 $data->{$section}->{$key} = $val;
72 }
73 }
74 0 close($fh);
75  
76 0 return $data;
77 }
78  
79 1 1;
« lib/Rex/Virtualization/LibVirt/hypervisor.pm ↑ Summary lib/Rex/Box/Amazon.pm »