blib/lib/Text/Vpp.pm

filter: Statementstmt 87.0% 395 / 454 Branchbran 70.1% 153 / 218 Conditioncond 62.2% 28 / 45 MC/DCmcdc 35.7% 10 / 28 Subroutinesub 89.1% 33 / 37 Podpod 44.8% 13 / 29 totaltotal 77.9% 632 / 811 CC 126 SCAR 46.7
CC
126
Cov
80%
processBlock
179.9
new
9.0
substitute
7.8
CRAP 106.9
↑ Summary
1 ############################################################
2 #
3 # $Header: /home/domi/perlDev/Text_Vpp/RCS/Vpp.pm,v 1.27 2005/06/09 13:52:13 domi Exp $
4 #
5 # $Source: /home/domi/perlDev/Text_Vpp/RCS/Vpp.pm,v $
6 # $Revision: 1.27 $
7 # $Locker: $
8 #
9 ############################################################
10  
11 package Text::Vpp;
12  
13 1 require 5.6.0;
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use IO::File ;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use AutoLoader qw/AUTOLOAD/ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 $VERSION = '1.17' ;
22  
23 # tiny FiFo "package"
24  
25 15 ▶sub F_new { return [1]; }
Subroutine F_new: called CC=1 SCAR=0.0
Pod undocumented
26  
27 3 ▶sub F_reset { my $FiFo = $_[0]; $FiFo->[0]= 1; $#$FiFo= 0; }
Subroutine F_reset: called CC=1 SCAR=0.0
Pod undocumented
28  
29 11 ▶sub F_tell { return $_[0]->[0]; }
Subroutine F_tell: called CC=1 SCAR=0.0
Pod undocumented
30  
31 31 ▶sub F_seek { $_[0]->[0]= $_[1]; }
Subroutine F_seek: called CC=1 SCAR=0.0
Pod undocumented
32  
33 23 ▶sub F_print { push @{$_[0]}, $_[1]; }
Subroutine F_print: called CC=1 SCAR=0.0
Pod undocumented
34  
35 120 ▶sub F_getline { my $FiFo = $_[0]; return $FiFo->[($FiFo->[0])++]; }
Subroutine F_getline: called CC=1 SCAR=0.0
Pod undocumented
36  
37 #---------------------
38  
39  
40 sub new
41 15 ▶ {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
42 15 my $type = shift ;
43
44 15 my $self = {} ;
45 15 my $file = shift ;
46 15 my $ref = shift ;
47 15 my $action = shift ;
48 15 my $comment = shift ;
49 15 my $prefix = shift;
50 15 my $suffix = shift;
51 15 my $substitute= shift;
52 15 my $backslash = shift;
53
54 15 ▶ if (defined $ref && (ref($ref) eq "HASH"))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref and ref $ref eq "HASH") 4 11 15
Condition66%2/3
defined $ref and ref $ref eq "HASH"
!ll&&!rl&&r
1104
MC/DC50%1/2
defined $ref and ref $ref eq "HASH"
defined $ref ref $ref eq "HASH"
Truth table66%2/3
A and B
A= defined $refB= ref $ref eq "HASH"
ABresult
0X0
100
111
55 {
56 4 $self->{var} = $ref ;
57 }
58
59 15 ▶ $self->{action} = defined $action ? $action : '@' ;
Branch: 1 branch
BranchTrueFalseTotal
defined $action ? : 3 12 15
60 15 ▶ $self->{comment} = defined $comment ? $comment : '#' ;
Branch: 1 branch
BranchTrueFalseTotal
defined $comment ? : 3 12 15
61 15 ▶ $prefix= '$' unless defined($prefix); #'; # for xemacs
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prefix 12 3 15
62 15 $self->{prefix} = $prefix ;
63 15 $self->{suffix} = $suffix;
64 15 $self->{substitute}= $substitute;
65 15 ▶ $self->{backslash} = defined $backslash ? $backslash : 1 ;
Branch: 1 branch
BranchTrueFalseTotal
defined $backslash ? : 3 12 15
66 15 ▶ if ( UNIVERSAL::can($file,'getline') )
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($file, 'getline')) { } 1 14 15
67 1 { $self->{fileDesc}= $file; $self->{name}= ref($file); }
68 else
69 14 { $self->{fileDesc} = new IO::File;
70 14 ▶ $self->{fileDesc}->open($file) || die "can't open $file \n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"fileDesc"}->open($file) or die "can't open $file \n" 14 0 14
71 14 $self->{name} = $file ;
72 }
73  
74 15 $self->{Fifo}= F_new;
75
76 15 $self= bless $self,$type ;
77  
78 15 $self->setActionChar($self->{action});
79 15 $self->setPrefixChar($self->{prefix});
80 15 $self->setSuffixChar($self->{suffix});
81 15 $self->setSubstitute($self->{substitute});
82 15 $self->setCommentChar($self->{comment});
83
84 15 return $self;
85 }
86  
87  
88 sub myEval
89 11 ▶ {
Subroutine myEval: called CC=3 SCAR=11.2
Pod undocumented
90 11 my $self = shift ;
91 11 my $expression = shift ;
92 11 my $out = shift ;
93  
94 # transform each $xxx into $self->{var}{$xxx}
95 # this allows for the creation of new variables
96 # one may use the construction ${\w} to protect against this
97 11 $expression =~ s[\$(\w+)\b] [\$self->{var}{$1}]g ;
98  
99 5 ▶ local *Vpp_Out= ref $out ? sub{push @$out,@_;} :
Subroutine __ANON__: called CC=1 SCAR=0.0
100 0 ▶ sub {die "Cannot call Vpp_Out in \@INCLUDE line";} ;
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 9 2 11
101 11 my $return = eval($expression) ;
102  
103 11 ▶ if ($@ ne "")
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 0 11 11
104 {
105 0 die "Error in eval : $@ \n",
106 "line : $expression \nfile: $self->{name} line $.\n";
107 }
108  
109 11 return ($return);
110 }
111  
112 sub ReplaceVars
113 56 ▶ {
Subroutine ReplaceVars: called CC=3 SCAR=12.0
Pod undocumented
114 56 my $self = shift ;
115  
116 56 $_[0] =~ s[\$({?)(\w+)\b(}?)]
117 42 ▶ [if (defined($self->{var}{$2}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'var'}{$2}) { } 42 0 42
118 42 ▶ { "\$self->{var}{$2}" . ( !$1 ? $3 : '' ); }
Branch: 1 branch
BranchTrueFalseTotal
!$1 ? : 42 0 42
119 0 else {"\$$1$2$3";}
120 ]ge ;
121  
122 }
123  
124 sub myExpression
125 41 ▶ {
Subroutine myExpression: called CC=2 SCAR=7.1
Pod undocumented
126 41 my $self = shift ;
127 41 my $expression = shift ;
128
129 41 $self->ReplaceVars($expression);
130
131 41 my $return = eval($expression) ;
132
133 41 ▶ if ($@ ne "")
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 0 41 41
134 {
135 0 die "Error in eval : $@ \n",
136 "line : $expression \nfile: $self->{name} line $.\n";
137 }
138  
139 41 return ($return);
140 }
141  
142  
143 sub substitute
144 16 ▶ {
Subroutine substitute: called CC=5 SCAR=20.6
Pod documented
145 #return array ref made of new file
146 16 my ($self,$fileOut) = @_ ;
147
148 16 $self->{errorText} = [] ;
149 16 $self->{error} = 0;
150
151 16 $self->{IF_Level}= 0; $self->{FOR_Level}= 0;
152
153 16 my $res = $self->processBlock(1,1,0,0,0) ;
154  
155 16 chomp @$res ;
156  
157 16 ▶ if (defined $fileOut)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fileOut) { } 1 15 16
158 {
159 1 ▶ if ( UNIVERSAL::can($fileOut,'print') )
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($fileOut, 'print')) { } 1 0 1
160 {
161 1 $fileOut->print(join("\n",@$res) ,"\n") ;
162 }
163 else
164 {
165 0 print "writing $fileOut\n";
166 0 my $FileOut = $fileOut;
167 0 ▶ $FileOut= ">$fileOut" unless $fileOut =~/^>/;
Branch: 1 branch
BranchTrueFalseTotal
unless $fileOut =~ /^>/ 0 0 0
168 0 my $SubsOut = new IO::File;
169 0 ▶ unless( $SubsOut->open($FileOut) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($SubsOut->open($FileOut)) 0 0 0
170 {
171 0 $self->snitch("cannot open $fileOut") ;
172 0 return 0 ;
173 }
174 0 print $SubsOut join("\n",@$res) ,"\n" ;
175 0 close $SubsOut ;
176 }
177 }
178 else
179 {
180 15 $self->{result} = $res ;
181 }
182
183 16 return (not $self->{error} ) ;
184 }
185  
186 sub getText
187 15 ▶ {
Subroutine getText: called CC=1 SCAR=0.0
Pod documented
188 15 my $self = shift ;
189 15 return $self->{result} ;
190 }
191  
192 sub getErrors
193 0 ▶ {
Subroutine getErrors: not called CC=1 SCAR=6.9
Pod documented
194 0 my $self = shift ;
195 0 return $self->{errorText} ;
196 }
197  
198 0 ▶sub Vpp_Out {croak "Original Vpp_Out called";}
Subroutine Vpp_Out: not called CC=1 SCAR=6.9
Pod undocumented
199  
200 sub do_shell
201 3 ▶ {
Subroutine do_shell: called CC=2 SCAR=7.0
Pod undocumented
202 3 my $self=shift;
203 3 my $shell_code = shift;
204 3 my $out= `$shell_code`;
205 3 ▶ warn "Error in SHELL code : status is $? \n",
Branch: 1 branch
BranchTrueFalseTotal
if $? > 0 0 3 3
206 "in file: $self->{name} line $.\n",
207 "code was\n$shell_code" if $? > 0;
208 3 split(/\n/,$out) ;
209 }
210  
211 sub processBlock
212 92 ▶ {
Subroutine processBlock: called CC=95 SCAR=51.9
Pod undocumented
213 # three parameters :
214 # GlobExpand : false if nothing should be expanded
215 # Expand : true if the calling ifdef is true
216 92 my ($self,$globExpand,$expand,$EnterLoop,$useFiFo,$ScanOnly)=@_ ;
217 92 ▶ $expand= 0 unless $globExpand;
Branch: 1 branch
BranchTrueFalseTotal
unless $globExpand 21 71 92
218 92 my $FiFo = $self->{Fifo};
219
220 92 my $out = [] ;
221
222 # Done is used to evaluate the elsif
223 92 my ($done) = $expand ;
224
225 # Stage is used for syntax check
226 92 ▶ my ($stage) = ($self->{IF_Level} == 0 || $EnterLoop) ? 0 : 1 ;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'IF_Level'} == 0 || $EnterLoop ? : 63 29 92
Condition100%3/3
$self->{"IF_Level"} == 0 or $EnterLoop
l!l&&r!l&&!r
194429
MC/DC100%2/2
$self->{"IF_Level"} == 0 or $EnterLoop
$self->{"IF_Level"} == 0 $EnterLoop
Truth table100%3/3
A or B
A= $self->{"IF_Level"} == 0B= $EnterLoop
ABresult
1X1
011
000
227
228 92 my ($line,$keep,$SubsIt) ;
229 92 local $/ = "\n"; # revert to standard line ending
230
231 92 my $Within_Perl_Input = 0;
232 92 my $Perl_Input_Termination;
233 my $Perl_Code;
234  
235 92 my $Within_Shell_Input = 0;
236 92 my $Shell_Input_Termination;
237 my $Shell_Code;
238  
239 # attention: keep the following declaration in sync with
240 # the assignments whence processing 'EVAL' line
241 92 my $action = $self->{action} ;
242 92 my $comment = $self->{comment};
243 92 my $prefix = $self->{prefix} ;
244 92 my $suffix = $self->{suffix} ;
245 92 my $substitute= $self->{substitute};
246 92 my $backslash = $self->{backslash};
247 92 my $VarPat = $self->{VarPat};
248 92 my $commentPat = $self->{commentPat};
249 92 my $actionPat = $self->{actionPat};
250 92 my $ifPat = $self->{ifPat};
251 92 my $elsifPat = $self->{elsifPat};
252 92 my $elsePat = $self->{elsePat};
253 92 my $endifPat = $self->{endifPat};
254 92 my $includePat = $self->{includePat};
255 92 my $evalPat = $self->{evalPat};
256 92 my $quotePat = $self->{quotePat};
257 92 my $endquotePat= $self->{endquotePat};
258 92 my $subsPat = $self->{subsPat};
259 92 my $subsLeadPat= $self->{subsLeadPat};
260 92 my $foreachPat = $self->{foreachPat};
261 92 my $endforPat = $self->{endforPat};
262 92 my $perlPat = $self->{perlPat};
263 92 my $shellPat = $self->{shellPat};
264  
265 92 ▶ if ( $useFiFo )
Branch: 1 branch
BranchTrueFalseTotal
if ($useFiFo) { } 49 43 92
266 {
267 49 $line= F_getline($FiFo);
268 }
269 else
270 {
271 43 $line = $self->{fileDesc}->getline;
272 43 ▶ F_print($FiFo,$line) if $ScanOnly;
Branch: 1 branch
BranchTrueFalseTotal
if $ScanOnly 9 34 43
273 }
274
275 92 ▶ while (defined($line))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 332 16 348
276 {
277 332 ▶ if ( $Within_Perl_Input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Within_Perl_Input) 33 299 332
278 33 ▶ if ( $line =~ /$Perl_Input_Termination/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$Perl_Input_Termination/) { } 2 31 33
279 2 $Within_Perl_Input= 0;
280 2 ▶ if ( $expand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 2 0 2
281 # $VAR may be used in eval'ed code
282 2 my $VAR = $self->{var} ;
283 0 ▶ local *Vpp_Out= sub {push @$out, @_; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
284 0 ▶ my $res = eval($Perl_Code);
Subroutine Chances: called CC=3 SCAR=11.0
Subroutine Hello: called CC=1 SCAR=0.0
Subroutine WhoIs: called CC=1 SCAR=0.0
Subroutine trans: called CC=1 SCAR=0.0
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if ($nseq > $num) { } 0 2 2
if ($k <= $nseq) 13 2 15
285 2 ▶ die "Error in eval(uating) PERL code : $@ \n",
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
286 "in file: $self->{name} line $.\n",
287 "code was\n$Perl_Code" if $@;
288 }
289 } else {
290 31 $Perl_Code.= $line;
291 }
292 33 next;
293 }
294  
295 299 ▶ if ( $Within_Shell_Input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Within_Shell_Input) 3 296 299
296 3 ▶ if ( $line =~ /$Shell_Input_Termination/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$Shell_Input_Termination/) { } 1 2 3
297 1 $Within_Shell_Input= 0;
298 1 ▶ push (@$out, $self->do_shell($Shell_Code)) if ( $expand );
Branch: 1 branch
BranchTrueFalseTotal
if $expand 1 0 1
299 } else {
300 2 $Shell_Code.= $line;
301 }
302 3 next;
303 }
304  
305 296 chomp($line);
306 #skip commented lines
307 296 ▶ next if (defined $commentPat and $line =~ $commentPat);
Branch: 1 branch
BranchTrueFalseTotal
if defined $commentPat and $line =~ /$commentPat/i 8 288 296
Condition66%2/3
defined $commentPat and $line =~ /$commentPat/i
!ll&&!rl&&r
02888
MC/DC50%1/2
defined $commentPat and $line =~ /$commentPat/i
defined $commentPat $line =~ /$commentPat/i
Truth table66%2/3
A and B
A= defined $commentPatB= $line =~ /$commentPat/i
ABresult
0X0
100
111
308
309 # get following line if the line is ended by \
310 # (followed by tab or whitespaces)
311 288 ▶ if ($backslash == 1 and $line =~ s/\\\s*$//)
Branch: 1 branch
BranchTrueFalseTotal
if ($backslash == 1 and $line =~ s/\\\s*$//) 5 283 288
Condition100%3/3
$backslash == 1 and $line =~ s/\\\s*$//
!ll&&!rl&&r
202635
MC/DC100%2/2
$backslash == 1 and $line =~ s/\\\s*$//
$backslash == 1 $line =~ s/\\\s*$//
Truth table100%3/3
A and B
A= $backslash == 1B= $line =~ s/\\\s*$//
ABresult
0X0
100
111
312 {
313 5 $keep .= $line ;
314 5 next ;
315 }
316
317 283 my $lineIn;
318 283 ▶ if (defined $keep)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $keep) { } 5 278 283
319 {
320 5 $lineIn = $keep.$line ;
321 5 undef $keep ;
322 }
323 else
324 {
325 278 $lineIn = $line ;
326 }
327
328 283 study $lineIn;
329 283 ▶ if ($lineIn =~ s/$ifPat//i)
Branch: 12 branches
BranchTrueFalseTotal
if ($lineIn =~ s/$ifPat//i) { } 29 254 283
elsif ($lineIn =~ s/$elsifPat//) { } 2 252 254
elsif ($lineIn =~ /$elsePat/i) { } 6 246 252
elsif ($lineIn =~ /$endifPat/i) { } 29 217 246
elsif ($lineIn =~ s/$foreachPat//) { } 27 190 217
elsif ($lineIn =~ /$endforPat/i) { } 47 143 190
elsif ($lineIn =~ /$includePat/i) { } 3 140 143
elsif ($lineIn =~ s/$evalPat//) { } 9 131 140
elsif ($lineIn =~ s/$perlPat//) { } 2 129 131
elsif ($lineIn =~ s/$shellPat//) { } 3 126 129
elsif ($lineIn =~ /$quotePat/i) { } 1 125 126
elsif ($SubsIt = $lineIn =~ /$subsLeadPat/ || !($lineIn =~ /$actionPat/)) { } 125 0 125
330 {
331 # process the lines after the IF,
332 # don't evaluate the boolean expression if ! $expand
333 29 ▶ my ($expandLoc) = $expand && $self->myExpression($lineIn) ;
Condition100%3/3
$expand && $self->myExpression($lineIn)
!ll&&!rl&&r
51311
MC/DC100%2/2
$expand && $self->myExpression($lineIn)
$expand $self->myExpression($lineIn)
Truth table100%3/3
A && B
A= $expandB= $self->myExpression($lineIn)
ABresult
0X0
100
111
334 29 my $Current_IF_Level = $self->{IF_Level}++;
335 push @$out,
336 29 @{$self->processBlock($expand,$expandLoc,0,$useFiFo,$ScanOnly)};
337  
338 29 ▶ if ( $self->{IF_Level} != $Current_IF_Level )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"IF_Level"} != $Current_IF_Level) 0 29 29
339 {
340 0 $self->snitch("illegal nesting of FOREACH and IF"); return [];
341 }
342 }
343 elsif ($lineIn =~ s/$elsifPat//)
344 {
345 # process the lines after the ELSIF, done is set if the block
346 # is expanded
347 2 ▶ unless ($stage == 1 or $stage ==2)
Branch: 1 branch
BranchTrueFalseTotal
unless ($stage == 1 or $stage == 2) 0 2 2
Condition66%2/3
$stage == 1 or $stage == 2
l!l&&r!l&&!r
110
MC/DC0%0/2
$stage == 1 or $stage == 2
$stage == 1 $stage == 2
Truth table66%2/3
A or B
A= $stage == 1B= $stage == 2
ABresult
1X1
011
000
348 {
349 0 $self->snitch("unexpected elsif");
350 }
351 2 $stage = 2 ;
352 2 ▶ if ( $done ) # if-condition was true
Branch: 1 branch
BranchTrueFalseTotal
if ($done) { } 0 2 2
353 0 { $expand= 0; } # now we are in the else
354 else
355 { # if-condition was false, so here we have a new chance
356 2 ▶ $expand = $globExpand && $self->myExpression($lineIn) ;
Condition66%2/3
$globExpand && $self->myExpression($lineIn)
!ll&&!rl&&r
011
MC/DC50%1/2
$globExpand && $self->myExpression($lineIn)
$globExpand $self->myExpression($lineIn)
Truth table66%2/3
A && B
A= $globExpandB= $self->myExpression($lineIn)
ABresult
0X0
100
111
357 2 $done = $expand ;
358 }
359 }
360 elsif ($lineIn =~ $elsePat)
361 {
362 6 ▶ if ($stage == 0 || $stage == 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($stage == 0 or $stage == 3) 0 6 6
Condition33%1/3
$stage == 0 or $stage == 3
l!l&&r!l&&!r
006
MC/DC0%0/2
$stage == 0 or $stage == 3
$stage == 0 $stage == 3
Truth table33%1/3
A or B
A= $stage == 0B= $stage == 3
ABresult
1X1
011
000
363 {
364 0 $self->snitch("unexpected else");
365 }
366 6 $stage = 3 ;
367 6 ▶ $expand = $globExpand && !$done ;
Condition66%2/3
$globExpand && !$done
!ll&&!rl&&r
051
MC/DC50%1/2
$globExpand && !$done
$globExpand !$done
Truth table66%2/3
A && not(B)
A= $globExpandB= !$done
ABresult
0X0
100
111
368 }
369 elsif ($lineIn =~ $endifPat)
370 {
371 0 ▶ if ($stage == 0) {$self->snitch("unexpected endif");}
Branch: 1 branch
BranchTrueFalseTotal
if ($stage == 0) 0 29 29
372 29 $self->{IF_Level}--;
373 29 return $out ;
374 }
375 elsif ($lineIn =~ s/$foreachPat//)
376 {
377 my ($emptyLoop,$Current_FOR_Level,$Start_of_Loop)
378 27 = (1,$self->{FOR_Level},1);
379  
380 27 ▶ if ( $expand )
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 15 12 27
381 {
382 15 my $LoopExpr = $lineIn;
383 15 $LoopExpr =~ s/^\s*my\s//; # remove my if there
384 15 my $LoopVar ;
385 15 ▶ $LoopVar = $1 if $LoopExpr =~ s/\$(\w+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $LoopExpr =~ s/\$(\w+)// 15 0 15
386  
387 15 $self->ReplaceVars($LoopExpr);
388 15 my @LoopList= eval $LoopExpr;
389 15 ▶ if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 15 15
390 {
391 0 die "Error in FOREACH-List-Expression: $@\n",
392 "line : $lineIn\nfile: $self->{name} line $.\n";
393 }
394 15 $emptyLoop= scalar(@LoopList) == 0;
395  
396 15 ▶ unless ($emptyLoop)
Branch: 1 branch
BranchTrueFalseTotal
unless ($emptyLoop) 14 1 15
397 {
398 14 ▶ if ( $self->{FOR_Level} == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'FOR_Level'} == 0) { } 3 11 14
399 {
400 3 F_reset($FiFo);
401 3 $self->{FOR_Level}++;
402 3 $self->processBlock(0,0,1,0,1); # Scan Only
403 3 ▶ if ( $Current_FOR_Level != $self->{FOR_Level} )
Branch: 1 branch
BranchTrueFalseTotal
if ($Current_FOR_Level != $self->{"FOR_Level"}) 0 3 3
404 {
405 0 $self->snitch("illegal nesting for IF and FOREACH");
406 0 return [];
407 }
408 3 $Start_of_Loop= 1;
409 }
410 11 else { $Start_of_Loop= F_tell($FiFo); }
411  
412 14 foreach my $LpVar (@LoopList)
413 {
414 31 $self->{var}{$LoopVar}= $LpVar;
415 31 $self->{FOR_Level}++;
416 31 F_seek($FiFo,$Start_of_Loop);
417  
418 31 push @$out, @{$self->processBlock(1,1,1,1,0)} ;
419  
420 31 ▶ if ( $Current_FOR_Level != $self->{FOR_Level} )
Branch: 1 branch
BranchTrueFalseTotal
if ($Current_FOR_Level != $self->{"FOR_Level"}) 0 31 31
421 {
422 0 $self->snitch("illegal nesting for IF and FOREACH");
423 0 return [];
424 }
425 }
426 }
427 }
428  
429 27 ▶ if ($emptyLoop) # loop has never been executed
Branch: 1 branch
BranchTrueFalseTotal
if ($emptyLoop) 13 14 27
430 {
431 13 ▶ if ( $self->{FOR_Level} == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'FOR_Level'} == 0) { } 3 10 13
432 {
433 3 $self->{FOR_Level}++;
434 3 $self->processBlock(0,0,1,0,0); # just skip
435 }
436 else
437 {
438 10 $self->{FOR_Level}++;
439 10 $self->processBlock(0,0,1,$useFiFo,$ScanOnly); # process but don't expand
440 }
441 13 ▶ if ( $Current_FOR_Level != $self->{FOR_Level} )
Branch: 1 branch
BranchTrueFalseTotal
if ($Current_FOR_Level != $self->{"FOR_Level"}) 0 13 13
442 {
443 0 $self->snitch("illegal nesting for IF and FOREACH");
444 0 return [];
445 }
446 }
447 }
448 elsif ($lineIn =~ $endforPat)
449 {
450 47 $self->{FOR_Level}--; return $out;
451 }
452 elsif ($lineIn =~ $includePat)
453 {
454 3 ▶ if ( $expand )
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 3 0 3
455 {
456 # look like we've got a new file to slurp
457 3 $lineIn =~ s/$includePat//;
458 3 my $newFile;
459 3 ▶ my $Incl = $lineIn =~ /^[\w_\-.]+$/ ?
Branch: 1 branch
BranchTrueFalseTotal
$lineIn =~ /^[\w_\-.]+$/ ? : 1 2 3
460 $lineIn : $self->myEval($lineIn);
461  
462 3 ▶ if ( ref($Incl) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $Incl eq 'HASH') { } 1 2 3
463 {
464 1 ▶ $Incl->{action}= $action unless defined $Incl->{action};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Incl->{"action"} 0 1 1
465 1 ▶ $Incl->{comment}= $comment unless defined $Incl->{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Incl->{"comment"} 0 1 1
466 1 ▶ $Incl->{prefix}= $prefix unless defined $Incl->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Incl->{"prefix"} 0 1 1
467 1 ▶ $Incl->{suffix}= $suffix unless defined $Incl->{suffix};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Incl->{"suffix"} 1 0 1
468 1 ▶ $Incl->{substitute}= $substitute unless defined $Incl->{substitute};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Incl->{"substitute"} 1 0 1
469 1 ▶ $Incl->{backslash}= $backslash unless defined $Incl->{backslash};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Incl->{"backslash"} 1 0 1
470 1 ▶ unless ( defined $Incl->{file} )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Incl->{"file"}) 0 1 1
471 {
472 0 $self->snitch("illegal file at include $lineIn");
473 0 return [];
474 }
475
476 $newFile = Text::Vpp-> new ($Incl->{file}, $self->{var},
477 $Incl->{action}, $Incl->{comment},
478 $Incl->{prefix}, $Incl->{suffix},
479 1 $Incl->{substitute}, $Incl->{backslash});
480 }
481 else
482 {
483 $newFile = Text::Vpp-> new ($Incl, $self->{var},
484 2 $action,$comment,$prefix,$suffix,
485 $substitute,$backslash) ;
486 }
487  
488 3 ▶ if ($newFile->substitute())
Branch: 1 branch
BranchTrueFalseTotal
if ($newFile->substitute) { } 3 0 3
489 {
490 3 my $res = $newFile->getText() ;
491 3 push @$out, @$res ;
492 }
493 else
494 {
495 # an error occured
496 0 push @{$self->{errorText}}, @{$newFile->getErrors()} ;
497 0 $self->{error} = 1;
498 0 return $out ;
499 }
500 3 undef $newFile ;
501 }
502 }
503 elsif ($lineIn =~ s/$evalPat//)
504 {
505 9 ▶ if ( $expand ) {$self->myEval($lineIn, $out);}
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 9 0 9
506  
507 # reassign in case there was a change to some
508 # of the following
509 # attention: keep the following assignments in sync with
510 # with the declarations at the beginning of this sub
511 9 $action = $self->{action} ;
512 9 $comment = $self->{comment};
513 9 $prefix = $self->{prefix} ;
514 9 $suffix = $self->{suffix} ;
515 9 $substitute = $self->{substitute};
516 9 $backslash = $self->{backslash};
517 9 $VarPat = $self->{VarPat};
518 9 $commentPat = $self->{commentPat};
519 9 $actionPat = $self->{actionPat};
520 9 $ifPat = $self->{ifPat};
521 9 $elsifPat = $self->{elsifPat};
522 9 $elsePat = $self->{elsePat};
523 9 $endifPat = $self->{endifPat};
524 9 $includePat = $self->{includePat};
525 9 $evalPat = $self->{evalPat};
526 9 $quotePat = $self->{quotePat};
527 9 $endquotePat= $self->{endquotePat};
528 9 $subsPat = $self->{subsPat};
529 9 $subsLeadPat= $self->{subsLeadPat};
530 9 $foreachPat = $self->{foreachPat};
531 9 $endforPat = $self->{endforPat};
532 9 $perlPat = $self->{perlPat};
533 9 $shellPat = $self->{shellPat};
534 }
535 elsif ($lineIn =~ s/$perlPat//)
536 2 { $Within_Perl_Input= 1;
537 2 $Perl_Code= "";
538 2 $lineIn =~ s/\s*$//;
539 2 $Perl_Input_Termination= qr/$lineIn/;
540 }
541 elsif ($lineIn =~ s/$shellPat//)
542 {
543 3 ▶ if ($lineIn =~ s/<<\s*//)
Branch: 1 branch
BranchTrueFalseTotal
if ($lineIn =~ s/<<\s*//) { } 1 2 3
544 {
545 1 $Within_Shell_Input= 1;
546 1 $Shell_Code= "";
547 1 $lineIn =~ s/\s*$//;
548 1 $Shell_Input_Termination= qr/$lineIn/;
549 }
550 else
551 {
552 2 push @$out, $self->do_shell($lineIn);
553 }
554 }
555 elsif ( $lineIn =~ /$quotePat/ )
556 {
557 1 my $Str = $lineIn; $Str =~ s/$quotePat//;
558 1 my ($ListSeparator,$ListPrefix);
559 # format @QUOTE (ListPrefix,ListSeparator)
560 1 ▶ if ( $Str =~ /^\(/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($Str =~ /^\(/) 1 0 1
561 {
562 1 ▶ if ( $Str =~ /^\(\s*(\S)([^\1]*?)\1\s*(?:,\s*(\S)([^\2]*?)\3\s*\))?/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($Str =~ /^\(\s*(\S)([^\1]*?)\1\s*(?:,\s*(\S)([^\2]*?)\3\s*\))?/) { } 1 0 1
563 1 { $ListPrefix= $2; $ListSeparator= $4; }
564 0 else { $self->snitch("illegal QUOTE action : $lineIn"); }
565 }
566 1 $Str= '';
567
568 1 while(1)
569 {
570 0 ▶ if ( $useFiFo ) { $line= F_getline($FiFo); }
Branch: 1 branch
BranchTrueFalseTotal
if ($useFiFo) { } 0 6 6
571 else
572 {
573 6 $line = $self->{fileDesc}->getline;
574 6 ▶ F_print($FiFo,$line) if $ScanOnly;
Branch: 1 branch
BranchTrueFalseTotal
if $ScanOnly 0 6 6
575 }
576 6 ▶ last if $line =~ $endquotePat;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$endquotePat/i 1 5 6
577
578 5 ▶ unless ( defined $line )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 5 5
579 {
580 0 $self->snitch("EOF while scanning QUOTE");
581 0 return [];
582 }
583  
584 5 ▶ $Str.= $line if ( $expand );
Branch: 1 branch
BranchTrueFalseTotal
if $expand 5 0 5
585 }
586
587 1 ▶ if ( $expand )
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 1 0 1
588 {
589 # protect '$' and '@'
590 1 ▶ if ( "$prefix$suffix" !~ /\$/
Branch: 1 branch
BranchTrueFalseTotal
unless ("$prefix$suffix" =~ /\$/ or defined $ListPrefix and $ListPrefix =~ /\$/) 1 0 1
Condition33%2/6
"$prefix$suffix" =~ /\$/ or defined $ListPrefix and $ListPrefix =~ /\$/
l!l&&r!l&&!r
001
defined $ListPrefix and $ListPrefix =~ /\$/
!ll&&!rl&&r
010
MC/DC0%0/3
"$prefix$suffix" =~ /\$/ or defined $ListPrefix and $ListPrefix =~ /\$/
"$prefix$suffix" =~ /\$/ defined $ListPrefix $ListPrefix =~ /\$/
Truth table25%1/4
A or B and C
A= "$prefix$suffix" =~ /\$/B= defined $ListPrefixC= $ListPrefix =~ /\$/
ABCresult
1XX1
0111
00X0
0100
591 && ( !defined($ListPrefix) || $ListPrefix !~ /\$/ ) )
592 1 { $Str =~ s/(?<!\\)\$/\\\$/g; }
593
594 1 ▶ if ( "$prefix$suffix" !~ /\@/
Branch: 1 branch
BranchTrueFalseTotal
unless ("$prefix$suffix" =~ /\@/ or defined $ListPrefix and $ListPrefix =~ /\@/) 1 0 1
Condition33%2/6
"$prefix$suffix" =~ /\@/ or defined $ListPrefix and $ListPrefix =~ /\@/
l!l&&r!l&&!r
001
defined $ListPrefix and $ListPrefix =~ /\@/
!ll&&!rl&&r
010
MC/DC0%0/3
"$prefix$suffix" =~ /\@/ or defined $ListPrefix and $ListPrefix =~ /\@/
"$prefix$suffix" =~ /\@/ defined $ListPrefix $ListPrefix =~ /\@/
Truth table25%1/4
A or B and C
A= "$prefix$suffix" =~ /\@/B= defined $ListPrefixC= $ListPrefix =~ /\@/
ABCresult
1XX1
0111
00X0
0100
595 && ( !defined($ListPrefix) || $ListPrefix !~ /\@/ ) )
596 1 { $Str =~ s/(?<!\\)\@/\\\@/g; }
597
598 1 ▶ if ( defined $ListPrefix ) { $Str =~ s/\Q$ListPrefix\E/\@/g; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ListPrefix) 1 0 1
599  
600 # substitute variables
601 1 ▶ if ( defined $suffix )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) { } 1 0 1
602 {
603 1 $Str =~ s[$VarPat][\$self->{var}{$1}]g;
604 }
605 else
606 {
607 0 $Str =~ s[$VarPat]
608 0 ▶ [ { "\$self->{var}{$2}" . ( !$1 ? $3 : '' ) ;} ]ge ;
Branch: 1 branch
BranchTrueFalseTotal
!$1 ? : 0 0 0
609 }
610
611 1 ▶ if ( defined $ListSeparator )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ListSeparator) { } 1 0 1
612 1 { local $"= $ListSeparator; $Str = eval("qq($Str)"); }
613 0 else { $Str = eval("qq($Str)"); }
614
615 1 ▶ if ($@ ne "")
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 0 1 1
616 {
617 0 die "Error in QUOTE/eval : $@ \n",
618 "expression:\n$Str\n\nfile: $self->{name} line $.\n";
619 }
620
621 1 chomp $Str;
622 1 push @$out, split /\n/,$Str;
623 }
624 }
625 ▶ elsif ( $SubsIt=($lineIn =~ $subsLeadPat) || $lineIn !~ $actionPat )
Condition66%2/3
$lineIn =~ /$subsLeadPat/ || !($lineIn =~ /$actionPat/)
l!l&&r!l&&!r
151100
MC/DC0%0/2
$lineIn =~ /$subsLeadPat/ || !($lineIn =~ /$actionPat/)
$lineIn =~ /$subsLeadPat/ !($lineIn =~ /$actionPat/)
Truth table66%2/3
A || not(B)
A= $lineIn =~ /$subsLeadPat/B= !($lineIn =~ /$actionPat/)
ABresult
1X1
011
000
626 {
627 # process the line
628 125 ▶ if ($expand)
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 93 32 125
629 {
630 93 ▶ if ( $SubsIt ) # eval substitution parts
Branch: 1 branch
BranchTrueFalseTotal
if ($SubsIt) 93 0 93
631 {
632 93 $lineIn =~ s/$subsPat/$self->myExpression($1)/ge;
633 }
634
635 # substitute variables
636 93 ▶ if ( defined $suffix )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) { } 1 92 93
637 {
638 1 $lineIn =~ s[$VarPat]
639 0 ▶ [ if (defined($self->{var}{$1}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'var'}{$1}) { } 0 0 0
640 0 { $self->{var}{$1};}
641 0 else {"$prefix$1$suffix" ;}
642 ]ge ;
643 }
644 else
645 {
646 92 $lineIn =~ s[$VarPat]
647 68 ▶ [ if (defined($self->{var}{$2}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'var'}{$2}) { } 68 0 68
648 68 ▶ { $self->{var}{$2} . ( !$1 ? $3 : '' ) ;}
Branch: 1 branch
BranchTrueFalseTotal
!$1 ? : 66 2 68
649 0 else {"$prefix$1$2$3" ;}
650 ]ge ;
651 }
652
653 93 push @$out, $lineIn ;
654 }
655 }
656 else
657 {
658 0 $self->snitch("Unknown command :$lineIn") ;
659 }
660 }
661
662 continue
663 {
664 256 ▶ if ( $useFiFo )
Branch: 1 branch
BranchTrueFalseTotal
if ($useFiFo) { } 71 185 256
665 71 { $line= F_getline($FiFo); }
666 else
667 {
668 185 $line = $self->{fileDesc}->getline;
669 185 ▶ F_print($FiFo,$line) if $ScanOnly;
Branch: 1 branch
BranchTrueFalseTotal
if $ScanOnly 14 171 185
670 }
671 }
672  
673
674 16 ▶ if ($self->{IF_Level} > 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'IF_Level'} > 0) { } 0 16 16
elsif ($self->{'FOR_Level'} > 0) { } 0 16 16
675 {
676 0 $self->snitch("Finished inside a conditionnal block");
677 }
678 elsif ( $self->{FOR_Level} > 0 )
679 {
680 0 $self->snitch("Finished inside a FOREACH block");
681 }
682  
683 16 return $out ;
684 }
685  
686 1 1;
687  
688 __END__
↑ Summary