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