| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojar::Config::Ini; |
|
2
|
1
|
|
|
1
|
|
18852
|
use Mojo::Base 'Mojar::Config'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.021; |
|
5
|
|
|
|
|
|
|
# Adapted from Mojolicious::Plugin::Config (3.57) |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
158
|
use Carp 'croak'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Mojo::Util qw(decode slurp); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
727
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub parse { |
|
11
|
10
|
|
|
10
|
1
|
2736
|
my ($self, $content_ref, %param) = @_; |
|
12
|
10
|
|
100
|
|
|
32
|
$param{sections} //= ':all'; |
|
13
|
|
|
|
|
|
|
croak 'Unrecognised sections spec' |
|
14
|
|
|
|
|
|
|
unless ref $param{sections} eq 'ARRAY' |
|
15
|
10
|
50
|
100
|
|
|
45
|
or $param{sections} eq ':all' or $param{sections} eq ':ignore'; |
|
|
|
|
66
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
10
|
50
|
|
|
|
15
|
return {} unless $$content_ref; |
|
18
|
|
|
|
|
|
|
|
|
19
|
10
|
|
|
|
|
9
|
my $config = {}; |
|
20
|
10
|
|
|
|
|
10
|
my $section = '_'; |
|
21
|
10
|
|
|
|
|
42
|
while ($$content_ref =~ /^(.*)$/gm) { |
|
22
|
26
|
|
|
|
|
26
|
$_ = $1; |
|
23
|
26
|
100
|
|
|
|
50
|
next unless /\S/; # blank line |
|
24
|
25
|
50
|
|
|
|
32
|
next if /^\s*#/; # comment line |
|
25
|
25
|
100
|
|
|
|
71
|
$section = $1, $config->{$section} = {}, next |
|
26
|
|
|
|
|
|
|
if /^\s*\[([^\]]+)\]/; # section header |
|
27
|
16
|
100
|
|
|
|
59
|
if (/^\s*([\w-]+)\s+=\s+(\S.*?)\s*$/) { |
|
28
|
15
|
100
|
|
|
|
20
|
if ($param{sections} eq ':ignore') { |
|
29
|
4
|
|
|
|
|
13
|
$config->{$1} = $2; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
else { |
|
32
|
11
|
|
|
|
|
43
|
$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
|
|
|
|
17
|
if (ref $param{sections} eq 'ARRAY') { |
|
41
|
3
|
|
|
|
|
3
|
my $cfg = {}; |
|
42
|
3
|
|
100
|
|
|
4
|
%$cfg = (%$cfg, %{$config->{$_} // {}}) for @{$param{sections}}; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
15
|
|
|
43
|
3
|
|
|
|
|
12
|
return $cfg; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
7
|
|
|
|
|
24
|
return $config; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
|
49
|
|
|
|
|
|
|
__END__ |