line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Config::Ini; |
2
|
1
|
|
|
1
|
|
21096
|
use Mojar::Config -base; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
12
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.031; |
5
|
|
|
|
|
|
|
# Adapted from Mojolicious::Plugin::Config (3.57) |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
182
|
use Carp 'croak'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
8
|
1
|
|
|
1
|
|
5
|
use Mojo::Util 'decode'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
420
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub parse { |
11
|
10
|
|
|
10
|
1
|
4845
|
my ($self, $content_ref, %param) = @_; |
12
|
10
|
|
100
|
|
|
44
|
$param{sections} //= ':all'; |
13
|
|
|
|
|
|
|
croak 'Unrecognised sections spec' |
14
|
|
|
|
|
|
|
unless ref $param{sections} eq 'ARRAY' |
15
|
10
|
50
|
100
|
|
|
61
|
or $param{sections} eq ':all' or $param{sections} eq ':ignore'; |
|
|
|
66
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
10
|
50
|
|
|
|
25
|
return {} unless $$content_ref; |
18
|
|
|
|
|
|
|
|
19
|
10
|
|
|
|
|
17
|
my $config = {}; |
20
|
10
|
|
|
|
|
17
|
my $section = '_'; |
21
|
10
|
|
|
|
|
56
|
while ($$content_ref =~ /^(.*)$/gm) { |
22
|
26
|
|
|
|
|
66
|
$_ = $1; |
23
|
26
|
100
|
|
|
|
86
|
next unless /\S/; # blank line |
24
|
25
|
50
|
|
|
|
62
|
next if /^\s*#/; # comment line |
25
|
25
|
100
|
|
|
|
99
|
$section = $1, $config->{$section} = {}, next |
26
|
|
|
|
|
|
|
if /^\s*\[([^\]]+)\]/; # section header |
27
|
16
|
100
|
|
|
|
81
|
if (/^\s*([\w-]+)\s+=\s+(\S.*?)\s*$/) { |
28
|
15
|
100
|
|
|
|
36
|
if ($param{sections} eq ':ignore') { |
29
|
4
|
|
|
|
|
22
|
$config->{$1} = $2; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
11
|
|
|
|
|
72
|
$config->{$section}{$1} = $2; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
0
|
33
|
|
|
6
|
croak qq{Failed to parse configuration line ($_)} if !$config && $@; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
10
|
100
|
|
|
|
27
|
if (ref $param{sections} eq 'ARRAY') { |
41
|
3
|
|
|
|
|
6
|
my $cfg = {}; |
42
|
3
|
|
100
|
|
|
5
|
%$cfg = (%$cfg, %{$config->{$_} // {}}) for @{$param{sections}}; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
19
|
|
43
|
3
|
|
|
|
|
17
|
return $cfg; |
44
|
|
|
|
|
|
|
} |
45
|
7
|
|
|
|
|
41
|
return $config; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |