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