| 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
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 28 | 0 | die("$section not found"); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | unless ( exists $self->{"__data"}->{$section}->{$key} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 56 | 0 | chomp $line; | |||||||||||||||||||
| 57 | 0 | ▶ | next if ( $line =~ m/^\s*?;/ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | ▶ | next if ( $line =~ m/^\s*?$/ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | if ( $line =~ m/^\[(.+)\]$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | $section = $1; | |||||||||||||||||||
| 62 | 0 | $data->{$section} = {}; | |||||||||||||||||||
| 63 | 0 | next; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | if ($section) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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; | |||||||||||||||||||