| 1 | 2 | ▶ | use 5.006; use strict; use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 2 | 2 | ▶ | use Carp (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | package Config::INI::Tiny; | ||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.106'; | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 27 | ▶ | sub new { my $class = shift; bless { section0 => '', line0 => 0, pairs => 0, @_ }, $class } | ||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 2 | my $str = '[^\r\n]* [^\r\n\t ]'; | |||||||||||||||||||||
| 11 | 2 | my $ws = '[\t ]*'; | |||||||||||||||||||||
| 12 | 2 | my $cmt = '[#;]'; # separate var because cf. "Starting in Perl 5.001" in L<perl5200delta/'Regular Expressions'> | |||||||||||||||||||||
| 13 | 2 | my $rx = qr{\G $ws (?: $cmt (?:$str)? | \[ $ws ($str) $ws \] | ([^=\r\n]+?) $ws = $ws ($str|) | ($str) )? $ws (?:\z|\n|\r\n?) }x; | |||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 27 | ▶ | sub parse { | ||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||
| 16 | 27 | my $self = shift; | |||||||||||||||||||||
| 17 | 27 | my $n = $self->{'line0'}, my @out = my $s = [ $self->{'section0'} ], pos( $_[0] ) = 0; | |||||||||||||||||||||
| 18 | 2 | ▶ | BEGIN { utf8->import if eval { require utf8 } } # 5.6 compat | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||
| 19 | 27 | ▶ | while ( ++$n, $_[0] =~ /$rx/g ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 20 | ; defined $2 ? push @$s, $self->{'pairs'} ? [ "$2", "$3" ] : ( "$2", "$3" ) | ||||||||||||||||||||||
| 21 | : defined $1 ? push @out, $s = [ "$1" ] | ||||||||||||||||||||||
| 22 | 106 | ▶ | : defined $4 ? Carp::croak map { s/"/\\"/g; qq'Bad INI syntax at line $n: "$_"' } "$4" | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 23 | : () | ||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||
| 25 | 22 | ▶ | wantarray ? @out : $out[0]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 26 | ▶ | sub to_hash { | ||||||||||||||||||||
|
Subroutine
to_hash: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||
| 29 | 26 | my $self = shift; | |||||||||||||||||||||
| 30 | 26 | my ( @section, %config ) = do { local $self->{'pairs'}; $self->parse( $_[0] ) }; | |||||||||||||||||||||
| 31 | 21 | ▶ | shift @section unless @{ $section[0] } > 1; # remove initial unnamed section if empty | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 32 | 21 | push @{ $config{ shift @$_ } }, $_ for @section; # collect sections in HoAoA, to minimise (re)alloc work | |||||||||||||||||||||
| 33 | 21 | $_ = { map @$_, @$_ } for values %config; # flatten HoAoA to HoH as cheaply as possible | |||||||||||||||||||||
| 34 | 21 | \%config; | |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | __END__ | ||||||||||||||||||||||