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