blib/lib/Config/File.pm

filter: Statementstmt 100% 47 / 47 Branchbran 78.5% 11 / 14 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 93.5% 72 / 77 CC 10 SCAR 19.0
CC
10
Cov
94%
read_config_file
10.1
BEGIN
1.0
BEGIN
1.0
CRAP 6.7
↑ Summary
1 package Config::File;
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 @ISA = qw/Exporter/;
10 2 @EXPORT_OK = qw/read_config_file/;
11 2 $VERSION = '1.54';
12  
13 2 ▶sub read_config_file($) {
Subroutine read_config_file: called CC=10 SCAR=23.1
Pod documented
14 2 my ( $conf, $file, $fh, $line_num );
15 2 $file = shift;
16 2 ▶ $fh = IO::File->new( $file, 'r' )
Branch: 1 branch
BranchTrueFalseTotal
$fh = "IO::File"->new($file, "r") or croak("Can't read configuration in ${file}: $!\n") 2 0 2
17 or croak "Can't read configuration in $file: $!\n";
18  
19 2 ▶ while ( ++$line_num and my $line = $fh->getline ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$line_num and my $line = $fh->getline) 11 2 13
Condition66%2/3
++$line_num and my $line = $fh->getline
!ll&&!rl&&r
0211
MC/DC50%1/2
++$line_num and my $line = $fh->getline
++$line_num my $line = $fh->getline
Truth table66%2/3
A and B
A= ++$line_numB= my $line = $fh->getline
ABresult
0X0
100
111
20 11 my ( $orig_line, $conf_ele, $conf_data );
21 11 chomp $line;
22 11 $orig_line = $line;
23  
24 11 ▶ next if $line =~ m/^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 1 10 11
25 10 $line =~ s/(?<!\\)#.*$//;
26 10 $line =~ s/\\#/#/g;
27 10 ▶ next if $line =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 10 10
28 10 $line =~ s{\$(\w+)}{
29 2 ▶ exists($conf->{$1}) ? $conf->{$1} : "\$$1"
Branch: 1 branch
BranchTrueFalseTotal
exists $conf->{$1} ? : 2 0 2
30 }gsex;
31  
32 10 ▶ unless ( $line =~ m/\s*([^\s=]+)\s*=\s*(.*?)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /\s*([^\s=]+)\s*=\s*(.*?)\s*$/) 1 9 10
33 1 warn "Line format invalid at line $line_num: '$orig_line'";
34 1 next;
35 }
36  
37 9 ( $conf_ele, $conf_data ) = ( $1, $2 );
38 9 ▶ unless ( $conf_ele =~ /^[\]\[A-Za-z0-9_-]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf_ele =~ /^[\]\[A-Za-z0-9_-]+$/) 1 8 9
39 1 warn "Invalid characters in key $conf_ele at line $line_num"
40 . " - Ignoring";
41 1 next;
42 }
43 $conf_ele =
44 8 '$conf->{"' . join( '"}->{"', split /[][]+/, $conf_ele ) . '"}';
45 8 $conf_data =~ s!([\\\'])!\\$1!g;
46 8 eval "$conf_ele = '$conf_data'";
47 }
48 2 $fh->close;
49  
50 2 ▶ return $conf // {};
Condition100%2/2
$conf // {}
l!l
11
MC/DC100%1/1
$conf // {}
$conf
Truth table100%2/2
A
A= $conf
Aresult
11
00
51 }
52  
53 2 1;
54  
55 __END__
↑ Summary