| 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
| |||||||||||||||||||||||||||||
| 17 | or croak "Can't read configuration in $file: $!\n"; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | while ( ++$line_num and my $line = $fh->getline ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
++$line_num and my $line = $fh->getline
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 25 | 10 | $line =~ s/(?<!\\)#.*$//; | |||||||||||||||||||||||||||
| 26 | 10 | $line =~ s/\\#/#/g; | |||||||||||||||||||||||||||
| 27 | 10 | ▶ | next if $line =~ m/^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 10 | $line =~ s{\$(\w+)}{ | |||||||||||||||||||||||||||
| 29 | 2 | ▶ | exists($conf->{$1}) ? $conf->{$1} : "\$$1" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | }gsex; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 10 | ▶ | unless ( $line =~ m/\s*([^\s=]+)\s*=\s*(.*?)\s*$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 // {}
MC/DC100%1/1
$conf // {}
$conf
Truth table100%2/2
A
A= $conf
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||