blib/lib/Config/INI/Tiny.pm

filter: Statementstmt 100% 37 / 37 Branchbran 87.5% 14 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 96.8% 62 / 64 CC 11 SCAR 14.2
CC
11
Cov
96%
parse
7.0
to_hash
4.0
BEGIN
2.1
CRAP 4.1
↑ Summary
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
BranchTrueFalseTotal
if eval { do { require utf8 } } 2 0 2
19 27 ▶ while ( ++$n, $_[0] =~ /$rx/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$n, $_[0] =~ /$rx/g) 106 22 128
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
BranchTrueFalseTotal
defined $2 ? : 37 69 106
$self->{'pairs'} ? : 2 35 37
defined $1 ? : 29 40 69
defined $4 ? : 5 35 40
23 : ()
24 }
25 22 ▶ wantarray ? @out : $out[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 22 0 22
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
BranchTrueFalseTotal
unless @{$section[0];} > 1 12 9 21
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__
↑ Summary