| 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
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 27 | ▶ | if ( /^\[(.*)\]/ && !/^\[(\d+((?:,)|(?:\.\.))*)+(\/\d+)*\]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^\[(.*)\]/u and not m(^\[(\d+((?:,)|(?:\.\.))*)+(/\d+)*\])u
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
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # check for inheritance | ||||||||||||||||||||||||||||
| 28 | 9 | $section = $1; | |||||||||||||||||||||||||||
| 29 | 9 | $ini->{$section} = {}; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 9 | ▶ | if ( $section =~ /</ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 49 | 18 | ▶ | $val =~ s/^\s*|\s*$//g if $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 18 | my @splitted; | |||||||||||||||||||||||||||
| 52 | 18 | ▶ | if ( !$val ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | 1 | $val = { string2hash($val) }; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 17 | $ref->{$last} = $val; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | return $ini; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | 1; | |||||||||||||||||||||||||||