line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
151547
|
use 5.006; use strict; use warnings; |
|
2
|
|
|
2
|
|
13
|
|
|
2
|
|
|
2
|
|
9
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
44
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
2
|
2
|
|
|
2
|
|
9
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
349
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Config::INI::Tiny; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.105'; |
7
|
|
|
|
|
|
|
|
8
|
27
|
|
|
27
|
1
|
15104
|
sub new { my $class = shift; bless { section0 => '', line0 => 0, pairs => 0, @_ }, $class } |
|
27
|
|
|
|
|
110
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $str = '[^\r\n]* [^\r\n\t ]'; |
11
|
|
|
|
|
|
|
my $ws = '[\t ]*'; |
12
|
|
|
|
|
|
|
my $cmt = '[#;]'; # separate var because cf. "Starting in Perl 5.001" in L |
13
|
|
|
|
|
|
|
my $rx = qr{\G $ws (?: $cmt (?:$str)? | \[ $ws ($str) $ws \] | ([^=\r\n]+?) $ws = $ws ($str|) | ($str) )? $ws (?:\z|\n|\r\n?) }x; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse { |
16
|
27
|
|
|
27
|
1
|
32
|
my $self = shift; |
17
|
27
|
|
|
|
|
82
|
my $n = $self->{'line0'}, my @out = my $s = [ $self->{'section0'} ], pos( $_[0] ) = 0; |
18
|
2
|
50
|
|
2
|
|
6
|
BEGIN { utf8->import if eval { require utf8 } } # 5.6 compat |
|
2
|
|
|
|
|
1895
|
|
19
|
27
|
|
|
|
|
267
|
while ( ++$n, $_[0] =~ /$rx/g ) { |
20
|
|
|
|
|
|
|
; defined $2 ? push @$s, $self->{'pairs'} ? [ "$2", "$3" ] : ( "$2", "$3" ) |
21
|
|
|
|
|
|
|
: defined $1 ? push @out, $s = [ "$1" ] |
22
|
106
|
100
|
|
|
|
686
|
: defined $4 ? Carp::croak map { s/"/\\"/g; qq'Bad INI syntax at line $n: "$_"' } "$4" |
|
5
|
100
|
|
|
|
17
|
|
|
5
|
100
|
|
|
|
493
|
|
|
|
100
|
|
|
|
|
|
23
|
|
|
|
|
|
|
: () |
24
|
|
|
|
|
|
|
} |
25
|
22
|
50
|
|
|
|
88
|
wantarray ? @out : $out[0]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub to_hash { |
29
|
26
|
|
|
26
|
1
|
37
|
my $self = shift; |
30
|
26
|
|
|
|
|
31
|
my ( @section, %config ) = do { local $self->{'pairs'}; $self->parse( $_[0] ) }; |
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
51
|
|
31
|
21
|
100
|
|
|
|
31
|
shift @section unless @{ $section[0] } > 1; # remove initial unnamed section if empty |
|
21
|
|
|
|
|
45
|
|
32
|
21
|
|
|
|
|
38
|
push @{ $config{ shift @$_ } }, $_ for @section; # collect sections in HoAoA, to minimise (re)alloc work |
|
35
|
|
|
|
|
93
|
|
33
|
21
|
|
|
|
|
107
|
$_ = { map @$_, @$_ } for values %config; # flatten HoAoA to HoH as cheaply as possible |
34
|
21
|
|
|
|
|
58
|
\%config; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |