blib/lib/Bat/Interpreter.pm

filter: Statementstmt 93.9% 281 / 299 Branchbran 82.4% 94 / 114 Conditioncond 69.2% 18 / 26 MC/DCmcdc 52.9% 9 / 17 Subroutinesub 100% 29 / 29 Podpod 100% 1 / 1 totaltotal 88.8% 432 / 486 SCAR 43.1
CC
69
Cov
90%
_handle_special_command
21.5
_handle_condition
13.2
__ANON__
10.0
CRAP 74.5
↑ Summary Build »
1 package Bat::Interpreter;
2  
3 25 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 25 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Types::Standard qw(ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use App::BatParser 0.011;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Bat::Interpreter::Delegate::FileStore::LocalFileSystem;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 25 ▶use Bat::Interpreter::Delegate::Executor::PartialDryRunner;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 25 ▶use Bat::Interpreter::Delegate::LineLogger::Silent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 25 ▶use File::Glob;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 25 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 25 our $VERSION = '0.024'; # VERSION
18  
19 # ABSTRACT: Pure perl interpreter for a small subset of bat/cmd files
20  
21 has 'batfilestore' => (
22 is => 'rw',
23 isa => ConsumerOf ['Bat::Interpreter::Role::FileStore'],
24 default => sub {
25 25 ▶ Bat::Interpreter::Delegate::FileStore::LocalFileSystem->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
26 }
27 25 );
28  
29 has 'executor' => (
30 is => 'rw',
31 isa => ConsumerOf ['Bat::Interpreter::Role::Executor'],
32 default => sub {
33 25 ▶ Bat::Interpreter::Delegate::Executor::PartialDryRunner->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
34 }
35 25 );
36  
37 has 'linelogger' => (
38 is => 'rw',
39 isa => ConsumerOf ['Bat::Interpreter::Role::LineLogger'],
40 default => sub {
41 24 ▶ Bat::Interpreter::Delegate::LineLogger::Silent->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
42 }
43 25 );
44  
45 sub run {
46 27 ▶ my $self = shift();
Subroutine run: called CC=8 SCAR=20.9
Pod documented
47 27 my $filename = shift();
48 27 ▶ my $external_env = shift() // \%ENV;
Condition100%2/2
shift() // \%ENV
l!l
324
MC/DC100%1/1
shift() // \%ENV
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
49  
50 27 my $parser = App::BatParser->new;
51  
52 27 my $ensure_last_line_has_carriage_return = "\r\n";
53 27 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 27 27
54 0 $ensure_last_line_has_carriage_return = "\n";
55 }
56  
57 27 my $parse_tree =
58 $parser->parse( $self->batfilestore->get_contents($filename) . $ensure_last_line_has_carriage_return );
59 27 ▶ if ($parse_tree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse_tree) { } 27 0 27
60 27 my $lines = $parse_tree->{'File'}{'Lines'};
61  
62 27 my %environment = %$external_env;
63  
64 # Index file based on labels
65 #Only for perl >= 5.020
66 #my %line_from_label = List::AllUtils::pairmap { $b->{'Label'}{'Identifier'} => $a }
67 #%{$lines}[ List::AllUtils::indexes { exists $_->{'Label'} } @$lines ];
68 27 my %line_from_label;
69 27 ▶ for ( my $i = 0; $i < scalar @$lines; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$lines) 163 27 190
70 163 my $line = $lines->[$i];
71 163 ▶ if ( exists $line->{'Label'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $line->{"Label"}) 21 142 163
72 21 $line_from_label{ $line->{'Label'}{'Identifier'} } = $i;
73 }
74 }
75 27 $line_from_label{'EOF'} = scalar @$lines;
76 27 $line_from_label{'eof'} = scalar @$lines;
77 27 my $context = { 'ENV' => \%environment,
78 'IP' => 0,
79 'LABEL_INDEX' => \%line_from_label,
80 'current_line' => '',
81 'STACK' => []
82 };
83  
84 # Execute lines in a nonlinear fashion
85 27 ▶ for ( my $instruction_pointer = 0; $instruction_pointer < scalar @$lines; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instruction_pointer < scalar @$lines) 144 27 171
86 144 my $current_instruction = $lines->[$instruction_pointer];
87 144 $context->{'IP'} = $instruction_pointer;
88 144 my $old_ip = $instruction_pointer;
89 144 $self->_handle_instruction( $current_instruction, $context );
90 144 $instruction_pointer = $context->{'IP'};
91 144 ▶ if ( $old_ip == $instruction_pointer ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_ip == $instruction_pointer) 120 24 144
92 120 $instruction_pointer++;
93 }
94 144 $self->_log_line_from_context($context);
95 }
96 27 return $context->{'STDOUT'};
97 } else {
98 0 die "An error ocurred parsing the file";
99 }
100 }
101  
102 sub _handle_instruction {
103 144 ▶ my $self = shift();
Subroutine _handle_instruction: called CC=4 SCAR=13.9
104 144 my $current_instruction = shift();
105 144 my $context = shift();
106  
107 144 my ($type) = keys %$current_instruction;
108  
109 144 ▶ if ( $type eq 'Comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Comment") 4 140 144
110 4 $context->{'current_line'} = ":: " . $current_instruction->{'Comment'}{'Text'};
111 }
112  
113 144 ▶ if ( $type eq 'Label' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Label") 21 123 144
114 21 $context->{'current_line'} = ":" . $current_instruction->{'Label'}{'Identifier'};
115 }
116  
117 144 ▶ if ( $type eq 'Statement' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Statement") 119 25 144
118 119 my $statement = $current_instruction->{'Statement'};
119 119 $self->_handle_statement( $statement, $context );
120 }
121  
122 }
123  
124 sub _handle_statement {
125 149 ▶ my $self = shift();
Subroutine _handle_statement: called CC=2 SCAR=7.0
126 149 my $statement = shift();
127 149 my $context = shift();
128  
129 149 my ($type) = keys %$statement;
130  
131 149 ▶ if ( $type eq 'Command' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Command") 149 0 149
132 149 my $command = $statement->{'Command'};
133 149 $self->_handle_command( $command, $context );
134 }
135  
136 }
137  
138 sub _handle_command {
139 149 ▶ my $self = shift();
Subroutine _handle_command: called CC=7 SCAR=19.7
140 149 my $command = shift();
141 149 my $context = shift();
142  
143 149 ▶ if ( defined $command && $command ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command and $command ne '') { } 149 0 149
Condition33%1/3
defined $command and $command ne ""
!ll&&!rl&&r
00149
MC/DC0%0/2
defined $command and $command ne ""
defined $command $command ne ""
Truth table33%1/3
A and B
A= defined $commandB= $command ne ""
ABresult
0X0
100
111
144 149 my ($type) = keys %$command;
145  
146 149 ▶ if ( $type eq 'SimpleCommand' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "SimpleCommand") 34 115 149
147 34 my $command_line = $command->{'SimpleCommand'};
148 34 $command_line = $self->_variable_substitution( $command_line, $context );
149  
150 # Path adjustment
151 34 $command_line = $self->_adjust_path($command_line);
152  
153 34 $context->{'current_line'} .= $command_line;
154  
155 34 ▶ if ( $command_line =~ /^exit\s+\/b/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command_line =~ m[^exit\s+/b]iu) { } 1 33 34
156 1 my $stack_frame = pop @{ $context->{'STACK'} };
157 1 ▶ if ( defined $stack_frame ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stack_frame) 1 0 1
158 1 $context->{'IP'} = $stack_frame->{'IP'} + 1;
159 }
160 } else {
161 33 $self->_execute_command( $command_line, $context );
162 }
163 }
164 149 ▶ if ( $type eq 'SpecialCommand' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "SpecialCommand") 115 34 149
165 115 my $special_command_line = $command->{'SpecialCommand'};
166 115 $self->_handle_special_command( $special_command_line, $context );
167 }
168 } else {
169  
170 # Empty command
171 0 $context->{'current_line'} .= '';
172 }
173  
174 }
175  
176 sub _handle_special_command {
177 115 ▶ my $self = shift();
Subroutine _handle_special_command: called CC=21 SCAR=30.7
178 115 my $special_command_line = shift();
179 115 my $context = shift();
180  
181 115 my ($type) = keys %$special_command_line;
182  
183 115 ▶ if ( $type eq 'If' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "If") 29 86 115
184 29 $context->{'current_line'} .= 'IF ';
185 29 my $condition;
186 my $statement;
187 29 ▶ if ( exists $special_command_line->{$type}->{'NegatedCondition'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $special_command_line->{$type}{'NegatedCondition'}) { } 5 24 29
188 5 $context->{'current_line'} .= 'NOT ';
189 5 $condition = $special_command_line->{$type}->{'NegatedCondition'}->{'Condition'};
190 5 $statement = $special_command_line->{$type}->{'Statement'};
191 5 ▶ if ( not $self->_handle_condition( $condition, $context ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_handle_condition($condition, $context)) 5 0 5
192 5 $self->_handle_statement( $statement, $context );
193 }
194 } else {
195 24 ( $condition, $statement ) = @{ $special_command_line->{'If'} }{ 'Condition', 'Statement' };
196 24 ▶ if ( $self->_handle_condition( $condition, $context ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_handle_condition($condition, $context)) 18 6 24
197 18 $self->_handle_statement( $statement, $context );
198 }
199 }
200  
201 }
202  
203 115 ▶ if ( $type eq 'Goto' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Goto") 21 94 115
204 21 my $label = $special_command_line->{'Goto'}{'Identifier'};
205 21 $context->{'current_line'} .= 'GOTO ' . $label;
206 21 $self->_goto_label( $label, $context, 0 );
207 }
208  
209 115 ▶ if ( $type eq 'Call' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Call") 5 110 115
210 5 my $token = $special_command_line->{'Call'}{'Token'};
211 5 $token = $self->_variable_substitution( $token, $context );
212 5 $token = $self->_adjust_path($token);
213 5 $context->{'current_line'} .= 'CALL ' . $token;
214 5 ▶ if ( $token =~ /^:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /^:/u) { } 2 3 5
215 2 $self->_goto_label( $token, $context, 1 );
216 } else {
217 3 ( my $first_word ) = $token =~ /\A([^\s]+)/;
218 3 ▶ if ( $first_word =~ /(\.[^.]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_word =~ /(\.[^.]+)$/u) 3 0 3
219 3 ( my $extension ) = $first_word =~ /(\.[^.]+)$/;
220 3 ▶ if ( $extension eq '.exe' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($extension eq '.exe') { } 0 3 3
elsif ($extension eq '.bat' or $extension eq '.cmd') { } 3 0 3
221 0 $self->_execute_command( $token, $context );
222 ▶ } elsif ( $extension eq '.bat' || $extension eq '.cmd' ) {
Condition33%1/3
$extension eq ".bat" or $extension eq ".cmd"
l!l&&r!l&&!r
030
MC/DC0%0/2
$extension eq ".bat" or $extension eq ".cmd"
$extension eq ".bat" $extension eq ".cmd"
Truth table33%1/3
A or B
A= $extension eq ".bat"B= $extension eq ".cmd"
ABresult
1X1
011
000
223 3 $self->_log_line_from_context($context);
224 3 my $stdout = $self->run( $token, $context->{ENV} );
225 3 ▶ if ( !defined $context->{STDOUT} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context->{"STDOUT"}) 3 0 3
226 3 $context->{STDOUT} = [];
227 }
228 3 ▶ if ( defined $stdout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdout) 0 3 3
229 0 push @{ $context->{STDOUT} }, @$stdout;
230 }
231 }
232 }
233 }
234 }
235  
236 115 ▶ if ( $type eq 'Set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Set") 24 91 115
237 24 my ( $variable, $value ) = @{ $special_command_line->{'Set'} }{ 'Variable', 'Value' };
238 24 $value = $self->_variable_substitution( $value, $context );
239 24 $value = $self->_adjust_path($value);
240 24 $context->{'current_line'} .= 'SET ' . $variable . '=' . $value;
241 24 $context->{ENV}{$variable} = $value;
242 }
243  
244 115 ▶ if ( $type eq 'For' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "For") 3 112 115
245 3 $context->{'current_line'} .= 'FOR ';
246 3 my $token = $special_command_line->{'For'}{'Token'};
247  
248 # Handle only simple cases
249 3 ▶ if ( $token =~ /\s*?\/F\s*?"delims="\s*%%(?<variable_bucle>[A-Z0-9]+?)\s*?in\s*?\('(?<comando>.+)'\)/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token =~ m[\s*?/F\s*?"delims="\s*%%(?<variable_bucle>[A-Z0-9]+?)\s*?in\s*?\('(?<comando>.+)'\)]iu) { } 1 2 3
elsif ($token =~ /\s*?%%(?<variable_bucle>[A-Z0-9]+?)\s*?in\s*?(\([\d]+(?:,[^,\s]+)+\))/iu) { } 2 0 2
250 1 my $comando = $+{'comando'};
251 1 my $parameter_name = $+{'variable_bucle'};
252 1 $comando = $self->_variable_substitution( $comando, $context );
253 1 $comando = $self->_adjust_path($comando);
254 1 $comando =~ s/%%/%/g;
255  
256 1 $context->{'current_line'} .= '/F "delims="' . $parameter_name . ' in ' . "'$comando' ";
257 1 my $salida = $self->_for_command_evaluation($comando);
258  
259 1 my $statement = $special_command_line->{'For'}{'Statement'};
260  
261 1 $context->{'PARAMETERS'}{$parameter_name} = $salida;
262  
263 1 $self->_handle_statement( $statement, $context );
264 1 delete $context->{'PARAMETERS'}{$parameter_name};
265 } elsif ( $token =~ /\s*?%%(?<variable_bucle>[A-Z0-9]+?)\s*?in\s*?(\([\d]+(?:,[^,\s]+)+\))/i ) {
266 2 my $statement = $special_command_line->{'For'}{'Statement'};
267 2 my $parameter_name = $+{'variable_bucle'};
268 2 my $value_list = $2;
269 2 $value_list =~ s/(\(|\))//g;
270 2 my @values = split( /,/, $value_list );
271 2 $context->{'current_line'} .= $token . ' do ';
272 2 for my $value (@values) {
273 6 $context->{'PARAMETERS'}->{$parameter_name} = $value;
274 6 $context->{'current_line'} .= "\n\t";
275 6 $self->_handle_statement( $statement, $context );
276 6 delete $context->{'PARAMETERS'}{$parameter_name};
277 }
278  
279 } else {
280 0 Carp::confess('FOR functionality not implemented!');
281 }
282 }
283  
284 115 ▶ if ( $type eq 'Echo' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Echo") 33 82 115
285 33 $context->{'current_line'} .= 'ECHO ';
286 33 my $echo = $special_command_line->{'Echo'};
287 33 ▶ if ( exists $echo->{'EchoModifier'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $echo->{'EchoModifier'}) { } 27 6 33
288 27 $context->{'current_line'} .= $echo->{'EchoModifier'};
289 } else {
290 6 my $message = $echo->{'Message'};
291 6 $message = $self->_variable_substitution( $message, $context );
292 6 $context->{'current_line'} .= $message;
293 }
294 }
295 }
296  
297 sub _handle_condition {
298 29 ▶ my $self = shift();
Subroutine _handle_condition: called CC=13 SCAR=25.8
299 29 my $condition = shift();
300 29 my $context = shift();
301  
302 29 my ($type) = keys %$condition;
303 29 ▶ if ( $type eq 'Comparison' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'Comparison') { } 21 8 29
elsif ($type eq 'Exists') { } 8 0 8
304 my ( $left_operand, $operator, $right_operand ) =
305 21 @{ $condition->{'Comparison'} }{qw(LeftOperand Operator RightOperand)};
306  
307 21 $left_operand = $self->_variable_substitution( $left_operand, $context );
308 21 $right_operand = $self->_variable_substitution( $right_operand, $context );
309  
310 21 $context->{'current_line'} .= $left_operand . ' ' . $operator . ' ' . $right_operand . ' ';
311  
312 21 my $uppercase_operator = uc($operator);
313 21 ▶ if ( $operator eq '==' || $uppercase_operator eq 'EQU' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($operator eq '==' or $uppercase_operator eq 'EQU') { } 7 14 21
elsif ($uppercase_operator eq 'NEQ') { } 2 12 14
elsif ($uppercase_operator eq 'LSS') { } 1 11 12
elsif ($uppercase_operator eq 'LEQ') { } 2 9 11
elsif ($uppercase_operator eq 'GTR') { } 2 7 9
elsif ($uppercase_operator eq 'GEQ') { } 7 0 7
Condition100%3/3
$operator eq "==" or $uppercase_operator eq "EQU"
l!l&&r!l&&!r
4314
MC/DC100%2/2
$operator eq "==" or $uppercase_operator eq "EQU"
$operator eq "==" $uppercase_operator eq "EQU"
Truth table100%3/3
A or B
A= $operator eq "=="B= $uppercase_operator eq "EQU"
ABresult
1X1
011
000
314 7 my $a = $left_operand =~ s/\s*(.*)\s*/$1/r;
315 7 my $b = $right_operand =~ s/\s*(.*)\s*/$1/r;
316 7 return $a eq $b;
317 } elsif ( $uppercase_operator eq 'NEQ' ) {
318 2 return $left_operand != $right_operand;
319 } elsif ( $uppercase_operator eq 'LSS' ) {
320 1 return $left_operand < $right_operand;
321 } elsif ( $uppercase_operator eq 'LEQ' ) {
322 2 return $left_operand <= $right_operand;
323 } elsif ( $uppercase_operator eq 'GTR' ) {
324 2 return $left_operand > $right_operand;
325 } elsif ( $uppercase_operator eq 'GEQ' ) {
326 7 return $left_operand >= $right_operand;
327  
328 } else {
329 0 die "Operator: $operator not implemented";
330 }
331 } elsif ( $type eq 'Exists' ) {
332 8 my $path = ${ $condition->{'Exists'} }{'Path'};
333 8 $path = $self->_variable_substitution( $path, $context );
334 8 $path = $self->_adjust_path($path);
335 8 $context->{'current_line'} .= 'EXIST ' . $path;
336  
337 # Glob expansion
338 8 my @paths = File::Glob::bsd_glob($path);
339 8 my $file_exists = 1;
340 8 ▶ if (@paths) {
Branch: 1 branch
BranchTrueFalseTotal
if (@paths) { } 6 2 8
341 6 for my $expanded_path (@paths) {
342 7 ▶ $file_exists = $file_exists && -e $expanded_path;
Condition66%2/3
$file_exists && -e $expanded_path
!ll&&!rl&&r
025
MC/DC50%1/2
$file_exists && -e $expanded_path
$file_exists -e $expanded_path
Truth table66%2/3
A && B
A= $file_existsB= -e $expanded_path
ABresult
0X0
100
111
343 }
344 6 return $file_exists;
345 } else {
346 2 return 0; # If bsd_glob returns and empty array there is no such file
347 }
348 } else {
349 0 die "Condition type $type not implemented";
350 }
351 0 return 0;
352 }
353  
354 sub _variable_substitution {
355 120 ▶ my $self = shift();
Subroutine _variable_substitution: called CC=4 SCAR=14.2
356 120 my $string = shift();
357 120 my $context = shift();
358  
359 120 ▶ if ( !defined $context ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context) 0 120 120
360 0 Carp::cluck "Please provide a context for variable substitution";
361 }
362  
363 120 my $parameters = $context->{'PARAMETERS'};
364 120 ▶ if ( defined $parameters && scalar keys %$parameters > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameters and scalar keys %$parameters > 0) 14 106 120
Condition100%3/3
defined $parameters and scalar keys %$parameters > 0
!ll&&!rl&&r
961014
MC/DC100%2/2
defined $parameters and scalar keys %$parameters > 0
defined $parameters scalar keys %$parameters > 0
Truth table100%3/3
A and B
A= defined $parametersB= scalar keys %$parameters > 0
ABresult
0X0
100
111
365  
366 my $handle_parameter_sustitution = sub {
367 7 ▶ my $parameter_name = shift();
Subroutine __ANON__: called CC=2 SCAR=8.4
368 7 ▶ if ( exists $parameters->{$parameter_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parameters->{$parameter_name}) { } 7 0 7
369 7 return $parameters->{$parameter_name};
370 } else {
371 0 Carp::cluck "Parameter not defined: $parameter_name";
372 0 return '';
373 }
374 14 };
375 14 $string =~ s/%%([A-Za-z])/$handle_parameter_sustitution->($1)/eg;
376 }
377  
378 my $handle_variable_manipulations = sub {
379 41 ▶ my $variable_name = shift();
Subroutine __ANON__: called CC=9 SCAR=23.0
380 41 my $manipulation = shift();
381  
382 41 ▶ if ( defined $variable_name && $variable_name ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $variable_name and $variable_name ne '') { } 29 12 41
Condition66%2/3
defined $variable_name and $variable_name ne ""
!ll&&!rl&&r
01229
MC/DC50%1/2
defined $variable_name and $variable_name ne ""
defined $variable_name $variable_name ne ""
Truth table66%2/3
A and B
A= defined $variable_nameB= $variable_name ne ""
ABresult
0X0
100
111
383  
384 29 my $result = $context->{'ENV'}{$1};
385 29 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) { } 29 0 29
386 29 ▶ if ( defined $manipulation && $manipulation ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $manipulation and $manipulation ne "") 5 24 29
Condition66%2/3
defined $manipulation and $manipulation ne ""
!ll&&!rl&&r
2405
MC/DC50%1/2
defined $manipulation and $manipulation ne ""
defined $manipulation $manipulation ne ""
Truth table66%2/3
A and B
A= defined $manipulationB= $manipulation ne ""
ABresult
0X0
100
111
387 5 $manipulation =~ s/^://;
388 5 ▶ if ( $manipulation =~ /^~(?<from>\d+),(?<length>\d+)$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($manipulation =~ /^~(?<from>\d+),(?<length>\d+)$/u) { } 2 3 5
elsif ($manipulation =~ /^~(?<from_end>-\d+),(?<length>\d+)$/u) { } 1 2 3
elsif ($manipulation =~ /^\~(\-\d)+$/u) { } 2 0 2
389 2 $result = substr( $result, $+{'from'}, $+{'length'} );
390 } elsif ( $manipulation =~ /^~(?<from_end>-\d+),(?<length>\d+)$/ ) {
391 1 $result = substr( $result, $+{'from_end'}, $+{'length'} );
392 } elsif ( $manipulation =~ /^\~(\-\d)+$/ ) {
393 2 $result = substr( $result, $1 );
394 } else {
395 0 Carp::cluck
396 "Variable manipulation not understood: $manipulation over variable: $variable_name. Returning unchanged variable: $result";
397 0 return $result;
398 }
399 }
400 29 return $result;
401 } else {
402 0 Carp::cluck("Variable: $variable_name not defined");
403 }
404 0 return '';
405 } else {
406 12 return '%%';
407 }
408 120 };
409  
410 120 $string =~ s/%([\w\#\$\'\(\)\*\+\,\-\.\?\@\[\]\`\{\}\~]*?)(:.+?)?%/$handle_variable_manipulations->($1, $2)/eg;
411  
412 120 $string =~ s/%%/%/g;
413  
414 120 return $string;
415 }
416  
417 sub _adjust_path {
418 72 ▶ my $self = shift();
Subroutine _adjust_path: called CC=2 SCAR=7.0
419 72 my $path = shift();
420 72 ▶ if ( !( $^O =~ 'Win' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O =~ /Win/u) 72 0 72
421 72 $path =~ s/\\/\//g;
422 }
423 72 return $path;
424 }
425  
426 sub _execute_command {
427 33 ▶ my $self = shift();
Subroutine _execute_command: called CC=1 SCAR=0.0
428 33 $self->executor->execute_command(@_);
429 }
430  
431 sub _goto_label {
432 23 ▶ my $self = shift();
Subroutine _goto_label: called CC=5 SCAR=16.1
433 23 my $label = shift();
434 23 my $context = shift();
435 23 my $call = shift();
436 23 $label =~ s/^://;
437 23 $label =~ s/ //g;
438 23 ▶ if ( $context->{'LABEL_INDEX'}{$label} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'LABEL_INDEX'}{$label}) { } 23 0 23
439 23 ▶ if ( $label =~ /eof/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label =~ /eof/iu) { } 4 19 23
440 4 my $stack_frame = pop @{ $context->{'STACK'} };
441 4 ▶ if ( defined $stack_frame ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stack_frame) { } 1 3 4
442 1 $context->{'IP'} = $stack_frame->{'IP'} + 1;
443 } else {
444 3 $context->{'IP'} = $context->{'LABEL_INDEX'}{$label};
445 }
446 } else {
447 19 ▶ if ($call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call) 2 17 19
448 2 push @{ $context->{'STACK'} }, { IP => $context->{'IP'} };
449 }
450 19 $context->{'IP'} = $context->{'LABEL_INDEX'}{$label};
451 }
452 } else {
453 0 die "Label: $label not indexed. Index contains: " . Dumper( $context->{'LABEL_INDEX'} );
454 }
455 }
456  
457 sub _for_command_evaluation {
458 1 ▶ my $self = shift();
Subroutine _for_command_evaluation: called CC=1 SCAR=0.0
459 1 my $comando = shift();
460 1 return $self->executor->execute_for_command($comando);
461 }
462  
463 sub _log_line_from_context {
464 147 ▶ my $self = shift();
Subroutine _log_line_from_context: called CC=3 SCAR=11.0
465 147 my $context = shift();
466 147 my $line = $context->{'current_line'};
467 147 ▶ if ( defined $line && $line ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line and $line ne "") 144 3 147
Condition66%2/3
defined $line and $line ne ""
!ll&&!rl&&r
03144
MC/DC50%1/2
defined $line and $line ne ""
defined $line $line ne ""
Truth table66%2/3
A and B
A= defined $lineB= $line ne ""
ABresult
0X0
100
111
468 144 $self->linelogger->log_line( $context->{'current_line'} );
469 }
470 147 $context->{'current_line'} = '';
471 }
472  
473 25 1;
474  
475 __END__
↑ Summary Build »