Ini.pm

filter: Statementstmt 100% 41 / 41 Branchbran 77.7% 14 / 18 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 91.6% 66 / 72 CC 13 SCAR 14.4
CC
13
Cov
92%
_arr2scalar
7.2
_simplify
4.0
read_ini
4.0
CRAP 4.2
↑ Summary Ini/Grammar.pm »
1 package Config::Format::Ini;
2  
3 9 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 our @EXPORT = qw( read_ini );
9 9 our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
10 9 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
11 9 our $VERSION = '0.07';
12  
13 9 ▶use Config::Format::Ini::Grammar;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use File::Slurp qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 our $SIMPLIFY=0;
17  
18 21 ▶sub read_ini {
Subroutine read_ini: called CC=4 SCAR=13.9
Pod documented
19 21 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 21 21
20 21 my $msg;
21 21 $msg .= scalar slurp $_ for @_ ;
22 21 my $p = new Config::Format::Ini::Grammar;
23 21 my $result = $p->startrule( $msg );
24 21 ▶ _simplify( $result) if $SIMPLIFY;
Branch: 1 branch
BranchTrueFalseTotal
if $Config::Format::Ini::SIMPLIFY 3 18 21
25 21 $result;
26 }
27  
28 4 ▶sub _arr2scalar {
Subroutine _arr2scalar: called CC=7 SCAR=19.8
29 # change arrays with one element to string
30 4 ▶ my $ref = shift ||return;
Condition50%1/2
shift() || (return)
l!l
40
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
31 4 ▶ return unless ref $ref eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ref eq "HASH" 0 4 4
32 4 ▶ while (my( $k,$v )=each %$ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ref) 11 4 15
33 11 ▶ next unless ref $v eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 0 11 11
34 11 ▶ (1 == @$v ) and $ref->{$k} = $v->[0];
Branch: 1 branch
BranchTrueFalseTotal
1 == @$v and $ref->{$k} = $v->[0] 5 6 11
35 11 ▶ (0 == @$v ) and $ref->{$k} = undef;
Branch: 1 branch
BranchTrueFalseTotal
0 == @$v and $ref->{$k} = undef 1 10 11
36 }
37 }
38 3 ▶sub _simplify {
Subroutine _simplify: called CC=4 SCAR=13.9
39 3 my $ini =shift;
40 3 ▶ return unless ref $ini eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ini eq "HASH" 0 3 3
41 5 (0 == keys %{$ini->{$_}})
42 ? undef $ini->{$_}
43 : _arr2scalar $ini->{$_}
44 3 ▶ for (keys %$ini);
Branch: 1 branch
BranchTrueFalseTotal
0 == keys %{$$ini{$_};} ? : 1 4 5
45 }
46  
47  
48 9 1;
49 __END__
↑ Summary Ini/Grammar.pm »