| 1 | package OpenInteract2::Config::Ini; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | # $Id: Ini.pm,v 1.21 2005/03/18 04:09:50 lachoy Exp $ | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 87 | ▶ | use File::Basename qw( dirname ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 87 | ▶ | use File::Spec::Functions qw( catfile ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 87 | ▶ | use Log::Log4perl qw( get_logger ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 87 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 87 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 87 | $OpenInteract2::Config::Ini::VERSION = sprintf("%d.%02d", q$Revision: 1.21 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 87 | my ( $log ); | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 18 | # CLASS METHODS | ||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | # Stuff in metadata (_m): | ||||||||||||||||||||||||||||||||||||
| 21 | # filename ($): file read from | ||||||||||||||||||||||||||||||||||||
| 22 | # directory ($): directory file read from | ||||||||||||||||||||||||||||||||||||
| 23 | # sections (\@): all full sections, in the order they were read | ||||||||||||||||||||||||||||||||||||
| 24 | # comments (\%): key is full section name, value is comment scalar | ||||||||||||||||||||||||||||||||||||
| 25 | # order (\@): order of sections read/assigned | ||||||||||||||||||||||||||||||||||||
| 26 | # order_map (\%): to determine if section exists | ||||||||||||||||||||||||||||||||||||
| 27 | # global (\@): keys in the 'Global' section | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | 31 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 30 | 31 | my ( $pkg, $params ) = @_; | |||||||||||||||||||||||||||||||||||
| 31 | 31 | ▶ | my $class = ref $pkg || $pkg; | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||||||||||||||||
| 32 | 31 | my $self = bless( { | |||||||||||||||||||||||||||||||||||
| 33 | filename => '', | ||||||||||||||||||||||||||||||||||||
| 34 | directory => '', | ||||||||||||||||||||||||||||||||||||
| 35 | sections => [], | ||||||||||||||||||||||||||||||||||||
| 36 | comments => {}, | ||||||||||||||||||||||||||||||||||||
| 37 | order => [], | ||||||||||||||||||||||||||||||||||||
| 38 | order_map => {}, | ||||||||||||||||||||||||||||||||||||
| 39 | global => [], | ||||||||||||||||||||||||||||||||||||
| 40 | }, $class ); | ||||||||||||||||||||||||||||||||||||
| 41 | 31 | ▶ | if ( $self->{_m}{filename} = $params->{filename} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 42 | 26 | ▶ | $self->{_m}{directory} = $params->{directory} || dirname( $params->{filename} ); | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$params->{'directory'} || dirname($params->{'filename'})
MC/DC0%0/2
$params->{'directory'} || dirname($params->{'filename'})
$params->{'directory'}
dirname($params->{'filename'})
Truth table66%2/3
A || B
A= $params->{'directory'}B= dirname($params->{'filename'})
| |||||||||||||||||||||||||||||||||||||
| 43 | 26 | $self->_translate_ini( OpenInteract2::Config->read_file( $params->{filename} ) ); | |||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||
| 45 | elsif ( $params->{content} ) { | ||||||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | $self->{_m}{directory} = $params->{directory} || '.'; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params->{'directory'} || '.'
MC/DC100%1/1
$params->{'directory'} || '.'
$params->{'directory'}
Truth table100%2/2
A
A= $params->{'directory'}
| |||||||||||||||||||||||||||||||||||||
| 47 | 4 | $self->_translate_ini( $params->{content} ); | |||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||
| 49 | elsif ( $params->{struct} ) { | ||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $self->{_m}{directory} = $params->{directory} || '.'; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{'directory'} || '.'
MC/DC0%0/1
$params->{'directory'} || '.'
$params->{'directory'}
Truth table0%0/2
A
A= $params->{'directory'}
| |||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->_translate_struct_to_ini( $params->{struct} ); | |||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||
| 53 | 29 | return $self; | |||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | # Return the INI data as a raw hashref (naive for now...) | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | sub as_data { | ||||||||||||||||||||||||||||||||||
|
Subroutine
as_data: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 59 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||
| 60 | 2 | my %data = (); | |||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | while ( my ( $k, $v ) = each %{ $self } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 62 | 28 | ▶ | $data{ $k } = $v unless ( $k eq '_m' ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||
| 64 | 2 | return \%data; | |||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ( $self, $section, @p ) = @_; | |||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my ( $sub_section, $param ) = ( $p[1] ) ? ( $p[0], $p[1] ) : ( undef, $p[0] ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 71 | my $item = ( $sub_section ) | ||||||||||||||||||||||||||||||||||||
| 72 | ? $self->{ $section }{ $sub_section }{ $param } | ||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | : $self->{ $section }{ $param }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $item unless ( ref $item eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return wantarray ? @{ $item } : $item->[0]; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | 13 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 80 | 13 | my ( $self, $section, @p ) = @_; | |||||||||||||||||||||||||||||||||||
| 81 | 13 | ▶ | my ( $sub_section, $param, $value ) = ( $p[2] ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 82 | ? ( $p[0], $p[1], $p[2] ) | ||||||||||||||||||||||||||||||||||||
| 83 | : ( undef, $p[0], $p[1] ); | ||||||||||||||||||||||||||||||||||||
| 84 | 13 | ▶ | unless ( $self->is_section( $section, $sub_section ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 85 | 3 | $self->add_section( $section, $sub_section ); | |||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | 13 | return $self->_read_item( $section, $sub_section, $param, $value ); | |||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ( $self, $section, @p ) = @_; | |||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my ( $sub_section, $param ) = ( $p[1] ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 94 | ? ( $p[0], $p[1] ) : ( undef, $p[0] ); | ||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | delete $self->{ $section }{ $sub_section }{ $param } if ( $sub_section ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 96 | 0 | delete $self->{ $section }{ $param }; | |||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | 13 | ▶ | sub is_section { | ||||||||||||||||||||||||||||||||||
|
Subroutine
is_section: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 101 | 13 | my ( $self, $section, $sub_section ) = @_; | |||||||||||||||||||||||||||||||||||
| 102 | 13 | ▶ | my $full_section = ( $sub_section ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 103 | ? "$section $sub_section" : $section; | ||||||||||||||||||||||||||||||||||||
| 104 | 13 | return $self->{_m}{order_map}{ $full_section }; | |||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | 95 | ▶ | sub add_section { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add_section: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 108 | 95 | my ( $self, $section, $sub_section ) = @_; | |||||||||||||||||||||||||||||||||||
| 109 | 95 | ▶ | my $full_section = ( $sub_section ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 110 | ? "$section $sub_section" : $section; | ||||||||||||||||||||||||||||||||||||
| 111 | 95 | push @{ $self->{_m}{order} }, $full_section; | |||||||||||||||||||||||||||||||||||
| 112 | 95 | $self->{_m}{order_map}{ $full_section }++; | |||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | sub sections { | ||||||||||||||||||||||||||||||||||
|
Subroutine
sections: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 116 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||
| 117 | 1 | return @{ $self->{_m}{order} }; | |||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub main_sections { | ||||||||||||||||||||||||||||||||||
|
Subroutine
main_sections: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||
| 122 | 0 | my @main = (); | |||||||||||||||||||||||||||||||||||
| 123 | 0 | foreach my $full_section ( @{ $self->{_m}{order} } ) { | |||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | push @main, $full_section unless ( $full_section =~ /\s/ ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||
| 126 | 0 | return @main; | |||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||
| 129 | 92 | ▶ | sub add_comments { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add_comments: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 130 | 92 | my ( $self, @items ) = @_; | |||||||||||||||||||||||||||||||||||
| 131 | 92 | my ( $section, $sub_section, $comments ); | |||||||||||||||||||||||||||||||||||
| 132 | 92 | ▶ | if ( scalar @items == 3 ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 133 | 33 | ( $section, $sub_section, $comments ) = @items; | |||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||
| 136 | 59 | ( $section, $comments ) = @items; | |||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||
| 138 | 92 | ▶ | my $full_section = ( $sub_section ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 139 | ? "$section $sub_section" : $section; | ||||||||||||||||||||||||||||||||||||
| 140 | 92 | $self->{_m}{comments}{ $full_section } = $comments; | |||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | 3 | ▶ | sub get_comments { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_comments: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 144 | 3 | my ( $self, $section, $sub_section ) = @_; | |||||||||||||||||||||||||||||||||||
| 145 | 3 | ▶ | my $full_section = ( $sub_section ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 146 | ? "$section $sub_section" : $section; | ||||||||||||||||||||||||||||||||||||
| 147 | 3 | return $self->{_m}{comments}{ $full_section }; | |||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 151 | # INPUT | ||||||||||||||||||||||||||||||||||||
| 152 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||
| 154 | 30 | ▶ | sub _translate_ini { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_translate_ini: called CC=21 SCAR=32.8
| |||||||||||||||||||||||||||||||||||||
| 155 | 30 | my ( $self, $content ) = @_; | |||||||||||||||||||||||||||||||||||
| 156 | 30 | ▶ | $log ||= get_logger( LOG_CONFIG ); | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$log ||= get_logger("OI2.CONFIG")
MC/DC0%0/2
$log ||= get_logger("OI2.CONFIG")
$log
get_logger("OI2.CONFIG")
Truth table66%2/3
A ||= B
A= $logB= get_logger("OI2.CONFIG")
| |||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||
| 158 | # Content can be either an arrayref of lines from a file or a | ||||||||||||||||||||||||||||||||||||
| 159 | # scalar with the content. | ||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||
| 161 | 30 | ▶ | my $lines = ( ref $content eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 162 | ? $content : [ split( "\n", $content ) ]; | ||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||
| 164 | # Temporary holding for comments | ||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||
| 166 | 30 | my @comments = (); | |||||||||||||||||||||||||||||||||||
| 167 | 30 | my ( $section, $sub_section ); | |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | 30 | my $line_number = 0; | |||||||||||||||||||||||||||||||||||
| 170 | 30 | my ( $multiline_value, $multiline_param ); | |||||||||||||||||||||||||||||||||||
| 171 | 30 | my $in_multiline = 0; | |||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||
| 173 | 30 | my $resolved_lines = $self->_resolve_all_includes( $lines ); | |||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | # Cycle through the lines: skip blanks; accumulate comments for | ||||||||||||||||||||||||||||||||||||
| 176 | # each section; register section/subsection; add parameter/value | ||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||
| 178 | 28 | for ( @{ $resolved_lines } ) { | |||||||||||||||||||||||||||||||||||
| 179 | 922 | chomp; | |||||||||||||||||||||||||||||||||||
| 180 | 922 | $line_number++; | |||||||||||||||||||||||||||||||||||
| 181 | 922 | ▶ | next if ( /^\s*$/ ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 182 | 810 | ▶ | if ( /^# Written by OpenInteract2::Config::Ini at/ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 183 | 0 | next; # ... get rid of current line | |||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||
| 185 | 810 | s/\s+$//; | |||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | 810 | ▶ | if ( /^\s*\#/ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 188 | 297 | push @comments, $_; | |||||||||||||||||||||||||||||||||||
| 189 | 297 | $multiline_param = ''; | |||||||||||||||||||||||||||||||||||
| 190 | 297 | $multiline_value = ''; | |||||||||||||||||||||||||||||||||||
| 191 | 297 | $in_multiline = 0; | |||||||||||||||||||||||||||||||||||
| 192 | 297 | next; | |||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | 513 | ▶ | if ( /^\s*\[\s*(\S|\S.*\S)\s*\]\s*$/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 196 | 92 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 197 | $log->debug( "Found section [$1]" ); | ||||||||||||||||||||||||||||||||||||
| 198 | 92 | ( $section, $sub_section ) = | |||||||||||||||||||||||||||||||||||
| 199 | $self->_read_section_head( $1, \@comments ); | ||||||||||||||||||||||||||||||||||||
| 200 | 92 | @comments = (); | |||||||||||||||||||||||||||||||||||
| 201 | 92 | next; | |||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||
| 203 | 421 | my ( $param, $value ); | |||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | 421 | my $this_multiline = $_ =~ s|\\$||; | |||||||||||||||||||||||||||||||||||
| 206 | 421 | ▶ | my $add_value = $_ || ''; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_ || ''
MC/DC0%0/1
$_ || ''
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||
| 207 | 421 | ▶ | if ( $in_multiline and $this_multiline ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$in_multiline and $this_multiline
MC/DC0%0/2
$in_multiline and $this_multiline
$in_multiline
$this_multiline
Truth table66%2/3
A and B
A= $in_multilineB= $this_multiline
| |||||||||||||||||||||||||||||||||||||
| 208 | 0 | $multiline_value .= "$add_value\n"; | |||||||||||||||||||||||||||||||||||
| 209 | 0 | next; | |||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | elsif ( $in_multiline ) { | ||||||||||||||||||||||||||||||||||||
| 212 | 9 | $param = $multiline_param; | |||||||||||||||||||||||||||||||||||
| 213 | 9 | $value = $multiline_value . $add_value; | |||||||||||||||||||||||||||||||||||
| 214 | 9 | $multiline_param = ''; | |||||||||||||||||||||||||||||||||||
| 215 | 9 | $multiline_value = ''; | |||||||||||||||||||||||||||||||||||
| 216 | 9 | $in_multiline = 0; | |||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | # Line is assigning multiple values at once... | ||||||||||||||||||||||||||||||||||||
| 220 | elsif ( /^\s*\@(.)/ ) { | ||||||||||||||||||||||||||||||||||||
| 221 | 12 | my $separator = $1; | |||||||||||||||||||||||||||||||||||
| 222 | 12 | s/^\s*@.\s*//; | |||||||||||||||||||||||||||||||||||
| 223 | 12 | my ( $value_listing ); | |||||||||||||||||||||||||||||||||||
| 224 | 12 | ( $param, $value_listing ) = /^\s*([^=]+?)\s*=\s*(.*)\s*$/; | |||||||||||||||||||||||||||||||||||
| 225 | 12 | ▶ | if ( $this_multiline ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 226 | 0 | die "Cannot define multiple values (with a leading '\@') ", | |||||||||||||||||||||||||||||||||||
| 227 | "on a line that is continued (with a trailing '\\') ", | ||||||||||||||||||||||||||||||||||||
| 228 | "at line number $line_number defining '$param'\n"; | ||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||
| 230 | 12 | $value = [ split /\s*$separator\s*/, $value_listing ]; | |||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||||||
| 233 | 400 | ( $param, $value ) = /^\s*([^=]+?)\s*=\s*(.*)\s*$/; | |||||||||||||||||||||||||||||||||||
| 234 | 400 | ▶ | if ( $this_multiline ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 235 | 9 | $multiline_param = $param; | |||||||||||||||||||||||||||||||||||
| 236 | 9 | ▶ | $multiline_value = $value || ''; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value || ''
MC/DC0%0/1
$value || ''
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||
| 237 | 9 | $in_multiline = 1; | |||||||||||||||||||||||||||||||||||
| 238 | 9 | next; | |||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||
| 242 | 412 | ▶ | if ( $log->is_debug ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my $show_section = ( $sub_section ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 244 | ? "$section.$sub_section" : $section; | ||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $show_param = $param || ''; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$param || ''
MC/DC0%0/1
$param || ''
$param
Truth table0%0/2
A
A= $param
| |||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my $show_value = $value || ''; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value || ''
MC/DC0%0/1
$value || ''
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||
| 247 | 0 | $log->debug( "Line $line_number: $show_section.$show_param = '$show_value'" ); | |||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||
| 249 | 412 | $self->_read_item( $section, $sub_section, $param, $value ); | |||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||
| 251 | 28 | return $self; | |||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub _translate_struct_to_ini { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_translate_struct_to_ini: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 255 | 0 | my ( $self, $struct ) = @_; | |||||||||||||||||||||||||||||||||||
| 256 | 0 | die "_translate_struct_to_ini() not done yet!"; | |||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||
| 260 | 33 | ▶ | sub _resolve_all_includes { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_all_includes: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||
| 261 | 33 | my ( $self, $content ) = @_; | |||||||||||||||||||||||||||||||||||
| 262 | 33 | my @resolved = (); | |||||||||||||||||||||||||||||||||||
| 263 | 33 | for ( @{ $content } ) { | |||||||||||||||||||||||||||||||||||
| 264 | 933 | chomp; | |||||||||||||||||||||||||||||||||||
| 265 | 933 | ▶ | if ( /^\@INCLUDE\s*=\s*(.*)\s*$/ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 266 | 5 | my $include_file = $1; | |||||||||||||||||||||||||||||||||||
| 267 | 5 | my $absolute_file = catfile( $self->{_m}{directory}, $include_file ); | |||||||||||||||||||||||||||||||||||
| 268 | 5 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 269 | $log->debug( "Asked to include file '$include_file'; ", | ||||||||||||||||||||||||||||||||||||
| 270 | "using absolute filename ", $absolute_file ); | ||||||||||||||||||||||||||||||||||||
| 271 | 5 | my $included_raw = eval { | |||||||||||||||||||||||||||||||||||
| 272 | 5 | OpenInteract2::Config->read_file( $absolute_file ) | |||||||||||||||||||||||||||||||||||
| 273 | }; | ||||||||||||||||||||||||||||||||||||
| 274 | 5 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 275 | 2 | oi_error "Failed to read INI configuration -- cannot \@INCLUDE ", | |||||||||||||||||||||||||||||||||||
| 276 | "file '$include_file': $@"; | ||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||
| 278 | 3 | my $included_resolved = $self->_resolve_all_includes( $included_raw ); | |||||||||||||||||||||||||||||||||||
| 279 | 3 | push @resolved, @{ $included_resolved }; | |||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||
| 281 | else { | ||||||||||||||||||||||||||||||||||||
| 282 | 928 | push @resolved, "$_\n"; | |||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||
| 285 | 31 | return \@resolved; | |||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||
| 289 | 92 | ▶ | sub _read_section_head { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_read_section_head: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 290 | 92 | my ( $self, $full_section, $comments ) = @_; | |||||||||||||||||||||||||||||||||||
| 291 | 92 | my $comment_text = join "\n", @{ $comments }; | |||||||||||||||||||||||||||||||||||
| 292 | 92 | ▶ | if ( $full_section =~ /^([\w\-]+)\s+([\w\-]+)$/ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 293 | 33 | my ( $section, $sub_section ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||
| 294 | 33 | ▶ | $self->{ $section }{ $sub_section } ||= {}; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{$section}{$sub_section} ||= {}
MC/DC0%0/1
$self->{$section}{$sub_section} ||= {}
$self->{$section}{$sub_section}
Truth table50%1/2
A
A= $self->{$section}{$sub_section}
| |||||||||||||||||||||||||||||||||||||
| 295 | 33 | $self->add_section( $section, $sub_section ); | |||||||||||||||||||||||||||||||||||
| 296 | 33 | $self->add_comments( $section, $sub_section, $comment_text ); | |||||||||||||||||||||||||||||||||||
| 297 | 33 | return ( $section, $sub_section ); | |||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||
| 299 | 59 | $self->add_section( $full_section ); | |||||||||||||||||||||||||||||||||||
| 300 | 59 | $self->add_comments( $full_section, $comment_text ); | |||||||||||||||||||||||||||||||||||
| 301 | 59 | ▶ | $self->{ $full_section } ||= {}; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{$full_section} ||= {}
MC/DC0%0/1
$self->{$full_section} ||= {}
$self->{$full_section}
Truth table50%1/2
A
A= $self->{$full_section}
| |||||||||||||||||||||||||||||||||||||
| 302 | 59 | return ( $full_section, undef ); | |||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||
| 306 | 425 | ▶ | sub _read_item { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_read_item: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 307 | 425 | my ( $self, $section, $sub_section, $param, $value ) = @_; | |||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||
| 309 | # Special case -- 'Global' stuff goes in the config object root | ||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||
| 311 | 425 | ▶ | if ( $section eq 'Global' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 312 | 7 | push @{ $self->{_m}{global} }, $param; | |||||||||||||||||||||||||||||||||||
| 313 | 7 | $self->_set_value( $self, $param, $value ); | |||||||||||||||||||||||||||||||||||
| 314 | 7 | return; | |||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | 418 | ▶ | $self->{ $section } ||= {}; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{$section} ||= {}
MC/DC100%1/1
$self->{$section} ||= {}
$self->{$section}
Truth table100%2/2
A
A= $self->{$section}
| |||||||||||||||||||||||||||||||||||||
| 318 | 418 | ▶ | if ( $sub_section ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 319 | 108 | ▶ | $self->{ $section }{ $sub_section } ||= {}; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{$section}{$sub_section} ||= {}
MC/DC100%1/1
$self->{$section}{$sub_section} ||= {}
$self->{$section}{$sub_section}
Truth table100%2/2
A
A= $self->{$section}{$sub_section}
| |||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||
| 322 | return ( $sub_section ) | ||||||||||||||||||||||||||||||||||||
| 323 | ? $self->_set_value( $self->{ $section }{ $sub_section }, $param, $value ) | ||||||||||||||||||||||||||||||||||||
| 324 | 418 | ▶ | : $self->_set_value( $self->{ $section }, $param, $value ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||
| 328 | # NOTE: $value can be a scalar or an arrayref (generally when a line | ||||||||||||||||||||||||||||||||||||
| 329 | # defines multiple values at once) | ||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||
| 331 | 425 | ▶ | sub _set_value { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_set_value: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||
| 332 | 425 | my ( $self, $set_in, $param, $value ) = @_; | |||||||||||||||||||||||||||||||||||
| 333 | 425 | ▶ | return unless ( $param ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 334 | 425 | my $existing = $set_in->{ $param }; | |||||||||||||||||||||||||||||||||||
| 335 | 425 | ▶ | my @values = ( ref $value ) ? @{ $value } : ( $value ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 336 | 425 | ▶ | if ( $existing and ref $existing eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$existing and ref $existing eq "ARRAY"
MC/DC100%2/2
$existing and ref $existing eq "ARRAY"
$existing
ref $existing eq "ARRAY"
Truth table100%3/3
A and B
A= $existingB= ref $existing eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||
| 337 | 20 | push @{ $set_in->{ $param } }, @values; | |||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||
| 339 | elsif ( $existing ) { | ||||||||||||||||||||||||||||||||||||
| 340 | 22 | $set_in->{ $param } = [ $existing, @values ]; | |||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||
| 342 | elsif ( scalar @values > 1 ) { | ||||||||||||||||||||||||||||||||||||
| 343 | 8 | $set_in->{ $param } = [ @values ]; | |||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||
| 345 | else { | ||||||||||||||||||||||||||||||||||||
| 346 | 375 | $set_in->{ $param } = $values[0]; | |||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||
| 350 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 351 | # OUTPUT | ||||||||||||||||||||||||||||||||||||
| 352 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||
| 354 | # to STDOUT | ||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub output { | ||||||||||||||||||||||||||||||||||
|
Subroutine
output: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 356 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||
| 357 | 0 | foreach my $key ( @{ $self->{_m}{global} } ) { | |||||||||||||||||||||||||||||||||||
| 358 | 0 | $self->{Global}{ $key } = $self->{ $key }; | |||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||
| 360 | 0 | print $self->_output_header(); | |||||||||||||||||||||||||||||||||||
| 361 | 0 | print $self->_output_all_sections(); | |||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | sub write_file { | ||||||||||||||||||||||||||||||||||
|
Subroutine
write_file: called CC=10 SCAR=29.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 365 | 1 | my ( $self, $filename ) = @_; | |||||||||||||||||||||||||||||||||||
| 366 | 1 | ▶ | $log ||= get_logger( LOG_CONFIG ); | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$log ||= get_logger("OI2.CONFIG")
MC/DC0%0/2
$log ||= get_logger("OI2.CONFIG")
$log
get_logger("OI2.CONFIG")
Truth table33%1/3
A ||= B
A= $logB= get_logger("OI2.CONFIG")
| |||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||
| 368 | 1 | ▶ | $filename ||= $self->{_m}{filename} || 'config.ini'; | ||||||||||||||||||||||||||||||||||
|
Condition20%1/5
$filename ||= $self->{"_m"}{"filename"} || "config.ini"
$self->{'_m'}{'filename'} || 'config.ini'
MC/DC0%0/2
$filename ||= $self->{"_m"}{"filename"} || "config.ini"
$filename
$self->{'_m'}{'filename'}
Truth table33%1/3
A ||= B
A= $filenameB= $self->{'_m'}{'filename'}
| |||||||||||||||||||||||||||||||||||||
| 369 | 1 | my ( $original_filename ) = ""; | |||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | if ( -f $filename ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 371 | 0 | $original_filename = $filename; | |||||||||||||||||||||||||||||||||||
| 372 | 0 | $filename = "$filename.new"; | |||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||
| 374 | 1 | ▶ | $original_filename ||= ''; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$original_filename ||= ""
MC/DC0%0/1
$original_filename ||= ""
$original_filename
Truth table50%1/2
A
A= $original_filename
| |||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||
| 376 | # Set 'Global' items from the config object root | ||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||
| 378 | 1 | foreach my $key ( @{ $self->{_m}{global} } ) { | |||||||||||||||||||||||||||||||||||
| 379 | 0 | $self->{Global}{ $key } = $self->{ $key }; | |||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||
| 382 | $log->is_debug && | ||||||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | $log->debug( "Writing INI to [$filename] (original: ", | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 384 | "$original_filename)" ); | ||||||||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | open( OUT, '>', $filename ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 386 | || die "Cannot write configuration to [$filename]: $!"; | ||||||||||||||||||||||||||||||||||||
| 387 | 1 | print OUT $self->_output_header(); | |||||||||||||||||||||||||||||||||||
| 388 | 1 | print OUT $self->_output_all_sections(); | |||||||||||||||||||||||||||||||||||
| 389 | 1 | close( OUT ); | |||||||||||||||||||||||||||||||||||
| 390 | 1 | ▶ | if ( $original_filename ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 391 | 0 | unlink( $original_filename ); | |||||||||||||||||||||||||||||||||||
| 392 | 0 | rename( $filename, $original_filename ); | |||||||||||||||||||||||||||||||||||
| 393 | 0 | $filename = $original_filename; | |||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||
| 395 | 1 | return $filename; | |||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||
| 398 | 1 | ▶ | sub _output_header { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_output_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 399 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||
| 400 | 1 | return "# Written by ", ref $self, " at ", scalar localtime, "\n"; | |||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||
| 403 | 1 | ▶ | sub _output_all_sections { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_output_all_sections: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||
| 404 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||
| 405 | 1 | my $out = ''; | |||||||||||||||||||||||||||||||||||
| 406 | 1 | foreach my $full_section ( $self->sections ) { | |||||||||||||||||||||||||||||||||||
| 407 | 3 | my ( $section, $sub_section ) = split /\s+/, $full_section; | |||||||||||||||||||||||||||||||||||
| 408 | 3 | my $comments = $self->get_comments( $section, $sub_section ); | |||||||||||||||||||||||||||||||||||
| 409 | 3 | ▶ | if ( $comments ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 410 | 0 | $out .= "$comments\n"; | |||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||
| 412 | 3 | $out .= join( "\n", "[$full_section]", | |||||||||||||||||||||||||||||||||||
| 413 | $self->_output_section( $section, $sub_section ), | ||||||||||||||||||||||||||||||||||||
| 414 | '' ); | ||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||
| 416 | 1 | return $out; | |||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||
| 419 | 3 | ▶ | sub _output_section { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_output_section: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 420 | 3 | my ( $self, $section, $sub_section ) = @_; | |||||||||||||||||||||||||||||||||||
| 421 | my $show_from = ( $sub_section ) | ||||||||||||||||||||||||||||||||||||
| 422 | ? $self->{ $section }{ $sub_section } | ||||||||||||||||||||||||||||||||||||
| 423 | 3 | ▶ | : $self->{ $section }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 424 | 3 | my @items = (); | |||||||||||||||||||||||||||||||||||
| 425 | 3 | foreach my $key ( keys %{ $show_from } ) { | |||||||||||||||||||||||||||||||||||
| 426 | 15 | ▶ | if ( ref $show_from->{ $key } eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 427 | 2 | foreach my $value ( @{ $show_from->{ $key } } ) { | |||||||||||||||||||||||||||||||||||
| 428 | 4 | push @items, $self->_show_item( $key, $value ); | |||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||
| 431 | elsif ( ref $show_from->{ $key } eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||
| 432 | # no-op -- this should get picked up later | ||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||
| 434 | else { | ||||||||||||||||||||||||||||||||||||
| 435 | 11 | push @items, $self->_show_item( $key, $show_from->{ $key } ); | |||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||
| 438 | 3 | return join "\n", @items; | |||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||
| 442 | 15 | ▶ | sub _show_item { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_show_item: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||
| 443 | 15 | ▶ | my $l = $_[1] || ''; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] || ''
MC/DC0%0/1
$_[1] || ''
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||
| 444 | 15 | ▶ | my $r = $_[2] || ''; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[2] || ''
MC/DC100%1/1
$_[2] || ''
$_[2]
Truth table100%2/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||||||
| 445 | 15 | return join( ' = ', $l, $r ); | |||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||
| 448 | 87 | 1; | |||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||
| 450 | __END__ | ||||||||||||||||||||||||||||||||||||