line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Format::Ini; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
313194
|
use 5.008008; |
|
9
|
|
|
|
|
42
|
|
|
9
|
|
|
|
|
398
|
|
4
|
9
|
|
|
9
|
|
57
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
18740
|
|
5
|
9
|
|
|
9
|
|
71
|
use warnings; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
409
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
93
|
use base qw( Exporter ); |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
2309
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw( read_ini ); |
9
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); |
10
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
11
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
12
|
|
|
|
|
|
|
|
13
|
9
|
|
|
9
|
|
11334
|
use Config::Format::Ini::Grammar; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
657
|
|
14
|
9
|
|
|
9
|
|
12549
|
use File::Slurp qw(slurp); |
|
9
|
|
|
|
|
211681
|
|
|
9
|
|
|
|
|
3425
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $SIMPLIFY=0; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub read_ini { |
19
|
21
|
50
|
|
21
|
1
|
51830
|
return unless @_; |
20
|
21
|
|
|
|
|
48
|
my $msg; |
21
|
21
|
|
|
|
|
172
|
$msg .= scalar slurp $_ for @_ ; |
22
|
21
|
|
|
|
|
3085
|
my $p = new Config::Format::Ini::Grammar; |
23
|
21
|
|
|
|
|
1601249
|
my $result = $p->startrule( $msg ); |
24
|
21
|
100
|
|
|
|
325702
|
_simplify( $result) if $SIMPLIFY; |
25
|
21
|
|
|
|
|
183
|
$result; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _arr2scalar { |
29
|
|
|
|
|
|
|
# change arrays with one element to string |
30
|
4
|
|
50
|
4
|
|
13
|
my $ref = shift ||return; |
31
|
4
|
50
|
|
|
|
15
|
return unless ref $ref eq 'HASH'; |
32
|
4
|
|
|
|
|
18
|
while (my( $k,$v )=each %$ref) { |
33
|
11
|
50
|
|
|
|
32
|
next unless ref $v eq 'ARRAY'; |
34
|
11
|
100
|
|
|
|
31
|
(1 == @$v ) and $ref->{$k} = $v->[0]; |
35
|
11
|
100
|
|
|
|
59
|
(0 == @$v ) and $ref->{$k} = undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
sub _simplify { |
39
|
3
|
|
|
3
|
|
9
|
my $ini =shift; |
40
|
3
|
50
|
|
|
|
19
|
return unless ref $ini eq 'HASH'; |
41
|
5
|
|
|
|
|
31
|
(0 == keys %{$ini->{$_}}) |
42
|
|
|
|
|
|
|
? undef $ini->{$_} |
43
|
|
|
|
|
|
|
: _arr2scalar $ini->{$_} |
44
|
3
|
100
|
|
|
|
13
|
for (keys %$ini); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |