| 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
| |||||||||||||
| 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
| |||||||||||||
| 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)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 31 | 4 | ▶ | return unless ref $ref eq 'HASH'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 4 | ▶ | while (my( $k,$v )=each %$ref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 11 | ▶ | next unless ref $v eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 11 | ▶ | (1 == @$v ) and $ref->{$k} = $v->[0]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 11 | ▶ | (0 == @$v ) and $ref->{$k} = undef; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 41 | 5 | (0 == keys %{$ini->{$_}}) | |||||||||||
| 42 | ? undef $ini->{$_} | ||||||||||||
| 43 | : _arr2scalar $ini->{$_} | ||||||||||||
| 44 | 3 | ▶ | for (keys %$ini); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | |||||||||||||
| 48 | 9 | 1; | |||||||||||
| 49 | __END__ | ||||||||||||