| 1 | # -*-cperl-*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # This module is copyrighted as per the usual perl legalese: | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 1997 Austin Schutz. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # expect() interface & functionality enhancements (c) 1999 Roland Giersig. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # All rights reserved. This program is free software; you can | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # redistribute it and/or modify it under the same terms as Perl | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # itself. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Don't blame/flame me if you bust your stuff. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # Austin Schutz <ASchutz@users.sourceforge.net> | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # This module now is maintained by | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # Dave Jacoby <jacoby@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | package Expect; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | ▶ | use IO::Pty 1.11; # We need make_slave_controlling_terminal() | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 23 | ▶ | use IO::Tty; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 23 | ▶ | use POSIX qw(:sys_wait_h :unistd_h); # For WNOHANG and isatty | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 23 | ▶ | use Fcntl qw(:DEFAULT); # For checking file handle settings. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 23 | ▶ | use Carp qw(cluck croak carp confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 23 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 23 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 23 | ▶ | use Errno; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # This is necessary to make routines within Expect work. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 23 | @Expect::ISA = qw(IO::Pty); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 23 | @Expect::EXPORT = qw(expect exp_continue exp_continue_timeout); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 23 | ▶ | $Expect::VERSION = '1.35'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # These are defaults which may be changed per object, or set as | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # the user wishes. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # This will be unset, since the default behavior differs between | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # spawned processes and initialized filehandles. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # $Expect::Log_Stdout = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 23 | $Expect::Log_Group = 1; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 23 | $Expect::Debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | $Expect::Exp_Max_Accum = 0; # unlimited | |||||||||||||||||||||||||||||||||||||||||
| 49 | 23 | $Expect::Exp_Internal = 0; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 23 | $Expect::IgnoreEintr = 0; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | $Expect::Manual_Stty = 0; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 23 | $Expect::Multiline_Matching = 1; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 23 | $Expect::Do_Soft_Close = 0; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 23 | @Expect::Before_List = (); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 23 | @Expect::After_List = (); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 23 | %Expect::Spawned_PIDs = (); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub version { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ($version) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | warn "Version $version is later than $Expect::VERSION. It may not be supported" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $version and $version > $Expect::VERSION
MC/DC0%0/2
defined $version and $version > $Expect::VERSION
defined $version
$version > $Expect::VERSION
Truth table0%0/3
A and B
A= defined $versionB= $version > $Expect::VERSION
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | if ( defined($version) && ( $version > $Expect::VERSION ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | die "Versions before 1.03 are not supported in this release" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $version and $version < "1.03"
MC/DC0%0/2
defined $version and $version < "1.03"
defined $version
$version < "1.03"
Truth table0%0/3
A and B
A= defined $versionB= $version < "1.03"
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | if ( ( defined($version) ) && ( $version < 1.03 ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return $Expect::VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 126 | ▶ | my ($class, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 126 | ▶ | $class = ref($class) if ref($class); # so we can be called as $exp->new() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Create the pty which we will use to pass process info. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 126 | my ($self) = IO::Pty->new; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 126 | ▶ | die "$class: Could not assign a pty" unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 126 | bless $self => $class; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 126 | $self->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # This is defined here since the default is different for | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # initialized handles as opposed to spawned processes. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 126 | ${*$self}{exp_Log_Stdout} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 126 | $self->_init_vars(); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 126 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # we got add'l parms, so pass them to spawn | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 64 | return $self->spawn(@args); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 62 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | sub spawn { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 126 | ▶ | my ($class, @cmd) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=21 SCAR=32.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | # spawn is passed command line args. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 126 | my $self; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 126 | ▶ | if ( ref($class) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 111 | $self = $class; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 15 | $self = $class->new(); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | croak "Cannot reuse an object with an already spawned command" | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 126 | ▶ | if exists ${*$self}{"exp_Command"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 125 | ${*$self}{"exp_Command"} = \@cmd; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # set up pipe to detect childs exec error | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 125 | ▶ | pipe( FROM_CHILD, TO_PARENT ) or die "Cannot open pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 125 | ▶ | pipe( FROM_PARENT, TO_CHILD ) or die "Cannot open pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 125 | TO_PARENT->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 125 | TO_CHILD->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 125 | eval { fcntl( TO_PARENT, Fcntl::F_SETFD, Fcntl::FD_CLOEXEC ); }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 125 | my $pid = fork; | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 125 | ▶ | unless ( defined($pid) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | warn "Cannot fork: $!" if $^W; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 125 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # parent | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 108 | my $errno; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 108 | ${*$self}{exp_Pid} = $pid; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 108 | close TO_PARENT; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 108 | close FROM_PARENT; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 108 | $self->close_slave(); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 108 | ▶ | $self->set_raw() if $self->raw_pty and isatty($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->raw_pty and isatty($self)
MC/DC50%1/2
$self->raw_pty and isatty($self)
$self->raw_pty
isatty($self)
Truth table66%2/3
A and B
A= $self->raw_ptyB= isatty($self)
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 108 | close TO_CHILD; # so child gets EOF and can go ahead | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # now wait for child exec (eof due to close-on-exit) or exec error | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 108 | my $errstatus = sysread( FROM_CHILD, $errno, 256 ); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 108 | ▶ | die "Cannot sync with child: $!" if not defined $errstatus; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 108 | close FROM_CHILD; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 108 | ▶ | if ($errstatus) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 13 | $! = $errno + 0; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 13 | ▶ | warn "Cannot exec(@cmd): $!\n" if $^W; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | # child | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 17 | close FROM_CHILD; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | close TO_CHILD; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 17 | $self->make_slave_controlling_terminal(); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 17 | ▶ | my $slv = $self->slave() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | or die "Cannot get slave: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 17 | ▶ | $slv->set_raw() if $self->raw_pty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 17 | close($self); | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # wait for parent before we detach | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 17 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 17 | my $errstatus = sysread( FROM_PARENT, $buffer, 256 ); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | ▶ | die "Cannot sync with parent: $!" if not defined $errstatus; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 17 | close FROM_PARENT; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 17 | close(STDIN); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | ▶ | open( STDIN, "<&" . $slv->fileno() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | or die "Couldn't reopen STDIN for reading, $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 17 | close(STDOUT); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 17 | ▶ | open( STDOUT, ">&" . $slv->fileno() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | or die "Couldn't reopen STDOUT for writing, $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 17 | close(STDERR); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 17 | ▶ | open( STDERR, ">&" . $slv->fileno() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | or die "Couldn't reopen STDERR for writing, $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 17 | { exec(@cmd) }; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | print TO_PARENT $! + 0; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | die "Cannot exec(@cmd): $!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # This is sort of for code compatibility, and to make debugging a little | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # easier. By code compatibility I mean that previously the process's | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # handle was referenced by $process{Pty_Handle} instead of just $process. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # This is almost like 'naming' the handle to the process. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # I think this also reflects Tcl Expect-like behavior. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 95 | ${*$self}{exp_Pty_Handle} = "spawn id(" . $self->fileno() . ")"; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 95 | ▶ | if ( ( ${*$self}{"exp_Debug"} ) or ( ${*$self}{"exp_Exp_Internal"} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
do {
*$self
}->{"exp_Debug"} or do {
*$self
}->{"exp_Exp_Internal"}
MC/DC0%0/2
do {
*$self
}->{"exp_Debug"} or do {
*$self
}->{"exp_Exp_Internal"}
do {
*$self
}->{"exp_Debug"}
do {
*$self
}->{"exp_Exp_Internal"}
Truth table33%1/3
A or B
A= do {
*$self
}->{"exp_Debug"}B= do {
*$self
}->{"exp_Exp_Internal"}
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | cluck( | |||||||||||||||||||||||||||||||||||||||||
| 186 | "Spawned '@cmd'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | "\t${*$self}{exp_Pty_Handle}\r\n", | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | "\tPid: ${*$self}{exp_Pid}\r\n", | |||||||||||||||||||||||||||||||||||||||||
| 189 | "\tTty: " . $self->SUPER::ttyname() . "\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 95 | $Expect::Spawned_PIDs{ ${*$self}{exp_Pid} } = undef; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 95 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | sub exp_init { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my ($class, $self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_init: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | # take a filehandle, for use later with expect() or interconnect() . | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # All the functions are written for reading from a tty, so if the naming | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # scheme looks odd, that's why. | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | croak "exp_init not passed a file object, stopped" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | unless defined( $self->fileno() ); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $self->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | # Define standard variables.. debug states, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $self->_init_vars(); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # Turn of logging. By default we don't want crap from a file to get spewed | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # on screen as we read it. | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ${*$self}{exp_Log_Stdout} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ${*$self}{exp_Pty_Handle} = "handle id(" . $self->fileno() . ")"; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | ${*$self}{exp_Pty_Handle} = "STDIN" if $self->fileno() == fileno(STDIN); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | print STDERR "Initialized ${*$self}{exp_Pty_Handle}.'\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ${*$self}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | # make an alias | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 23 | *init = \&exp_init; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # We're happy OOP people. No direct access to stuff. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # For standard read-writeable parameters, we define some autoload magic... | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 23 | my %Writeable_Vars = ( | |||||||||||||||||||||||||||||||||||||||||
| 227 | debug => 'exp_Debug', | ||||||||||||||||||||||||||||||||||||||||||
| 228 | exp_internal => 'exp_Exp_Internal', | ||||||||||||||||||||||||||||||||||||||||||
| 229 | do_soft_close => 'exp_Do_Soft_Close', | ||||||||||||||||||||||||||||||||||||||||||
| 230 | max_accum => 'exp_Max_Accum', | ||||||||||||||||||||||||||||||||||||||||||
| 231 | match_max => 'exp_Max_Accum', | ||||||||||||||||||||||||||||||||||||||||||
| 232 | notransfer => 'exp_NoTransfer', | ||||||||||||||||||||||||||||||||||||||||||
| 233 | log_stdout => 'exp_Log_Stdout', | ||||||||||||||||||||||||||||||||||||||||||
| 234 | log_user => 'exp_Log_Stdout', | ||||||||||||||||||||||||||||||||||||||||||
| 235 | log_group => 'exp_Log_Group', | ||||||||||||||||||||||||||||||||||||||||||
| 236 | manual_stty => 'exp_Manual_Stty', | ||||||||||||||||||||||||||||||||||||||||||
| 237 | restart_timeout_upon_receive => 'exp_Continue', | ||||||||||||||||||||||||||||||||||||||||||
| 238 | raw_pty => 'exp_Raw_Pty', | ||||||||||||||||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 23 | my %Readable_Vars = ( | |||||||||||||||||||||||||||||||||||||||||
| 241 | pid => 'exp_Pid', | ||||||||||||||||||||||||||||||||||||||||||
| 242 | exp_pid => 'exp_Pid', | ||||||||||||||||||||||||||||||||||||||||||
| 243 | exp_match_number => 'exp_Match_Number', | ||||||||||||||||||||||||||||||||||||||||||
| 244 | match_number => 'exp_Match_Number', | ||||||||||||||||||||||||||||||||||||||||||
| 245 | exp_error => 'exp_Error', | ||||||||||||||||||||||||||||||||||||||||||
| 246 | error => 'exp_Error', | ||||||||||||||||||||||||||||||||||||||||||
| 247 | exp_command => 'exp_Command', | ||||||||||||||||||||||||||||||||||||||||||
| 248 | command => 'exp_Command', | ||||||||||||||||||||||||||||||||||||||||||
| 249 | exp_match => 'exp_Match', | ||||||||||||||||||||||||||||||||||||||||||
| 250 | match => 'exp_Match', | ||||||||||||||||||||||||||||||||||||||||||
| 251 | exp_matchlist => 'exp_Matchlist', | ||||||||||||||||||||||||||||||||||||||||||
| 252 | matchlist => 'exp_Matchlist', | ||||||||||||||||||||||||||||||||||||||||||
| 253 | exp_before => 'exp_Before', | ||||||||||||||||||||||||||||||||||||||||||
| 254 | before => 'exp_Before', | ||||||||||||||||||||||||||||||||||||||||||
| 255 | exp_after => 'exp_After', | ||||||||||||||||||||||||||||||||||||||||||
| 256 | after => 'exp_After', | ||||||||||||||||||||||||||||||||||||||||||
| 257 | exp_exitstatus => 'exp_Exit', | ||||||||||||||||||||||||||||||||||||||||||
| 258 | exitstatus => 'exp_Exit', | ||||||||||||||||||||||||||||||||||||||||||
| 259 | exp_pty_handle => 'exp_Pty_Handle', | ||||||||||||||||||||||||||||||||||||||||||
| 260 | pty_handle => 'exp_Pty_Handle', | ||||||||||||||||||||||||||||||||||||||||||
| 261 | exp_logfile => 'exp_Log_File', | ||||||||||||||||||||||||||||||||||||||||||
| 262 | logfile => 'exp_Log_File', | ||||||||||||||||||||||||||||||||||||||||||
| 263 | %Writeable_Vars, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 323 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=13 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 323 | ▶ | my $type = ref($self) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | or croak "$self is not an object"; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 23 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 323 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 323 | $name =~ s/.*:://; # strip fully-qualified portion | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 323 | ▶ | unless ( exists $Readable_Vars{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | croak "ERROR: cannot find method `$name' in class $type"; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 323 | my $varname = $Readable_Vars{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 323 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 323 | ▶ | $tmp = ${*$self}{$varname} if exists ${*$self}{$varname}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 323 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 76 | ▶ | if ( exists $Writeable_Vars{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 76 | my $ref = ref($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 76 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ${*$self}{$varname} = [@args]; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } elsif ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ${*$self}{$varname} = {@args}; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 76 | ${*$self}{$varname} = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | carp "Trying to set read-only variable `$name'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | if $^W; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 323 | my $ref = ref($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 323 | ▶ | return ( wantarray ? @{$tmp} : $tmp ) if ( $ref eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 317 | ▶ | return ( wantarray ? %{$tmp} : $tmp ) if ( $ref eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 317 | return $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | sub set_seq { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | my ( $self, $escape_sequence, $function, $params, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_seq: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # Set an escape sequence/function combo for a read handle for interconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # Ex: $read_handle->set_seq('',\&function,\@parameters); | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ${ ${*$self}{exp_Function} }{$escape_sequence} = $function; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( ( !defined($function) ) || ( $function eq 'undef' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $function or $function eq "undef"
MC/DC0%0/2
not defined $function or $function eq "undef"
not defined $function
$function eq "undef"
Truth table0%0/3
not(A) or B
A= not defined $functionB= $function eq "undef"
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ${ ${*$self}{exp_Function} }{$escape_sequence} = \&_undef; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ${ ${*$self}{exp_Parameters} }{$escape_sequence} = $params; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # This'll be a joy to execute. :) | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if ( ${*$self}{"exp_Debug"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | print STDERR "Escape seq. '" . $escape_sequence; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | print STDERR "' function for ${*$self}{exp_Pty_Handle} set to '"; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | print STDERR ${ ${*$self}{exp_Function} }{$escape_sequence}; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | print STDERR "(" . join( ',', @args ) . ")'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | sub set_group { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_group: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | # Make sure we can read from the read handle | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( !defined( $args[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ( defined( ${*$self}{exp_Listen_Group} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return @{ ${*$self}{exp_Listen_Group} }; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | # Refrain from referencing an undef | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | @{ ${*$self}{exp_Listen_Group} } = (); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ( $self->_get_mode() !~ 'r' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | warn( | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | "Attempting to set a handle group on ${*$self}{exp_Pty_Handle}, ", | |||||||||||||||||||||||||||||||||||||||||
| 344 | "a non-readable handle!\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 345 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | while ( my $write_handle = shift @args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $write_handle->_get_mode() !~ 'w' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | warn( | |||||||||||||||||||||||||||||||||||||||||
| 350 | "Attempting to set a non-writeable listen handle ", | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | "${*$write_handle}{exp_Pty_handle} for ", | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | "${*$self}{exp_Pty_Handle}!\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 353 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | push( @{ ${*$self}{exp_Listen_Group} }, $write_handle ); | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | sub log_file { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 65 | ▶ | my ($self, $file, $mode) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_file: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 65 | ▶ | $mode ||= "a"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mode ||= "a"
MC/DC100%1/1
$mode ||= "a"
$mode
Truth table100%2/2
A
A= $mode
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return ( ${*$self}{exp_Log_File} ) | |||||||||||||||||||||||||||||||||||||||||
| 364 | 65 | ▶ | if @_ < 2; # we got no param, return filehandle | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | # $e->log_file(undef) is an acceptable call hence we need to check the number of parameters here | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 65 | ▶ | if ( ${*$self}{exp_Log_File} and ref( ${*$self}{exp_Log_File} ) ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
do {
*$self
}->{"exp_Log_File"} and ref do {
*$self
}->{"exp_Log_File"} ne "CODE"
MC/DC100%2/2
do {
*$self
}->{"exp_Log_File"} and ref do {
*$self
}->{"exp_Log_File"} ne "CODE"
do {
*$self
}->{"exp_Log_File"}
ref do {
*$self
}->{"exp_Log_File"} ne "CODE"
Truth table100%3/3
A and B
A= do {
*$self
}->{"exp_Log_File"}B= ref do {
*$self
}->{"exp_Log_File"} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 9 | close( ${*$self}{exp_Log_File} ); | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 65 | ${*$self}{exp_Log_File} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 65 | ▶ | return if ( not $file ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 39 | my $fh = $file; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 39 | ▶ | if ( not ref($file) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | # it's a filename | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 23 | ▶ | $fh = IO::File->new( $file, $mode ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | or croak "Cannot open logfile $file: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 39 | ▶ | if ( ref($file) ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 23 | ▶ | croak "Given logfile doesn't have a 'print' method" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | if not $fh->can("print"); | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 23 | $fh->autoflush(1); # so logfile is up to date | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 39 | ${*$self}{exp_Log_File} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 39 | return $fh; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | # I'm going to leave this here in case I might need to change something. | ||||||||||||||||||||||||||||||||||||||||||
| 391 | # Previously this was calling `stty`, in a most bastardized manner. | ||||||||||||||||||||||||||||||||||||||||||
| 392 | sub exp_stty { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | my ($self) = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_stty: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my ($mode) = "@_"; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | return unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ( not defined $INC{"IO/Stty.pm"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | carp "IO::Stty not installed, cannot change mode"; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if ( ${*$self}{"exp_Debug"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | print STDERR "Setting ${*$self}{exp_Pty_Handle} to tty mode '$mode'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | unless ( POSIX::isatty($self) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if ( ${*$self}{"exp_Debug"} or $^W ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
do {
*$self
}->{"exp_Debug"} or $^W
MC/DC0%0/2
do {
*$self
}->{"exp_Debug"} or $^W
do {
*$self
}->{"exp_Debug"}
$^W
Truth table0%0/3
A or B
A= do {
*$self
}->{"exp_Debug"}B= $^W
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | warn "${*$self}{exp_Pty_Handle} is not a tty. Not changing mode"; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | return ''; # No undef to avoid warnings elsewhere. | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | IO::Stty::stty( $self, split( /\s/, $mode ) ); | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 23 | *stty = \&exp_stty; | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | # If we want to clear the buffer. Otherwise Accum will grow during send_slow | ||||||||||||||||||||||||||||||||||||||||||
| 417 | # etc. and contain the remainder after matches. | ||||||||||||||||||||||||||||||||||||||||||
| 418 | sub clear_accum { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 39 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_accum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 39 | return $self->set_accum(''); | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | sub set_accum { | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 57 | ▶ | my ($self, $accum) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_accum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 57 | my $old_accum = ${*$self}{exp_Accum}; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 57 | ${*$self}{exp_Accum} = $accum; | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | # return the contents of the accumulator. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 57 | return $old_accum; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | sub get_accum { | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_accum: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 1 | return ${*$self}{exp_Accum}; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 438 | # define constants for pattern subs | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 9832 | ▶ | sub exp_continue {"exp_continue"} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_continue: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 4771 | ▶ | sub exp_continue_timeout {"exp_continue_timeout"} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_continue_timeout: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 443 | # Expect on multiple objects at once. | ||||||||||||||||||||||||||||||||||||||||||
| 444 | # | ||||||||||||||||||||||||||||||||||||||||||
| 445 | # Call as Expect::expect($timeout, -i => \@exp_list, @patternlist, | ||||||||||||||||||||||||||||||||||||||||||
| 446 | # -i => $exp, @pattern_list, ...); | ||||||||||||||||||||||||||||||||||||||||||
| 447 | # or $exp->expect($timeout, @patternlist, -i => \@exp_list, @patternlist, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | # -i => $exp, @pattern_list, ...); | ||||||||||||||||||||||||||||||||||||||||||
| 449 | # | ||||||||||||||||||||||||||||||||||||||||||
| 450 | # Patterns are arrays that consist of | ||||||||||||||||||||||||||||||||||||||||||
| 451 | # [ $pattern_type, $pattern, $sub, @subparms ] | ||||||||||||||||||||||||||||||||||||||||||
| 452 | # | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # Optional $pattern_type is '-re' (RegExp, default) or '-ex' (exact); | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # | ||||||||||||||||||||||||||||||||||||||||||
| 455 | # $sub is optional CODE ref, which is called as &{$sub}($exp, @subparms) | ||||||||||||||||||||||||||||||||||||||||||
| 456 | # if pattern matched; may return exp_continue or exp_continue_timeout. | ||||||||||||||||||||||||||||||||||||||||||
| 457 | # | ||||||||||||||||||||||||||||||||||||||||||
| 458 | # Old-style syntax (pure pattern strings with optional type) also supported. | ||||||||||||||||||||||||||||||||||||||||||
| 459 | # | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | sub expect { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 4811 | ▶ | my $self; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expect: called CC=44 SCAR=55.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 4811 | ▶ | print STDERR ("expect(@_) called...\n") if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 4811 | ▶ | if ( defined( $_[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 4811 | ▶ | if ( ref( $_[0] ) and $_[0]->isa('Expect') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $_[0] and $_[0]->isa("Expect")
MC/DC0%0/2
ref $_[0] and $_[0]->isa("Expect")
ref $_[0]
$_[0]->isa("Expect")
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->isa("Expect")
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 4811 | $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } elsif ( $_[0] eq 'Expect' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | shift; # or as Expect->expect | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 4811 | ▶ | croak "expect(): not enough arguments, should be expect(timeout, [patterns...])" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 4811 | my $timeout = shift; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 4811 | my $timeout_hook = undef; | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 4811 | my @object_list; | |||||||||||||||||||||||||||||||||||||||||
| 478 | my %patterns; | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 4811 | my @pattern_list; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 4811 | my @timeout_list; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 4811 | my $curr_list; | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 4811 | ▶ | if ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 4811 | $curr_list = [$self]; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | # called directly, so first parameter must be '-i' to establish | ||||||||||||||||||||||||||||||||||||||||||
| 489 | # object list. | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $curr_list = []; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | croak | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | "expect(): ERROR: if called directly (not as \$obj->expect(...), but as Expect::expect(...), first parameter MUST be '-i' to set an object (list) for the patterns to work on." | ||||||||||||||||||||||||||||||||||||||||||
| 493 | if ( $_[0] ne '-i' ); | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | # Let's make a list of patterns wanting to be evaled as regexps. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 4811 | my $parm; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 4811 | my $parm_nr = 1; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 4811 | ▶ | while ( defined( $parm = shift ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 14323 | ▶ | print STDERR ("expect(): handling param '$parm'...\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 14323 | ▶ | if ( ref($parm) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 14214 | ▶ | if ( ref($parm) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 14214 | my $err = _add_patterns_to_list( | |||||||||||||||||||||||||||||||||||||||||
| 505 | \@pattern_list, \@timeout_list, | ||||||||||||||||||||||||||||||||||||||||||
| 506 | $parm_nr, $parm | ||||||||||||||||||||||||||||||||||||||||||
| 507 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 14214 | ▶ | carp( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | "expect(): Warning: multiple `timeout' patterns (", | ||||||||||||||||||||||||||||||||||||||||||
| 510 | scalar(@timeout_list), ").\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 511 | ) if @timeout_list > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 14214 | ▶ | $timeout_hook = $timeout_list[-1] if $timeout_list[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 14214 | ▶ | croak $err if $err; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 14214 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | croak("expect(): Unknown pattern ref $parm"); | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | # not a ref, is an option or raw pattern | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 109 | ▶ | if ( substr( $parm, 0, 1 ) eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | # it's an option | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 21 | ▶ | print STDERR ("expect(): handling option '$parm'...\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 21 | ▶ | if ( $parm eq '-i' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | # first add collected patterns to object list | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if ( scalar(@$curr_list) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | push @object_list, $curr_list | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | if not exists $patterns{"$curr_list"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | push @{ $patterns{"$curr_list"} }, @pattern_list; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | @pattern_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | # now put parm(s) into current object list | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if ( ref( $_[0] ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $curr_list = shift; | |||||||||||||||||||||||||||||||||||||||||
| 539 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $curr_list = [shift]; | |||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||
| 542 | ▶ | } elsif ( $parm eq '-re' | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parm eq "-re" or $parm eq "-ex"
MC/DC0%0/2
$parm eq "-re" or $parm eq "-ex"
$parm eq "-re"
$parm eq "-ex"
Truth table33%1/3
A or B
A= $parm eq "-re"B= $parm eq "-ex"
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | or $parm eq '-ex' ) | ||||||||||||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 21 | ▶ | if ( ref( $_[1] ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | push @pattern_list, [ $parm_nr, $parm, shift, shift ]; | |||||||||||||||||||||||||||||||||||||||||
| 547 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 21 | push @pattern_list, [ $parm_nr, $parm, shift, undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 21 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 551 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | croak("Unknown option $parm"); | |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | # a plain pattern, check if it is followed by a CODE ref | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 88 | ▶ | if ( ref( $_[0] ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | if ( $parm eq 'timeout' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | push @timeout_list, shift; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | carp( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | "expect(): Warning: multiple `timeout' patterns (", | ||||||||||||||||||||||||||||||||||||||||||
| 562 | scalar(@timeout_list), | ||||||||||||||||||||||||||||||||||||||||||
| 563 | ").\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 564 | ) if @timeout_list > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | $timeout_hook = $timeout_list[-1] if $timeout_list[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | } elsif ( $parm eq 'eof' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | push @pattern_list, [ $parm_nr, "-$parm", undef, shift ]; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | push @pattern_list, [ $parm_nr, '-ex', $parm, shift ]; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 88 | ▶ | print STDERR ("expect(): exact match '$parm'...\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 88 | push @pattern_list, [ $parm_nr, '-ex', $parm, undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 88 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | # add rest of collected patterns to object list | ||||||||||||||||||||||||||||||||||||||||||
| 582 | 4811 | ▶ | carp "expect(): Empty object list" unless $curr_list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | 4811 | ▶ | push @object_list, $curr_list if not exists $patterns{"$curr_list"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | 4811 | push @{ $patterns{"$curr_list"} }, @pattern_list; | |||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 4811 | ▶ | my $debug = $self ? ${*$self}{exp_Debug} : $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 4811 | ▶ | my $internal = $self ? ${*$self}{exp_Exp_Internal} : $Expect::Exp_Internal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | # now start matching... | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 4811 | ▶ | if (@Expect::Before_List) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | print STDERR ("Starting BEFORE pattern matching...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$debug or $internal
MC/DC0%0/2
$debug or $internal
$debug
$internal
Truth table0%0/3
A or B
A= $debugB= $internal
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | if ( $debug or $internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | _multi_expect( 0, undef, @Expect::Before_List ); | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 4811 | ▶ | cluck("Starting EXPECT pattern matching...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $internal
MC/DC0%0/2
$debug or $internal
$debug
$internal
Truth table33%1/3
A or B
A= $debugB= $internal
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | if ( $debug or $internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 4811 | my @ret; | |||||||||||||||||||||||||||||||||||||||||
| 600 | @ret = _multi_expect( | ||||||||||||||||||||||||||||||||||||||||||
| 601 | $timeout, $timeout_hook, | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 4811 | map { [ $_, @{ $patterns{"$_"} } ] } @object_list | |||||||||||||||||||||||||||||||||||||||||
| 603 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 4811 | ▶ | if (@Expect::After_List) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | print STDERR ("Starting AFTER pattern matching...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$debug or $internal
MC/DC0%0/2
$debug or $internal
$debug
$internal
Truth table0%0/3
A or B
A= $debugB= $internal
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | if ( $debug or $internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | _multi_expect( 0, undef, @Expect::After_List ); | |||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 4811 | ▶ | return wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 615 | # the real workhorse | ||||||||||||||||||||||||||||||||||||||||||
| 616 | # | ||||||||||||||||||||||||||||||||||||||||||
| 617 | sub _multi_expect { | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 4811 | ▶ | my ($timeout, $timeout_hook, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multi_expect: called CC=109 SCAR=63.9
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 4811 | ▶ | if ($timeout_hook) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 4720 | ▶ | croak "Unknown timeout_hook type $timeout_hook" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $timeout_hook eq "CODE" or ref $timeout_hook eq "ARRAY"
MC/DC0%0/2
ref $timeout_hook eq "CODE" or ref $timeout_hook eq "ARRAY"
ref $timeout_hook eq "CODE"
ref $timeout_hook eq "ARRAY"
Truth table33%1/3
A or B
A= ref $timeout_hook eq "CODE"B= ref $timeout_hook eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | unless ( ref($timeout_hook) eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||
| 623 | or ref($timeout_hook) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | 4811 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 627 | 4811 | my @patterns = @{$pat}[ 1 .. $#{$pat} ]; | |||||||||||||||||||||||||||||||||||||||||
| 628 | 4811 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 629 | 4811 | ${*$exp}{exp_New_Data} = 1; # first round we always try to match | |||||||||||||||||||||||||||||||||||||||||
| 630 | 4811 | ▶ | if ( exists ${*$exp}{"exp_Max_Accum"} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists do {
*$exp
}->{"exp_Max_Accum"} and do {
*$exp
}->{"exp_Max_Accum"}
MC/DC0%0/2
exists do {
*$exp
}->{"exp_Max_Accum"} and do {
*$exp
}->{"exp_Max_Accum"}
exists do {
*$exp
}->{"exp_Max_Accum"}
do {
*$exp
}->{"exp_Max_Accum"}
Truth table33%1/3
A and B
A= exists do {
*$exp
}->{"exp_Max_Accum"}B= do {
*$exp
}->{"exp_Max_Accum"}
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 4811 | and ${*$exp}{"exp_Max_Accum"} ) | |||||||||||||||||||||||||||||||||||||||||
| 632 | { | ||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ${*$exp}{exp_Accum} = $exp->_trim_length( | |||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ${*$exp}{exp_Max_Accum} | |||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 4811 | ▶ | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | "${*$exp}{exp_Pty_Handle}: beginning expect.\r\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | "\tTimeout: ", | ||||||||||||||||||||||||||||||||||||||||||
| 641 | ( defined($timeout) ? $timeout : "unlimited" ), | ||||||||||||||||||||||||||||||||||||||||||
| 642 | " seconds.\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 643 | "\tCurrent time: " . localtime() . "\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 644 | ) if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | # What are we expecting? What do you expect? :-) | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 4811 | ▶ | if ( ${*$exp}{exp_Exp_Internal} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | print STDERR "${*$exp}{exp_Pty_Handle}: list of patterns:\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | foreach my $pattern (@patterns) { | |||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | ' ', | ||||||||||||||||||||||||||||||||||||||||||
| 652 | defined( $pattern->[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 653 | ? '#' . $pattern->[0] . ': ' | ||||||||||||||||||||||||||||||||||||||||||
| 654 | : '', | ||||||||||||||||||||||||||||||||||||||||||
| 655 | $pattern->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 656 | " `", | ||||||||||||||||||||||||||||||||||||||||||
| 657 | _make_readable( $pattern->[2] ), | ||||||||||||||||||||||||||||||||||||||||||
| 658 | "'\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 659 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | print STDERR "\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 4811 | my $successful_pattern; | |||||||||||||||||||||||||||||||||||||||||
| 667 | my $exp_matched; | ||||||||||||||||||||||||||||||||||||||||||
| 668 | 4811 | my $err; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 4811 | my $before; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 4811 | my $after; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 4811 | my $match; | |||||||||||||||||||||||||||||||||||||||||
| 672 | 4811 | my @matchlist; | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | # Set the last loop time to now for time comparisons at end of loop. | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 4811 | my $start_loop_time = time(); | |||||||||||||||||||||||||||||||||||||||||
| 676 | 4811 | my $exp_cont = 1; | |||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | READLOOP: | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 4811 | ▶ | while ($exp_cont) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 9762 | $exp_cont = 1; | |||||||||||||||||||||||||||||||||||||||||
| 681 | 9762 | $err = ""; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 9762 | my $rmask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 683 | 9762 | my $time_left = undef; | |||||||||||||||||||||||||||||||||||||||||
| 684 | 9762 | ▶ | if ( defined $timeout ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 9762 | $time_left = $timeout - ( time() - $start_loop_time ); | |||||||||||||||||||||||||||||||||||||||||
| 686 | 9762 | ▶ | $time_left = 0 if $time_left < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 9762 | $exp_matched = undef; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | # Test for a match first so we can test the current Accum w/out | ||||||||||||||||||||||||||||||||||||||||||
| 692 | # worrying about an EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 9762 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 695 | 9762 | my @patterns = @{$pat}[ 1 .. $#{$pat} ]; | |||||||||||||||||||||||||||||||||||||||||
| 696 | 9762 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | # build mask for select in next section... | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 9762 | my $fn = $exp->fileno(); | |||||||||||||||||||||||||||||||||||||||||
| 700 | 9762 | ▶ | vec( $rmask, $fn, 1 ) = 1 if defined $fn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 9762 | ▶ | next unless ${*$exp}{exp_New_Data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | # clear error status | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 9718 | ${*$exp}{exp_Error} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 706 | 9718 | ${*$exp}{exp_After} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 707 | 9718 | ${*$exp}{exp_Match_Number} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 9718 | ${*$exp}{exp_Match} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | # This could be huge. We should attempt to do something | ||||||||||||||||||||||||||||||||||||||||||
| 711 | # about this. Because the output is used for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 712 | # I'm of the opinion that showing smaller amounts if the | ||||||||||||||||||||||||||||||||||||||||||
| 713 | # total is huge should be ok. | ||||||||||||||||||||||||||||||||||||||||||
| 714 | # Thus the 'trim_length' | ||||||||||||||||||||||||||||||||||||||||||
| 715 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | "\r\n${*$exp}{exp_Pty_Handle}: Does `", | |||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | $exp->_trim_length( _make_readable( ${*$exp}{exp_Accum} ) ), | |||||||||||||||||||||||||||||||||||||||||
| 718 | "'\r\nmatch:\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 9718 | ▶ | ) if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | # we don't keep the parameter number anymore | ||||||||||||||||||||||||||||||||||||||||||
| 722 | # (clashes with before & after), instead the parameter number is | ||||||||||||||||||||||||||||||||||||||||||
| 723 | # stored inside the pattern; we keep the pattern ref | ||||||||||||||||||||||||||||||||||||||||||
| 724 | # and look up the number later. | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 9718 | foreach my $pattern (@patterns) { | |||||||||||||||||||||||||||||||||||||||||
| 726 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 727 | " pattern", | ||||||||||||||||||||||||||||||||||||||||||
| 728 | defined( $pattern->[0] ) ? ' #' . $pattern->[0] : '', | ||||||||||||||||||||||||||||||||||||||||||
| 729 | ": ", | ||||||||||||||||||||||||||||||||||||||||||
| 730 | $pattern->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 731 | " `", | ||||||||||||||||||||||||||||||||||||||||||
| 732 | _make_readable( $pattern->[2] ), | ||||||||||||||||||||||||||||||||||||||||||
| 733 | "'? " | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 14640 | ▶ | ) if ( ${*$exp}{exp_Exp_Internal} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | # Matching exactly | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 14640 | ▶ | if ( $pattern->[1] eq '-ex' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | my $match_index = | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 119 | index( ${*$exp}{exp_Accum}, $pattern->[2] ); | |||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | # We matched if $match_index > -1 | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 119 | ▶ | if ( $match_index > -1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | $before = | ||||||||||||||||||||||||||||||||||||||||||
| 744 | 29 | substr( ${*$exp}{exp_Accum}, 0, $match_index ); | |||||||||||||||||||||||||||||||||||||||||
| 745 | $match = substr( | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 29 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 747 | 29 | $match_index, length( $pattern->[2] ) | |||||||||||||||||||||||||||||||||||||||||
| 748 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 749 | $after = substr( | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 29 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 751 | 29 | $match_index + length( $pattern->[2] ) | |||||||||||||||||||||||||||||||||||||||||
| 752 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 29 | ${*$exp}{exp_Before} = $before; | |||||||||||||||||||||||||||||||||||||||||
| 754 | 29 | ${*$exp}{exp_Match} = $match; | |||||||||||||||||||||||||||||||||||||||||
| 755 | 29 | ${*$exp}{exp_After} = $after; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 29 | ${*$exp}{exp_Match_Number} = $pattern->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 757 | 29 | $exp_matched = $exp; | |||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||
| 759 | } elsif ( $pattern->[1] eq '-re' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 9720 | ▶ | if ($Expect::Multiline_Matching) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | @matchlist = | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 9706 | ( ${*$exp}{exp_Accum} =~ m/($pattern->[2])/m); | |||||||||||||||||||||||||||||||||||||||||
| 764 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 765 | @matchlist = | ||||||||||||||||||||||||||||||||||||||||||
| 766 | 14 | ( ${*$exp}{exp_Accum} =~ m/($pattern->[2])/); | |||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||
| 768 | 9720 | ▶ | if (@matchlist) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | # Matching regexp | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 4797 | $match = shift @matchlist; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 4797 | my $start = index ${*$exp}{exp_Accum}, $match; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 4797 | ▶ | die 'The match could not be found' if $start == -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 4797 | $before = substr ${*$exp}{exp_Accum}, 0, $start; | |||||||||||||||||||||||||||||||||||||||||
| 775 | 4797 | $after = substr ${*$exp}{exp_Accum}, $start + length($match); | |||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 4797 | ${*$exp}{exp_Before} = $before; | |||||||||||||||||||||||||||||||||||||||||
| 778 | 4797 | ${*$exp}{exp_Match} = $match; | |||||||||||||||||||||||||||||||||||||||||
| 779 | 4797 | ${*$exp}{exp_After} = $after; | |||||||||||||||||||||||||||||||||||||||||
| 780 | #pop @matchlist; # remove kludged empty bracket from end | ||||||||||||||||||||||||||||||||||||||||||
| 781 | 4797 | @{ ${*$exp}{exp_Matchlist} } = @matchlist; | |||||||||||||||||||||||||||||||||||||||||
| 782 | 4797 | ${*$exp}{exp_Match_Number} = $pattern->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 783 | 4797 | $exp_matched = $exp; | |||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||
| 785 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | # 'timeout' or 'eof' | ||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 14640 | ▶ | if ($exp_matched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 4781 | ${*$exp}{exp_Accum} = $after | |||||||||||||||||||||||||||||||||||||||||
| 792 | 4826 | ▶ | unless ${*$exp}{exp_NoTransfer}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | print STDERR "YES!!\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 4826 | ▶ | if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 795 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 796 | " Before match string: `", | ||||||||||||||||||||||||||||||||||||||||||
| 797 | $exp->_trim_length( _make_readable( ($before) ) ), | ||||||||||||||||||||||||||||||||||||||||||
| 798 | "'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 799 | " Match string: `", | ||||||||||||||||||||||||||||||||||||||||||
| 800 | _make_readable($match), | ||||||||||||||||||||||||||||||||||||||||||
| 801 | "'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 802 | " After match string: `", | ||||||||||||||||||||||||||||||||||||||||||
| 803 | $exp->_trim_length( _make_readable( ($after) ) ), | ||||||||||||||||||||||||||||||||||||||||||
| 804 | "'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 805 | " Matchlist: (", | ||||||||||||||||||||||||||||||||||||||||||
| 806 | join( | ||||||||||||||||||||||||||||||||||||||||||
| 807 | ", ", | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | map { "`" . $exp->_trim_length( _make_readable( ($_) ) ) . "'" } @matchlist, | |||||||||||||||||||||||||||||||||||||||||
| 809 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 810 | ")\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 4826 | ▶ | ) if ( ${*$exp}{exp_Exp_Internal} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | # call hook function if defined | ||||||||||||||||||||||||||||||||||||||||||
| 814 | 4826 | ▶ | if ( $pattern->[3] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 816 | "Calling hook $pattern->[3]...\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 817 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 4777 | if ( ${*$exp}{exp_Exp_Internal} | |||||||||||||||||||||||||||||||||||||||||
| 819 | 4777 | ▶ | or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
do {
*$exp
}->{"exp_Exp_Internal"} or $Expect::Debug
MC/DC0%0/2
do {
*$exp
}->{"exp_Exp_Internal"} or $Expect::Debug
do {
*$exp
}->{"exp_Exp_Internal"}
$Expect::Debug
Truth table33%1/3
A or B
A= do {
*$exp
}->{"exp_Exp_Internal"}B= $Expect::Debug
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | 4777 | ▶ | if ( $#{$pattern} > 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | # call with parameters if given | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | $exp_cont = &{ $pattern->[3] }( $exp, @{$pattern}[ 4 .. $#{$pattern} ] ); | |||||||||||||||||||||||||||||||||||||||||
| 824 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 825 | 4777 | $exp_cont = &{ $pattern->[3] }($exp); | |||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 4826 | ▶ | if ( $exp_cont and $exp_cont eq exp_continue ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$exp_cont and $exp_cont eq exp_continue()
MC/DC50%1/2
$exp_cont and $exp_cont eq exp_continue()
$exp_cont
$exp_cont eq exp_continue()
Truth table66%2/3
A and B
A= $exp_contB= $exp_cont eq exp_continue()
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | print STDERR ("Continuing expect, restarting timeout...\r\n") | ||||||||||||||||||||||||||||||||||||||||||
| 830 | 64 | if ( ${*$exp}{exp_Exp_Internal} | |||||||||||||||||||||||||||||||||||||||||
| 831 | 64 | ▶ | or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
do {
*$exp
}->{"exp_Exp_Internal"} or $Expect::Debug
MC/DC0%0/2
do {
*$exp
}->{"exp_Exp_Internal"} or $Expect::Debug
do {
*$exp
}->{"exp_Exp_Internal"}
$Expect::Debug
Truth table33%1/3
A or B
A= do {
*$exp
}->{"exp_Exp_Internal"}B= $Expect::Debug
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 64 | $start_loop_time = time(); # restart timeout count | |||||||||||||||||||||||||||||||||||||||||
| 833 | 64 | next READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 834 | ▶ | } elsif ( $exp_cont | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$exp_cont and $exp_cont eq exp_continue_timeout()
MC/DC0%0/2
$exp_cont and $exp_cont eq exp_continue_timeout()
$exp_cont
$exp_cont eq exp_continue_timeout()
Truth table33%1/3
A and B
A= $exp_contB= $exp_cont eq exp_continue_timeout()
| |||||||||||||||||||||||||||||||||||||||||||
| 835 | and $exp_cont eq exp_continue_timeout ) | ||||||||||||||||||||||||||||||||||||||||||
| 836 | { | ||||||||||||||||||||||||||||||||||||||||||
| 837 | print STDERR ("Continuing expect...\r\n") | ||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | if ( ${*$exp}{exp_Exp_Internal} | |||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | ▶ | or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
do {
*$exp
}->{"exp_Exp_Internal"} or $Expect::Debug
MC/DC0%0/2
do {
*$exp
}->{"exp_Exp_Internal"} or $Expect::Debug
do {
*$exp
}->{"exp_Exp_Internal"}
$Expect::Debug
Truth table0%0/3
A or B
A= do {
*$exp
}->{"exp_Exp_Internal"}B= $Expect::Debug
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | next READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | 4762 | last READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | 9814 | ▶ | print STDERR "No.\r\n" if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||
| 846 | 4892 | ▶ | print STDERR "\r\n" if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | # don't have to match again until we get new data | ||||||||||||||||||||||||||||||||||||||||||
| 849 | 4892 | ${*$exp}{exp_New_Data} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||
| 851 | } # End of matching section | ||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | # No match, let's see what is pending on the filehandles... | ||||||||||||||||||||||||||||||||||||||||||
| 854 | 4936 | ▶ | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$Expect::Exp_Internal or $Expect::Debug
MC/DC0%0/2
$Expect::Exp_Internal or $Expect::Debug
$Expect::Exp_Internal
$Expect::Debug
Truth table33%1/3
A or B
A= $Expect::Exp_InternalB= $Expect::Debug
| |||||||||||||||||||||||||||||||||||||||||||
| 855 | "Waiting for new data (", | ||||||||||||||||||||||||||||||||||||||||||
| 856 | defined($time_left) ? $time_left : 'unlimited', | ||||||||||||||||||||||||||||||||||||||||||
| 857 | " seconds)...\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 858 | ) if ( $Expect::Exp_Internal or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||||
| 859 | 4936 | my $nfound; | |||||||||||||||||||||||||||||||||||||||||
| 860 | SELECT: { | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 4936 | $nfound = select( $rmask, undef, undef, $time_left ); | |||||||||||||||||||||||||||||||||||||||||
| 862 | 4936 | ▶ | if ( $nfound < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | if ( $!{EINTR} and $Expect::IgnoreEintr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$!{"EINTR"} and $Expect::IgnoreEintr
MC/DC0%0/2
$!{"EINTR"} and $Expect::IgnoreEintr
$!{"EINTR"}
$Expect::IgnoreEintr
Truth table0%0/3
A and B
A= $!{"EINTR"}B= $Expect::IgnoreEintr
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | print STDERR ("ignoring EINTR, restarting select()...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Expect::Exp_Internal or $Expect::Debug
MC/DC0%0/2
$Expect::Exp_Internal or $Expect::Debug
$Expect::Exp_Internal
$Expect::Debug
Truth table0%0/3
A or B
A= $Expect::Exp_InternalB= $Expect::Debug
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | if ( $Expect::Exp_Internal or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | next SELECT; | |||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | print STDERR ("select() returned error code '$!'\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Expect::Exp_Internal or $Expect::Debug
MC/DC0%0/2
$Expect::Exp_Internal or $Expect::Debug
$Expect::Exp_Internal
$Expect::Debug
Truth table0%0/3
A or B
A= $Expect::Exp_InternalB= $Expect::Debug
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | if ( $Expect::Exp_Internal or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||
| 871 | # returned error | ||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | $err = "4:$!"; | |||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | last READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | # go until we don't find something (== timeout). | ||||||||||||||||||||||||||||||||||||||||||
| 878 | 4936 | ▶ | if ( $nfound == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | # No pattern, no EOF. Did we time out? | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 70 | $err = "1:TIMEOUT"; | |||||||||||||||||||||||||||||||||||||||||
| 882 | 70 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 883 | 70 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 884 | 70 | $before = ${*$exp}{exp_Before} = ${*$exp}{exp_Accum}; | |||||||||||||||||||||||||||||||||||||||||
| 885 | 70 | ▶ | next if not defined $exp->fileno(); # skip already closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | 70 | ▶ | ${*$exp}{exp_Error} = $err unless ${*$exp}{exp_Error}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||||||||||||
| 889 | 70 | ▶ | print STDERR ("TIMEOUT\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Expect::Debug or $Expect::Exp_Internal
MC/DC0%0/2
$Expect::Debug or $Expect::Exp_Internal
$Expect::Debug
$Expect::Exp_Internal
Truth table33%1/3
A or B
A= $Expect::DebugB= $Expect::Exp_Internal
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | if ( $Expect::Debug or $Expect::Exp_Internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 891 | 70 | ▶ | if ($timeout_hook) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 892 | 46 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 893 | 46 | ▶ | print STDERR ("Calling timeout function $timeout_hook...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Expect::Debug or $Expect::Exp_Internal
MC/DC0%0/2
$Expect::Debug or $Expect::Exp_Internal
$Expect::Debug
$Expect::Exp_Internal
Truth table33%1/3
A or B
A= $Expect::DebugB= $Expect::Exp_Internal
| |||||||||||||||||||||||||||||||||||||||||||
| 894 | if ( $Expect::Debug or $Expect::Exp_Internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 46 | ▶ | if ( ref($timeout_hook) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | $ret = &{$timeout_hook}( $params[0]->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 897 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 898 | 46 | ▶ | if ( $#{$timeout_hook} > 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | $ret = &{ $timeout_hook->[3] }( | |||||||||||||||||||||||||||||||||||||||||
| 900 | $params[0]->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | @{$timeout_hook}[ 4 .. $#{$timeout_hook} ] | |||||||||||||||||||||||||||||||||||||||||
| 902 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 903 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 904 | 46 | $ret = &{ $timeout_hook->[3] }( $params[0]->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||
| 907 | 46 | ▶ | if ( $ret and $ret eq exp_continue ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ret and $ret eq exp_continue()
MC/DC50%1/2
$ret and $ret eq exp_continue()
$ret
$ret eq exp_continue()
Truth table66%2/3
A and B
A= $retB= $ret eq exp_continue()
| |||||||||||||||||||||||||||||||||||||||||||
| 908 | 44 | $start_loop_time = time(); # restart timeout count | |||||||||||||||||||||||||||||||||||||||||
| 909 | 44 | next READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||||||||||||||||
| 912 | 26 | last READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 4866 | my @bits = split( //, unpack( 'b*', $rmask ) ); | |||||||||||||||||||||||||||||||||||||||||
| 916 | 4866 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 917 | 4866 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 918 | 4866 | ▶ | next if not defined $exp->fileno(); # skip already closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 4866 | ▶ | if ( $bits[ $exp->fileno() ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 920 | 4866 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: new data.\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | # read in what we found. | ||||||||||||||||||||||||||||||||||||||||||
| 924 | 4866 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 925 | 4866 | my $nread = sysread( $exp, $buffer, 2048 ); | |||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | # Make errors (nread undef) show up as EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 928 | 4866 | ▶ | $nread = 0 unless defined($nread); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | 4866 | ▶ | if ( $nread == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 931 | 23 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: EOF\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 932 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 933 | 23 | $before = ${*$exp}{exp_Before} = $exp->clear_accum(); | |||||||||||||||||||||||||||||||||||||||||
| 934 | 23 | $err = "2:EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 23 | ${*$exp}{exp_Error} = $err; | |||||||||||||||||||||||||||||||||||||||||
| 936 | 23 | ${*$exp}{exp_Has_EOF} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 937 | 23 | $exp_cont = undef; | |||||||||||||||||||||||||||||||||||||||||
| 938 | 23 | foreach my $eof_pat ( grep { $_->[1] eq '-eof' } @{$pat}[ 1 .. $#{$pat} ] ) { | |||||||||||||||||||||||||||||||||||||||||
| 939 | 9 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 940 | 9 | ▶ | print STDERR ( "Calling EOF hook $eof_pat->[3]...\r\n", ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 941 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 942 | 9 | ▶ | if ( $#{$eof_pat} > 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | # call with parameters if given | ||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | $ret = &{ $eof_pat->[3] }( $exp, @{$eof_pat}[ 4 .. $#{$eof_pat} ] ); | |||||||||||||||||||||||||||||||||||||||||
| 946 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 947 | 9 | $ret = &{ $eof_pat->[3] }($exp); | |||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||
| 949 | 9 | ▶ | if ($ret | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$ret and $ret eq exp_continue() || $ret eq exp_continue_timeout()
$ret eq exp_continue() or $ret eq exp_continue_timeout()
MC/DC0%0/3
$ret and $ret eq exp_continue() || $ret eq exp_continue_timeout()
$ret
$ret eq exp_continue()
$ret eq exp_continue_timeout()
Truth table25%1/4
A and B or C
A= $retB= $ret eq exp_continue()C= $ret eq exp_continue_timeout()
| |||||||||||||||||||||||||||||||||||||||||||
| 950 | and ( $ret eq exp_continue | ||||||||||||||||||||||||||||||||||||||||||
| 951 | or $ret eq exp_continue_timeout ) | ||||||||||||||||||||||||||||||||||||||||||
| 952 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 953 | { | ||||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | $exp_cont = $ret; | |||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | # is it dead? | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 23 | ▶ | if ( defined( ${*$exp}{exp_Pid} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | my $ret = | ||||||||||||||||||||||||||||||||||||||||||
| 961 | 23 | waitpid( ${*$exp}{exp_Pid}, POSIX::WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 962 | 23 | ▶ | if ( $ret == ${*$exp}{exp_Pid} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 963 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 964 | "%s: exit(0x%02X)\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 965 | 23 | ▶ | ${*$exp}{exp_Pty_Handle}, $? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 966 | ) if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 967 | 23 | $err = "3:Child PID ${*$exp}{exp_Pid} exited with status $?"; | |||||||||||||||||||||||||||||||||||||||||
| 968 | 23 | ${*$exp}{exp_Error} = $err; | |||||||||||||||||||||||||||||||||||||||||
| 969 | 23 | ${*$exp}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 970 | 23 | delete $Expect::Spawned_PIDs{ ${*$exp}{exp_Pid} }; | |||||||||||||||||||||||||||||||||||||||||
| 971 | 23 | ${*$exp}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | 23 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: closing...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 975 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 976 | 23 | $exp->hard_close(); | |||||||||||||||||||||||||||||||||||||||||
| 977 | 23 | next; | |||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||
| 979 | 4843 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: read $nread byte(s).\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 980 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||
| 982 | # ugly hack for broken solaris ttys that spew <blank><backspace> | ||||||||||||||||||||||||||||||||||||||||||
| 983 | # into our pretty output | ||||||||||||||||||||||||||||||||||||||||||
| 984 | 4843 | ▶ | $buffer =~ s/ \cH//g if not ${*$exp}{exp_Raw_Pty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | # Append it to the accumulator. | ||||||||||||||||||||||||||||||||||||||||||
| 987 | 4843 | ${*$exp}{exp_Accum} .= $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 988 | 4843 | ▶ | if ( exists ${*$exp}{exp_Max_Accum} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists do {
*$exp
}->{"exp_Max_Accum"} and do {
*$exp
}->{"exp_Max_Accum"}
MC/DC0%0/2
exists do {
*$exp
}->{"exp_Max_Accum"} and do {
*$exp
}->{"exp_Max_Accum"}
exists do {
*$exp
}->{"exp_Max_Accum"}
do {
*$exp
}->{"exp_Max_Accum"}
Truth table33%1/3
A and B
A= exists do {
*$exp
}->{"exp_Max_Accum"}B= do {
*$exp
}->{"exp_Max_Accum"}
| |||||||||||||||||||||||||||||||||||||||||||
| 989 | 4843 | and ${*$exp}{exp_Max_Accum} ) | |||||||||||||||||||||||||||||||||||||||||
| 990 | { | ||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | ${*$exp}{exp_Accum} = $exp->_trim_length( | |||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | ${*$exp}{exp_Max_Accum} | |||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||
| 996 | 4843 | ${*$exp}{exp_New_Data} = 1; # next round we try to match again | |||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||
| 998 | $exp_cont = exp_continue | ||||||||||||||||||||||||||||||||||||||||||
| 999 | 4843 | if ( exists ${*$exp}{exp_Continue} | |||||||||||||||||||||||||||||||||||||||||
| 1000 | 4843 | ▶ | and ${*$exp}{exp_Continue} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists do {
*$exp
}->{"exp_Continue"} and do {
*$exp
}->{"exp_Continue"}
MC/DC0%0/2
exists do {
*$exp
}->{"exp_Continue"} and do {
*$exp
}->{"exp_Continue"}
exists do {
*$exp
}->{"exp_Continue"}
do {
*$exp
}->{"exp_Continue"}
Truth table33%1/3
A and B
A= exists do {
*$exp
}->{"exp_Continue"}B= do {
*$exp
}->{"exp_Continue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | # Now propagate what we have read to other listeners... | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | 4843 | $exp->_print_handles($buffer); | |||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||
| 1005 | # End handle reading section. | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | } # end read loop | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | $start_loop_time = time() # restart timeout count | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | 4866 | ▶ | if ( $exp_cont and $exp_cont eq exp_continue ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$exp_cont and $exp_cont eq exp_continue()
MC/DC0%0/2
$exp_cont and $exp_cont eq exp_continue()
$exp_cont
$exp_cont eq exp_continue()
Truth table66%2/3
A and B
A= $exp_contB= $exp_cont eq exp_continue()
| |||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | # End READLOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||
| 1015 | # Post loop. Do we have anything? | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | # Tell us status | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | 4811 | ▶ | if ( $Expect::Debug or $Expect::Exp_Internal ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Expect::Debug or $Expect::Exp_Internal
MC/DC0%0/2
$Expect::Debug or $Expect::Exp_Internal
$Expect::Debug
$Expect::Exp_Internal
Truth table33%1/3
A or B
A= $Expect::DebugB= $Expect::Exp_Internal
| |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | if ($exp_matched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1019 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | "Returning from expect ", | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | ▶ | ${*$exp_matched}{exp_Error} ? 'un' : '', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1022 | "successfully.", | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | ${*$exp_matched}{exp_Error} | |||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | ? "\r\n Error: ${*$exp_matched}{exp_Error}." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1025 | : '', | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | "\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | print STDERR ("Returning from expect with TIMEOUT or EOF\r\n"); | |||||||||||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | ▶ | if ( $Expect::Debug and $exp_matched ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Expect::Debug and $exp_matched
MC/DC0%0/2
$Expect::Debug and $exp_matched
$Expect::Debug
$exp_matched
Truth table0%0/3
A and B
A= $Expect::DebugB= $exp_matched
| |||||||||||||||||||||||||||||||||||||||||||
| 1032 | 0 | print STDERR " ${*$exp_matched}{exp_Pty_Handle}: accumulator: `"; | |||||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | ▶ | if ( ${*$exp_matched}{exp_Error} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1034 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | $exp_matched->_trim_length( _make_readable( ${*$exp_matched}{exp_Before} ) ), | |||||||||||||||||||||||||||||||||||||||||
| 1036 | "'\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1037 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1039 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | $exp_matched->_trim_length( _make_readable( ${*$exp_matched}{exp_Accum} ) ), | |||||||||||||||||||||||||||||||||||||||||
| 1041 | "'\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1042 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1045 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||
| 1047 | 4811 | ▶ | if ($exp_matched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1048 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | ? ( | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | 4762 | ${*$exp_matched}{exp_Match_Number}, ${*$exp_matched}{exp_Error}, | |||||||||||||||||||||||||||||||||||||||||
| 1051 | 4762 | ${*$exp_matched}{exp_Match}, ${*$exp_matched}{exp_Before}, | |||||||||||||||||||||||||||||||||||||||||
| 1052 | 4762 | ${*$exp_matched}{exp_After}, $exp_matched, | |||||||||||||||||||||||||||||||||||||||||
| 1053 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | 4762 | ▶ | : ${*$exp_matched}{exp_Match_Number}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | 49 | ▶ | return wantarray ? ( undef, $err, undef, $before, undef, undef ) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||
| 1060 | # Patterns are arrays that consist of | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | # [ $pattern_type, $pattern, $sub, @subparms ] | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | # optional $pattern_type is '-re' (RegExp, default) or '-ex' (exact); | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | # $sub is optional CODE ref, which is called as &{$sub}($exp, @subparms) | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | # if pattern matched; | ||||||||||||||||||||||||||||||||||||||||||
| 1065 | # the $parm_nr gets unshifted onto the array for reporting purposes. | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||
| 1067 | sub _add_patterns_to_list { | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | 14214 | ▶ | my ($listref, $timeoutlistref,$store_parm_nr, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_patterns_to_list: called CC=14 SCAR=30.2
| |||||||||||||||||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||||||||||||||||
| 1070 | # $timeoutlistref gets timeout patterns | ||||||||||||||||||||||||||||||||||||||||||
| 1071 | 14214 | ▶ | my $parm_nr = $store_parm_nr || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$store_parm_nr || 1
MC/DC0%0/1
$store_parm_nr || 1
$store_parm_nr
Truth table50%1/2
A
A= $store_parm_nr
| |||||||||||||||||||||||||||||||||||||||||||
| 1072 | 14214 | foreach my $parm (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 1073 | 14214 | ▶ | if ( not ref($parm) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | return "Parameter #$parm_nr is not an ARRAY ref."; | |||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | 14214 | $parm = [@$parm]; # make copy | |||||||||||||||||||||||||||||||||||||||||
| 1077 | 14214 | ▶ | if ( $parm->[0] =~ m/\A-/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||
| 1079 | # it's an option | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | 0 | ▶ | if ( $parm->[0] ne '-re' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$parm->[0] ne "-re" and $parm->[0] ne "-ex"
MC/DC0%0/2
$parm->[0] ne "-re" and $parm->[0] ne "-ex"
$parm->[0] ne "-re"
$parm->[0] ne "-ex"
Truth table0%0/3
A and B
A= $parm->[0] ne "-re"B= $parm->[0] ne "-ex"
| |||||||||||||||||||||||||||||||||||||||||||
| 1081 | and $parm->[0] ne '-ex' ) | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | return "Unknown option $parm->[0] in pattern #$parm_nr"; | |||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | 14214 | ▶ | if ( $parm->[0] eq 'timeout' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1087 | 4720 | ▶ | if ( defined $timeoutlistref ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | 4720 | splice @$parm, 0, 1, ( "-$parm->[0]", undef ); | |||||||||||||||||||||||||||||||||||||||||
| 1089 | 4720 | ▶ | unshift @$parm, $store_parm_nr ? $parm_nr : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1090 | 4720 | push @$timeoutlistref, $parm; | |||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | 4720 | next; | |||||||||||||||||||||||||||||||||||||||||
| 1093 | } elsif ( $parm->[0] eq 'eof' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | 4720 | splice @$parm, 0, 1, ( "-$parm->[0]", undef ); | |||||||||||||||||||||||||||||||||||||||||
| 1095 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | 4774 | unshift @$parm, '-re'; # defaults to RegExp | |||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | 9494 | ▶ | if ( @$parm > 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1100 | 9491 | ▶ | if ( ref( $parm->[2] ) ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1101 | 0 | croak( | |||||||||||||||||||||||||||||||||||||||||
| 1102 | "Pattern #$parm_nr doesn't have a CODE reference", | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | "after the pattern." | ||||||||||||||||||||||||||||||||||||||||||
| 1104 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | 3 | push @$parm, undef; # make sure we have three elements | |||||||||||||||||||||||||||||||||||||||||
| 1108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||
| 1110 | 9494 | ▶ | unshift @$parm, $store_parm_nr ? $parm_nr : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1111 | 9494 | push @$listref, $parm; | |||||||||||||||||||||||||||||||||||||||||
| 1112 | 9494 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 1113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 14214 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||
| 1118 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 1119 | # $process->interact([$in_handle],[$escape sequence]) | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | # If you don't specify in_handle STDIN will be used. | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | sub interact { | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | ▶ | my ($self, $infile, $escape_sequence) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interact: not called CC=6 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | my $outfile; | |||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | my @old_group = $self->set_group(); | |||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||
| 1127 | # If the handle is STDIN we'll | ||||||||||||||||||||||||||||||||||||||||||
| 1128 | # $infile->fileno == 0 should be stdin.. follow stdin rules. | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | 23 | ▶ | no strict 'subs'; # Allow bare word 'STDIN' | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | ▶ | unless ( defined($infile) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1131 | # We need a handle object Associated with STDIN. | ||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | $infile = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | $infile->IO::File::fdopen( STDIN, 'r' ); | |||||||||||||||||||||||||||||||||||||||||
| 1134 | 0 | $outfile = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | $outfile->IO::File::fdopen( STDOUT, 'w' ); | |||||||||||||||||||||||||||||||||||||||||
| 1136 | } elsif ( fileno($infile) == fileno(STDIN) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||
| 1138 | # With STDIN we want output to go to stdout. | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | $outfile = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1140 | 0 | $outfile->IO::File::fdopen( STDOUT, 'w' ); | |||||||||||||||||||||||||||||||||||||||||
| 1141 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | undef($outfile); | |||||||||||||||||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||
| 1145 | # Here we assure ourselves we have an Expect object. | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | 0 | my $in_object = Expect->exp_init($infile); | |||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | ▶ | if ( defined($outfile) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||
| 1149 | # as above.. we want output to go to stdout if we're given stdin. | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | my $out_object = Expect->exp_init($outfile); | |||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | $out_object->manual_stty(1); | |||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | $self->set_group($out_object); | |||||||||||||||||||||||||||||||||||||||||
| 1153 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | $self->set_group($in_object); | |||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | 0 | $in_object->set_group($self); | |||||||||||||||||||||||||||||||||||||||||
| 1157 | 0 | ▶ | $in_object->set_seq( $escape_sequence, undef ) if defined($escape_sequence); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||
| 1159 | # interconnect normally sets stty -echo raw. Interact really sort | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | # of implies we don't do that by default. If anyone wanted to they could | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | # set it before calling interact, of use interconnect directly. | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | 0 | my $old_manual_stty_val = $self->manual_stty(); | |||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | $self->manual_stty(1); | |||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||
| 1165 | # I think this is right. Don't send stuff from in_obj to stdout by default. | ||||||||||||||||||||||||||||||||||||||||||
| 1166 | # in theory whatever 'self' is should echo what's going on. | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | my $old_log_stdout_val = $self->log_stdout(); | |||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | $self->log_stdout(0); | |||||||||||||||||||||||||||||||||||||||||
| 1169 | 0 | $in_object->log_stdout(0); | |||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||
| 1171 | # Allow for the setting of an optional EOF escape function. | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | # $in_object->set_seq('EOF',undef); | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | # $self->set_seq('EOF',undef); | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | Expect::interconnect( $self, $in_object ); | |||||||||||||||||||||||||||||||||||||||||
| 1175 | 0 | $self->log_stdout($old_log_stdout_val); | |||||||||||||||||||||||||||||||||||||||||
| 1176 | 0 | $self->set_group(@old_group); | |||||||||||||||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||||||||||||||||
| 1178 | # If old_group was undef, make sure that occurs. This is a slight hack since | ||||||||||||||||||||||||||||||||||||||||||
| 1179 | # it modifies the value directly. | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | # Normally an undef passed to set_group will return the current groups. | ||||||||||||||||||||||||||||||||||||||||||
| 1181 | # It is possible that it may be of worth to make it possible to undef | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | # The current group without doing this. | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | ▶ | unless (@old_group) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | @{ ${*$self}{exp_Listen_Group} } = (); | |||||||||||||||||||||||||||||||||||||||||
| 1185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | $self->manual_stty($old_manual_stty_val); | |||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||
| 1191 | sub interconnect { | ||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | ▶ | my (@handles) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interconnect: not called CC=48 SCAR=77.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||
| 1194 | # my ($handle)=(shift); call as Expect::interconnect($spawn1,$spawn2,...) | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | my ( $nread ); | |||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | my ( $rout, $emask, $eout ); | |||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | my ( $escape_character_buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | my ( $read_mask, $temp_mask ) = ( '', '' ); | |||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||
| 1200 | # Get read/write handles | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | $temp_mask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | vec( $temp_mask, $handle->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||
| 1205 | # Under Linux w/ 5.001 the next line comes up w/ 'Uninit var.'. | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | # It appears to be impossible to make the warning go away. | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | # doing something like $temp_mask='' unless defined ($temp_mask) | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | # has no effect whatsoever. This may be a bug in 5.001. | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | $read_mask = $read_mask | $temp_mask; | |||||||||||||||||||||||||||||||||||||||||
| 1210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1211 | 0 | ▶ | if ($Expect::Debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | print STDERR "Read handles:\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | print STDERR "\tRead handle: "; | |||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | print STDERR "'${*$handle}{exp_Pty_Handle}'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | 0 | print STDERR "\t\tListen Handles:"; | |||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | foreach my $write_handle ( @{ ${*$handle}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | print STDERR " '${*$write_handle}{exp_Pty_Handle}'"; | |||||||||||||||||||||||||||||||||||||||||
| 1219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1220 | 0 | print STDERR ".\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||
| 1224 | # I think if we don't set raw/-echo here we may have trouble. We don't | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | # want a bunch of echoing crap making all the handles jabber at each other. | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | ▶ | unless ( ${*$handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||
| 1229 | # This is probably O/S specific. | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | 0 | ${*$handle}{exp_Stored_Stty} = $handle->exp_stty('-g'); | |||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | print STDERR "Setting tty for ${*$handle}{exp_Pty_Handle} to 'raw -echo'.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | ▶ | if ${*$handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | $handle->exp_stty("raw -echo"); | |||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | 0 | foreach my $write_handle ( @{ ${*$handle}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1236 | 0 | ▶ | unless ( ${*$write_handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1237 | 0 | ${*$write_handle}{exp_Stored_Stty} = | |||||||||||||||||||||||||||||||||||||||||
| 1238 | 0 | $write_handle->exp_stty('-g'); | |||||||||||||||||||||||||||||||||||||||||
| 1239 | 0 | print STDERR "Setting ${*$write_handle}{exp_Pty_Handle} to 'raw -echo'.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | ▶ | if ${*$handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | $write_handle->exp_stty("raw -echo"); | |||||||||||||||||||||||||||||||||||||||||
| 1242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||
| 1246 | 0 | ▶ | print STDERR "Attempting interconnection\r\n" if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||
| 1248 | # Wait until the process dies or we get EOF | ||||||||||||||||||||||||||||||||||||||||||
| 1249 | # In the case of !${*$handle}{exp_Pid} it means | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | # the handle was exp_inited instead of spawned. | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | CONNECT_LOOP: | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||
| 1253 | # Go until we have a reason to stop | ||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 1255 | |||||||||||||||||||||||||||||||||||||||||||
| 1256 | # test each handle to see if it's still alive. | ||||||||||||||||||||||||||||||||||||||||||
| 1257 | 0 | foreach my $read_handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1258 | 0 | waitpid( ${*$read_handle}{exp_Pid}, WNOHANG ) | |||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | if ( exists( ${*$read_handle}{exp_Pid} ) | |||||||||||||||||||||||||||||||||||||||||
| 1260 | 0 | ▶ | and ${*$read_handle}{exp_Pid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"}
MC/DC0%0/2
exists do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"}
exists do {
*$read_handle
}->{"exp_Pid"}
do {
*$read_handle
}->{"exp_Pid"}
Truth table0%0/3
A and B
A= exists do {
*$read_handle
}->{"exp_Pid"}B= do {
*$read_handle
}->{"exp_Pid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | ▶ | if ( exists( ${*$read_handle}{exp_Pid} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"} and not kill(0, do {
*$read_handle
}->{"exp_Pid"})
exists do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"}
MC/DC0%0/3
exists do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"} and not kill(0, do {
*$read_handle
}->{"exp_Pid"})
exists do {
*$read_handle
}->{"exp_Pid"}
do {
*$read_handle
}->{"exp_Pid"}
not kill(0, do {
*$read_handle
}->{"exp_Pid"})
Truth table0%0/4
A and B and not(C)
A= exists do {
*$read_handle
}->{"exp_Pid"}B= do {
*$read_handle
}->{"exp_Pid"}C= not kill(0, do {
*$read_handle
}->{"exp_Pid"})
| |||||||||||||||||||||||||||||||||||||||||||
| 1262 | 0 | and ( ${*$read_handle}{exp_Pid} ) | |||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | and ( !kill( 0, ${*$read_handle}{exp_Pid} ) ) ) | |||||||||||||||||||||||||||||||||||||||||
| 1264 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1265 | print STDERR | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | 0 | "Got EOF (${*$read_handle}{exp_Pty_Handle} died) reading ${*$read_handle}{exp_Pty_Handle}\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1267 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1268 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | 0 | ▶ | unless defined( ${ ${*$read_handle}{exp_Function} }{"EOF"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1270 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | unless &{ ${ ${*$read_handle}{exp_Function} }{"EOF"} } | |||||||||||||||||||||||||||||||||||||||||
| 1272 | 0 | ▶ | ( @{ ${ ${*$read_handle}{exp_Parameters} }{"EOF"} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||
| 1276 | # Every second? No, go until we get something from someone. | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | my $nfound = select( $rout = $read_mask, undef, $eout = $emask, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||||||||||||||||
| 1279 | # Is there anything to share? May be -1 if interrupted by a signal... | ||||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | ▶ | next CONNECT_LOOP if not defined $nfound or $nfound < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $nfound or $nfound < 1
MC/DC0%0/2
not defined $nfound or $nfound < 1
not defined $nfound
$nfound < 1
Truth table0%0/3
not(A) or B
A= not defined $nfoundB= $nfound < 1
| |||||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||
| 1282 | # Which handles have stuff? | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | my @bits = split( //, unpack( 'b*', $rout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | ▶ | $eout = 0 unless defined($eout); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | my @ebits = split( //, unpack( 'b*', $eout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||
| 1287 | # print "Ebits: $eout\r\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | foreach my $read_handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | ▶ | if ( $bits[ $read_handle->fileno() ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1290 | $nread = sysread( | ||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | $read_handle, ${*$read_handle}{exp_Pty_Buffer}, | |||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | 1024 | |||||||||||||||||||||||||||||||||||||||||
| 1293 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||
| 1295 | # Appease perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 1296 | 0 | ▶ | $nread = 0 unless defined($nread); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1297 | 0 | print STDERR "interconnect: read $nread byte(s) from ${*$read_handle}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||||||||||||||||
| 1300 | # Test for escape seq. before printing. | ||||||||||||||||||||||||||||||||||||||||||
| 1301 | # Appease perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | 0 | ▶ | $escape_character_buffer = '' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1303 | unless defined($escape_character_buffer); | ||||||||||||||||||||||||||||||||||||||||||
| 1304 | 0 | $escape_character_buffer .= ${*$read_handle}{exp_Pty_Buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 1305 | 0 | foreach my $escape_sequence ( keys( %{ ${*$read_handle}{exp_Function} } ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | print STDERR "Tested escape sequence $escape_sequence from ${*$read_handle}{exp_Pty_Handle}" | |||||||||||||||||||||||||||||||||||||||||
| 1307 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||
| 1309 | # Make sure it doesn't grow out of bounds. | ||||||||||||||||||||||||||||||||||||||||||
| 1310 | $escape_character_buffer = $read_handle->_trim_length( | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | $escape_character_buffer, | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | 0 | ${*$read_handle}{"exp_Max_Accum"} | |||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | ▶ | ) if ( ${*$read_handle}{"exp_Max_Accum"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | ▶ | if ( $escape_character_buffer =~ /($escape_sequence)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | my $match = $1; | |||||||||||||||||||||||||||||||||||||||||
| 1316 | 0 | ▶ | if ( ${*$read_handle}{"exp_Debug"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | print STDERR | |||||||||||||||||||||||||||||||||||||||||
| 1318 | 0 | "\r\ninterconnect got escape sequence from ${*$read_handle}{exp_Pty_Handle}.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1319 | |||||||||||||||||||||||||||||||||||||||||||
| 1320 | # I'm going to make the esc. seq. pretty because it will | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | # probably contain unprintable characters. | ||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | print STDERR "\tEscape Sequence: '" | |||||||||||||||||||||||||||||||||||||||||
| 1323 | . _trim_length( | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 1325 | _make_readable($escape_sequence) | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | ) . "'\r\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | print STDERR "\tMatched by string: '" . _trim_length( undef, _make_readable($match) ) . "'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||||||||||||||||
| 1330 | # Print out stuff before the escape. | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | # Keep in mind that the sequence may have been split up | ||||||||||||||||||||||||||||||||||||||||||
| 1332 | # over several reads. | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | # Let's get rid of it from this read. If part of it was | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | # in the last read there's not a lot we can do about it now. | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | 0 | ▶ | if ( ${*$read_handle}{exp_Pty_Buffer} =~ /([\w\W]*)($escape_sequence)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | $read_handle->_print_handles($1); | |||||||||||||||||||||||||||||||||||||||||
| 1337 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1338 | 0 | $read_handle->_print_handles( ${*$read_handle}{exp_Pty_Buffer} ); | |||||||||||||||||||||||||||||||||||||||||
| 1339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||||||||||||||||
| 1341 | # Clear the buffer so no more matches can be made and it will | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | # only be printed one time. | ||||||||||||||||||||||||||||||||||||||||||
| 1343 | 0 | ${*$read_handle}{exp_Pty_Buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1344 | 0 | $escape_character_buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||||||||||||||||
| 1346 | # Do the function here. Must return non-zero to continue. | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | # More cool syntax. Maybe I should turn these in to objects. | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | 0 | unless &{ ${ ${*$read_handle}{exp_Function} }{$escape_sequence} } | |||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | ▶ | ( @{ ${ ${*$read_handle}{exp_Parameters} }{$escape_sequence} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1353 | 0 | ▶ | $nread = 0 unless defined($nread); # Appease perl -w? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1354 | 0 | waitpid( ${*$read_handle}{exp_Pid}, WNOHANG ) | |||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | if ( defined( ${*$read_handle}{exp_Pid} ) | |||||||||||||||||||||||||||||||||||||||||
| 1356 | 0 | ▶ | && ${*$read_handle}{exp_Pid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"}
MC/DC0%0/2
defined do {
*$read_handle
}->{"exp_Pid"} and do {
*$read_handle
}->{"exp_Pid"}
defined do {
*$read_handle
}->{"exp_Pid"}
do {
*$read_handle
}->{"exp_Pid"}
Truth table0%0/3
A and B
A= defined do {
*$read_handle
}->{"exp_Pid"}B= do {
*$read_handle
}->{"exp_Pid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1357 | 0 | ▶ | if ( $nread == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1358 | 0 | print STDERR "Got EOF reading ${*$read_handle}{exp_Pty_Handle}\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1359 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1360 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | 0 | ▶ | unless defined( ${ ${*$read_handle}{exp_Function} }{"EOF"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1362 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1363 | 0 | unless &{ ${ ${*$read_handle}{exp_Function} }{"EOF"} } | |||||||||||||||||||||||||||||||||||||||||
| 1364 | 0 | ▶ | ( @{ ${ ${*$read_handle}{exp_Parameters} }{"EOF"} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | 0 | ▶ | last CONNECT_LOOP if ( $nread < 0 ); # This would be an error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1367 | 0 | $read_handle->_print_handles( ${*$read_handle}{exp_Pty_Buffer} ); | |||||||||||||||||||||||||||||||||||||||||
| 1368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||
| 1370 | # I'm removing this because I haven't determined what causes exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | # consistently. | ||||||||||||||||||||||||||||||||||||||||||
| 1372 | 0 | if (0) #$ebits[$read_handle->fileno()]) | |||||||||||||||||||||||||||||||||||||||||
| 1373 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1374 | print STDERR "Got Exception reading ${*$read_handle}{exp_Pty_Handle}\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1375 | if ${*$read_handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | unless defined( ${ ${*$read_handle}{exp_Function} }{"EOF"} ); | ||||||||||||||||||||||||||||||||||||||||||
| 1378 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | unless &{ ${ ${*$read_handle}{exp_Function} }{"EOF"} } | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | ( @{ ${ ${*$read_handle}{exp_Parameters} }{"EOF"} } ); | ||||||||||||||||||||||||||||||||||||||||||
| 1381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1385 | 0 | ▶ | unless ( ${*$handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1386 | 0 | $handle->exp_stty( ${*$handle}{exp_Stored_Stty} ); | |||||||||||||||||||||||||||||||||||||||||
| 1387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | 0 | foreach my $write_handle ( @{ ${*$handle}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1389 | 0 | ▶ | unless ( ${*$write_handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1390 | 0 | $write_handle->exp_stty( ${*$write_handle}{exp_Stored_Stty} ); | |||||||||||||||||||||||||||||||||||||||||
| 1391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||
| 1395 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||||||||||||||||
| 1398 | # user can decide if log output gets also sent to logfile | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | sub print_log_file { | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | 4870 | ▶ | my ($self, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_log_file: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||||||||||||||||
| 1402 | 4870 | ▶ | if ( ${*$self}{exp_Log_File} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1403 | 4749 | ▶ | if ( ref( ${*$self}{exp_Log_File} ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1404 | 48 | ${*$self}{exp_Log_File}->(@params); | |||||||||||||||||||||||||||||||||||||||||
| 1405 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1406 | 4701 | ${*$self}{exp_Log_File}->print(@params); | |||||||||||||||||||||||||||||||||||||||||
| 1407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||
| 1410 | 4870 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | |||||||||||||||||||||||||||||||||||||||||||
| 1413 | # we provide our own print so we can debug what gets sent to the | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | # processes... | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | sub print { | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | 4624 | ▶ | my ( $self, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||||||||||||||||
| 1418 | 4624 | ▶ | return if not defined $self->fileno(); # skip if closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1419 | 4624 | ▶ | if ( ${*$self}{exp_Exp_Internal} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1420 | 0 | my $args = _make_readable( join( '', @args ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1421 | 0 | cluck "Sending '$args' to ${*$self}{exp_Pty_Handle}\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | 4624 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||
| 1424 | 4624 | ▶ | while ( length($arg) > 80 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1425 | 10326 | $self->SUPER::print( substr( $arg, 0, 80 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1426 | 10326 | $arg = substr( $arg, 80 ); | |||||||||||||||||||||||||||||||||||||||||
| 1427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1428 | 4624 | $self->SUPER::print($arg); | |||||||||||||||||||||||||||||||||||||||||
| 1429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1430 | |||||||||||||||||||||||||||||||||||||||||||
| 1431 | 4624 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1433 | |||||||||||||||||||||||||||||||||||||||||||
| 1434 | # make an alias for Tcl/Expect users for a DWIM experience... | ||||||||||||||||||||||||||||||||||||||||||
| 1435 | 23 | *send = \&print; | |||||||||||||||||||||||||||||||||||||||||
| 1436 | |||||||||||||||||||||||||||||||||||||||||||
| 1437 | # This is an Expect standard. It's nice for talking to modems and the like | ||||||||||||||||||||||||||||||||||||||||||
| 1438 | # where from time to time they get unhappy if you send items too quickly. | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | sub send_slow { | ||||||||||||||||||||||||||||||||||||||||||
| 1440 | 24 | ▶ | my ($self, $sleep_time, @chunks) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_slow: called CC=12 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||||||||||||||||
| 1442 | 24 | ▶ | return if not defined $self->fileno(); # skip if closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||
| 1444 | # Flushing makes it so each character can be seen separately. | ||||||||||||||||||||||||||||||||||||||||||
| 1445 | 24 | my $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 1446 | 24 | ▶ | while ( $chunk = shift @chunks ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1447 | 24 | my @linechars = split( '', $chunk ); | |||||||||||||||||||||||||||||||||||||||||
| 1448 | 24 | foreach my $char (@linechars) { | |||||||||||||||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||||||||||||||||
| 1450 | # How slow? | ||||||||||||||||||||||||||||||||||||||||||
| 1451 | 1040 | select( undef, undef, undef, $sleep_time ); | |||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||
| 1453 | 1040 | print $self $char; | |||||||||||||||||||||||||||||||||||||||||
| 1454 | 0 | print STDERR "Printed character \'" . _make_readable($char) . "\' to ${*$self}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1455 | 1040 | ▶ | if ${*$self}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||
| 1457 | # I think I can get away with this if I save it in accum | ||||||||||||||||||||||||||||||||||||||||||
| 1458 | 1040 | ▶ | if ( ${*$self}{"exp_Log_Stdout"} || ${*$self}{exp_Log_Group} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
do {
*$self
}->{"exp_Log_Stdout"} or do {
*$self
}->{"exp_Log_Group"}
MC/DC0%0/2
do {
*$self
}->{"exp_Log_Stdout"} or do {
*$self
}->{"exp_Log_Group"}
do {
*$self
}->{"exp_Log_Stdout"}
do {
*$self
}->{"exp_Log_Group"}
Truth table33%1/3
A or B
A= do {
*$self
}->{"exp_Log_Stdout"}B= do {
*$self
}->{"exp_Log_Group"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1459 | 1040 | my $rmask = ""; | |||||||||||||||||||||||||||||||||||||||||
| 1460 | 1040 | vec( $rmask, $self->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||||||||||||||||
| 1462 | # .01 sec granularity should work. If we miss something it will | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | # probably get flushed later, maybe in an expect call. | ||||||||||||||||||||||||||||||||||||||||||
| 1464 | 1040 | ▶ | while ( select( $rmask, undef, undef, .01 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1465 | 24 | my $ret = sysread( $self, ${*$self}{exp_Pty_Buffer}, 1024 ); | |||||||||||||||||||||||||||||||||||||||||
| 1466 | 24 | ▶ | last if not defined $ret or $ret == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $ret or $ret == 0
MC/DC0%0/2
not defined $ret or $ret == 0
not defined $ret
$ret == 0
Truth table33%1/3
not(A) or B
A= not defined $retB= $ret == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||
| 1468 | # Is this necessary to keep? Probably.. # | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | # if you need to expect it later. | ||||||||||||||||||||||||||||||||||||||||||
| 1470 | 24 | ${*$self}{exp_Accum} .= ${*$self}{exp_Pty_Buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 1471 | 0 | ${*$self}{exp_Accum} = $self->_trim_length( | |||||||||||||||||||||||||||||||||||||||||
| 1472 | 0 | ${*$self}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 1473 | 0 | ${*$self}{"exp_Max_Accum"} | |||||||||||||||||||||||||||||||||||||||||
| 1474 | 24 | ▶ | ) if ( ${*$self}{"exp_Max_Accum"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1475 | 24 | $self->_print_handles( ${*$self}{exp_Pty_Buffer} ); | |||||||||||||||||||||||||||||||||||||||||
| 1476 | print STDERR "Received \'" | ||||||||||||||||||||||||||||||||||||||||||
| 1477 | . $self->_trim_length( _make_readable($char) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | 0 | . "\' from ${*$self}{exp_Pty_Handle}\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1479 | 24 | ▶ | if ${*$self}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||
| 1485 | 24 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||
| 1488 | sub test_handles { | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | 0 | ▶ | my ($timeout, @handle_list) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_handles: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1490 | |||||||||||||||||||||||||||||||||||||||||||
| 1491 | # This should be called by Expect::test_handles($timeout,@objects); | ||||||||||||||||||||||||||||||||||||||||||
| 1492 | 0 | my ( $allmask, $rout ); | |||||||||||||||||||||||||||||||||||||||||
| 1493 | 0 | foreach my $handle (@handle_list) { | |||||||||||||||||||||||||||||||||||||||||
| 1494 | 0 | my $rmask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1495 | 0 | vec( $rmask, $handle->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1496 | 0 | ▶ | $allmask = '' unless defined($allmask); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1497 | 0 | $allmask = $allmask | $rmask; | |||||||||||||||||||||||||||||||||||||||||
| 1498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | 0 | my $nfound = select( $rout = $allmask, undef, undef, $timeout ); | |||||||||||||||||||||||||||||||||||||||||
| 1500 | 0 | ▶ | return () unless $nfound; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||
| 1502 | # Which handles have stuff? | ||||||||||||||||||||||||||||||||||||||||||
| 1503 | 0 | my @bits = split( //, unpack( 'b*', $rout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1504 | |||||||||||||||||||||||||||||||||||||||||||
| 1505 | 0 | my $handle_num = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1506 | 0 | my @return_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 1507 | 0 | foreach my $handle (@handle_list) { | |||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||
| 1509 | # I go to great lengths to get perl -w to shut the hell up. | ||||||||||||||||||||||||||||||||||||||||||
| 1510 | 0 | ▶ | if ( defined( $bits[ $handle->fileno() ] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $bits[$handle->fileno] and $bits[$handle->fileno]
MC/DC0%0/2
defined $bits[$handle->fileno] and $bits[$handle->fileno]
defined $bits[$handle->fileno]
$bits[$handle->fileno]
Truth table0%0/3
A and B
A= defined $bits[$handle->fileno]B= $bits[$handle->fileno]
| |||||||||||||||||||||||||||||||||||||||||||
| 1511 | and ( $bits[ $handle->fileno() ] ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1513 | 0 | push( @return_list, $handle_num ); | |||||||||||||||||||||||||||||||||||||||||
| 1514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1515 | } continue { | ||||||||||||||||||||||||||||||||||||||||||
| 1516 | 0 | $handle_num++; | |||||||||||||||||||||||||||||||||||||||||
| 1517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1518 | |||||||||||||||||||||||||||||||||||||||||||
| 1519 | 0 | return @return_list; | |||||||||||||||||||||||||||||||||||||||||
| 1520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||
| 1522 | # Be nice close. This should emulate what an interactive shell does after a | ||||||||||||||||||||||||||||||||||||||||||
| 1523 | # command finishes... sort of. We're not as patient as a shell. | ||||||||||||||||||||||||||||||||||||||||||
| 1524 | sub soft_close { | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
soft_close: called CC=26 SCAR=48.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1526 | |||||||||||||||||||||||||||||||||||||||||||
| 1527 | 7 | my ( $nfound, $nread, $rmask, $end_time, $temp_buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 1528 | |||||||||||||||||||||||||||||||||||||||||||
| 1529 | # Give it 15 seconds to cough up an eof. | ||||||||||||||||||||||||||||||||||||||||||
| 1530 | 7 | ▶ | cluck "Closing ${*$self}{exp_Pty_Handle}.\r\n" if ${*$self}{exp_Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1531 | 7 | ▶ | return -1 if not defined $self->fileno(); # skip if handle already closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1532 | 7 | ▶ | unless ( exists ${*$self}{exp_Has_EOF} and ${*$self}{exp_Has_EOF} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists do {
*$self
}->{"exp_Has_EOF"} and do {
*$self
}->{"exp_Has_EOF"}
MC/DC0%0/2
exists do {
*$self
}->{"exp_Has_EOF"} and do {
*$self
}->{"exp_Has_EOF"}
exists do {
*$self
}->{"exp_Has_EOF"}
do {
*$self
}->{"exp_Has_EOF"}
Truth table33%1/3
A and B
A= exists do {
*$self
}->{"exp_Has_EOF"}B= do {
*$self
}->{"exp_Has_EOF"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1533 | 7 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1534 | 7 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1535 | 10 | my $select_time = $end_time - time(); | |||||||||||||||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||||||||||||||||
| 1537 | # Sanity check. | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | 10 | ▶ | $select_time = 0 if $select_time < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1539 | 10 | $rmask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1540 | 10 | vec( $rmask, $self->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1541 | 10 | ($nfound) = select( $rmask, undef, undef, $select_time ); | |||||||||||||||||||||||||||||||||||||||||
| 1542 | 10 | ▶ | last unless ( defined($nfound) && $nfound ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $nfound and $nfound
MC/DC0%0/2
defined $nfound and $nfound
defined $nfound
$nfound
Truth table33%1/3
A and B
A= defined $nfoundB= $nfound
| |||||||||||||||||||||||||||||||||||||||||||
| 1543 | 10 | $nread = sysread( $self, $temp_buffer, 8096 ); | |||||||||||||||||||||||||||||||||||||||||
| 1544 | |||||||||||||||||||||||||||||||||||||||||||
| 1545 | # 0 = EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | 10 | ▶ | unless ( defined($nread) && $nread ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $nread and $nread
MC/DC50%1/2
defined $nread and $nread
defined $nread
$nread
Truth table66%2/3
A and B
A= defined $nreadB= $nread
| |||||||||||||||||||||||||||||||||||||||||||
| 1547 | 0 | print STDERR "Got EOF from ${*$self}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1548 | 7 | ▶ | if ${*$self}{exp_Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1549 | 7 | last; | |||||||||||||||||||||||||||||||||||||||||
| 1550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1551 | 3 | $self->_print_handles($temp_buffer); | |||||||||||||||||||||||||||||||||||||||||
| 1552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | 7 | ▶ | if ( ( $end_time <= time() ) && ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$end_time <= time and do {
*$self
}->{"exp_Debug"}
MC/DC0%0/2
$end_time <= time and do {
*$self
}->{"exp_Debug"}
$end_time <= time
do {
*$self
}->{"exp_Debug"}
Truth table33%1/3
A and B
A= $end_time <= timeB= do {
*$self
}->{"exp_Debug"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1554 | 0 | print STDERR "Timed out waiting for an EOF from ${*$self}{exp_Pty_Handle}.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1557 | 7 | my $close_status = $self->close(); | |||||||||||||||||||||||||||||||||||||||||
| 1558 | 7 | ▶ | if ( $close_status && ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$close_status and do {
*$self
}->{"exp_Debug"}
MC/DC0%0/2
$close_status and do {
*$self
}->{"exp_Debug"}
$close_status
do {
*$self
}->{"exp_Debug"}
Truth table33%1/3
A and B
A= $close_statusB= do {
*$self
}->{"exp_Debug"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1559 | 0 | print STDERR "${*$self}{exp_Pty_Handle} closed.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||
| 1562 | # quit now if it isn't a process. | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | 7 | ▶ | return $close_status unless defined( ${*$self}{exp_Pid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1564 | |||||||||||||||||||||||||||||||||||||||||||
| 1565 | # Now give it 15 seconds to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1566 | 7 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1567 | 7 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1568 | 7 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1569 | |||||||||||||||||||||||||||||||||||||||||||
| 1570 | # Stop here if the process dies. | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | 7 | ▶ | if ( defined($returned_pid) && $returned_pid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $returned_pid and $returned_pid
MC/DC0%0/2
defined $returned_pid and $returned_pid
defined $returned_pid
$returned_pid
Truth table33%1/3
A and B
A= defined $returned_pidB= $returned_pid
| |||||||||||||||||||||||||||||||||||||||||||
| 1572 | 7 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1573 | 7 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1574 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1575 | "Pid %d of %s exited, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1576 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1577 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1578 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1580 | 7 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1581 | 7 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1582 | 7 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1584 | 0 | sleep 1; # Keep loop nice. | |||||||||||||||||||||||||||||||||||||||||
| 1585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1586 | |||||||||||||||||||||||||||||||||||||||||||
| 1587 | # Send it a term if it isn't dead. | ||||||||||||||||||||||||||||||||||||||||||
| 1588 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1589 | 0 | print STDERR "${*$self}{exp_Pty_Handle} not exiting, sending TERM.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1591 | 0 | kill TERM => ${*$self}{exp_Pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1592 | |||||||||||||||||||||||||||||||||||||||||||
| 1593 | # Now to be anal retentive.. wait 15 more seconds for it to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | 0 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1595 | 0 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1596 | 0 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1597 | 0 | ▶ | if ( defined($returned_pid) && $returned_pid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $returned_pid and $returned_pid
MC/DC0%0/2
defined $returned_pid and $returned_pid
defined $returned_pid
$returned_pid
Truth table0%0/3
A and B
A= defined $returned_pidB= $returned_pid
| |||||||||||||||||||||||||||||||||||||||||||
| 1598 | 0 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1599 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1600 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1601 | "Pid %d of %s terminated, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1602 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1603 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1604 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1606 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1607 | 0 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1608 | 0 | return $?; | |||||||||||||||||||||||||||||||||||||||||
| 1609 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1610 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 1611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1612 | |||||||||||||||||||||||||||||||||||||||||||
| 1613 | # Since this is a 'soft' close, sending it a -9 would be inappropriate. | ||||||||||||||||||||||||||||||||||||||||||
| 1614 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||||||||||||||||
| 1617 | # 'Make it go away' close. | ||||||||||||||||||||||||||||||||||||||||||
| 1618 | sub hard_close { | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | 167 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hard_close: called CC=18 SCAR=48.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1620 | |||||||||||||||||||||||||||||||||||||||||||
| 1621 | 167 | ▶ | cluck "Closing ${*$self}{exp_Pty_Handle}.\r\n" if ${*$self}{exp_Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||||||||||
| 1623 | # Don't wait for an EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 1624 | 167 | my $close_status = $self->close(); | |||||||||||||||||||||||||||||||||||||||||
| 1625 | 167 | ▶ | if ( $close_status && ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$close_status and do {
*$self
}->{"exp_Debug"}
MC/DC0%0/2
$close_status and do {
*$self
}->{"exp_Debug"}
$close_status
do {
*$self
}->{"exp_Debug"}
Truth table66%2/3
A and B
A= $close_statusB= do {
*$self
}->{"exp_Debug"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1626 | 0 | print STDERR "${*$self}{exp_Pty_Handle} closed.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||
| 1629 | # Return now if handle. | ||||||||||||||||||||||||||||||||||||||||||
| 1630 | 167 | ▶ | return $close_status unless defined( ${*$self}{exp_Pid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1631 | |||||||||||||||||||||||||||||||||||||||||||
| 1632 | # Now give it 5 seconds to die. Less patience here if it won't die. | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | 78 | my $end_time = time() + 5; | |||||||||||||||||||||||||||||||||||||||||
| 1634 | 78 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1635 | 145 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1636 | |||||||||||||||||||||||||||||||||||||||||||
| 1637 | # Stop here if the process dies. | ||||||||||||||||||||||||||||||||||||||||||
| 1638 | 145 | ▶ | if ( defined($returned_pid) && $returned_pid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $returned_pid and $returned_pid
MC/DC50%1/2
defined $returned_pid and $returned_pid
defined $returned_pid
$returned_pid
Truth table66%2/3
A and B
A= defined $returned_pidB= $returned_pid
| |||||||||||||||||||||||||||||||||||||||||||
| 1639 | 78 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1640 | 78 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1641 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1642 | "Pid %d of %s terminated, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1643 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1644 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1645 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1647 | 78 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1648 | 78 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1649 | 78 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1651 | 67 | sleep 1; # Keep loop nice. | |||||||||||||||||||||||||||||||||||||||||
| 1652 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1653 | |||||||||||||||||||||||||||||||||||||||||||
| 1654 | # Send it a term if it isn't dead. | ||||||||||||||||||||||||||||||||||||||||||
| 1655 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1656 | 0 | print STDERR "${*$self}{exp_Pty_Handle} not exiting, sending TERM.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1657 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1658 | 0 | kill TERM => ${*$self}{exp_Pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1659 | |||||||||||||||||||||||||||||||||||||||||||
| 1660 | # wait 15 more seconds for it to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1661 | 0 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1662 | 0 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1663 | 0 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1664 | 0 | ▶ | if ( defined($returned_pid) && $returned_pid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $returned_pid and $returned_pid
MC/DC0%0/2
defined $returned_pid and $returned_pid
defined $returned_pid
$returned_pid
Truth table0%0/3
A and B
A= defined $returned_pidB= $returned_pid
| |||||||||||||||||||||||||||||||||||||||||||
| 1665 | 0 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1666 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1667 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1668 | "Pid %d of %s terminated, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1669 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1670 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1671 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1672 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1673 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1674 | 0 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1675 | 0 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1677 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 1678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1679 | 0 | kill KILL => ${*$self}{exp_Pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1680 | |||||||||||||||||||||||||||||||||||||||||||
| 1681 | # wait 5 more seconds for it to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1682 | 0 | $end_time = time() + 5; | |||||||||||||||||||||||||||||||||||||||||
| 1683 | 0 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1684 | 0 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1685 | 0 | ▶ | if ( defined($returned_pid) && $returned_pid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $returned_pid and $returned_pid
MC/DC0%0/2
defined $returned_pid and $returned_pid
defined $returned_pid
$returned_pid
Truth table0%0/3
A and B
A= defined $returned_pidB= $returned_pid
| |||||||||||||||||||||||||||||||||||||||||||
| 1686 | 0 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1687 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1688 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1689 | "Pid %d of %s killed, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1690 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1691 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1692 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1694 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1695 | 0 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1696 | 0 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1698 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 1699 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1700 | 0 | warn "Pid ${*$self}{exp_Pid} of ${*$self}{exp_Pty_Handle} is HUNG.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1701 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1702 | |||||||||||||||||||||||||||||||||||||||||||
| 1703 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1705 | |||||||||||||||||||||||||||||||||||||||||||
| 1706 | # These should not be called externally. | ||||||||||||||||||||||||||||||||||||||||||
| 1707 | |||||||||||||||||||||||||||||||||||||||||||
| 1708 | sub _init_vars { | ||||||||||||||||||||||||||||||||||||||||||
| 1709 | 126 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_vars: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1710 | |||||||||||||||||||||||||||||||||||||||||||
| 1711 | # for every spawned process or filehandle. | ||||||||||||||||||||||||||||||||||||||||||
| 1712 | 126 | ▶ | ${*$self}{exp_Log_Stdout} = $Expect::Log_Stdout | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1713 | if defined($Expect::Log_Stdout); | ||||||||||||||||||||||||||||||||||||||||||
| 1714 | 126 | ${*$self}{exp_Log_Group} = $Expect::Log_Group; | |||||||||||||||||||||||||||||||||||||||||
| 1715 | 126 | ${*$self}{exp_Debug} = $Expect::Debug; | |||||||||||||||||||||||||||||||||||||||||
| 1716 | 126 | ${*$self}{exp_Exp_Internal} = $Expect::Exp_Internal; | |||||||||||||||||||||||||||||||||||||||||
| 1717 | 126 | ${*$self}{exp_Manual_Stty} = $Expect::Manual_Stty; | |||||||||||||||||||||||||||||||||||||||||
| 1718 | 126 | ${*$self}{exp_Stored_Stty} = 'sane'; | |||||||||||||||||||||||||||||||||||||||||
| 1719 | 126 | ${*$self}{exp_Do_Soft_Close} = $Expect::Do_Soft_Close; | |||||||||||||||||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||||||||||||||||
| 1721 | # sysread doesn't like my or local vars. | ||||||||||||||||||||||||||||||||||||||||||
| 1722 | 126 | ${*$self}{exp_Pty_Buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1723 | |||||||||||||||||||||||||||||||||||||||||||
| 1724 | # Initialize accumulator. | ||||||||||||||||||||||||||||||||||||||||||
| 1725 | 126 | ${*$self}{exp_Max_Accum} = $Expect::Exp_Max_Accum; | |||||||||||||||||||||||||||||||||||||||||
| 1726 | 126 | ${*$self}{exp_Accum} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1727 | 126 | ${*$self}{exp_NoTransfer} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1728 | |||||||||||||||||||||||||||||||||||||||||||
| 1729 | # create empty expect_before & after lists | ||||||||||||||||||||||||||||||||||||||||||
| 1730 | 126 | ${*$self}{exp_expect_before_list} = []; | |||||||||||||||||||||||||||||||||||||||||
| 1731 | 126 | ${*$self}{exp_expect_after_list} = []; | |||||||||||||||||||||||||||||||||||||||||
| 1732 | |||||||||||||||||||||||||||||||||||||||||||
| 1733 | 126 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||||||||||||||||
| 1736 | sub _make_readable { | ||||||||||||||||||||||||||||||||||||||||||
| 1737 | 0 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_readable: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1738 | |||||||||||||||||||||||||||||||||||||||||||
| 1739 | 0 | ▶ | $s = '' if not defined($s); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1740 | 0 | study $s; # Speed things up? | |||||||||||||||||||||||||||||||||||||||||
| 1741 | 0 | $s =~ s/\\/\\\\/g; # So we can tell easily(?) what is a backslash | |||||||||||||||||||||||||||||||||||||||||
| 1742 | 0 | $s =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 1743 | 0 | $s =~ s/\r/\\r/g; | |||||||||||||||||||||||||||||||||||||||||
| 1744 | 0 | $s =~ s/\t/\\t/g; | |||||||||||||||||||||||||||||||||||||||||
| 1745 | 0 | $s =~ s/\'/\\\'/g; # So we can tell whassa quote and whassa notta quote. | |||||||||||||||||||||||||||||||||||||||||
| 1746 | 0 | $s =~ s/\"/\\\"/g; | |||||||||||||||||||||||||||||||||||||||||
| 1747 | |||||||||||||||||||||||||||||||||||||||||||
| 1748 | # Formfeed (does anyone use formfeed?) | ||||||||||||||||||||||||||||||||||||||||||
| 1749 | 0 | $s =~ s/\f/\\f/g; | |||||||||||||||||||||||||||||||||||||||||
| 1750 | 0 | $s =~ s/\010/\\b/g; | |||||||||||||||||||||||||||||||||||||||||
| 1751 | |||||||||||||||||||||||||||||||||||||||||||
| 1752 | # escape control chars high/low, but allow ISO 8859-1 chars | ||||||||||||||||||||||||||||||||||||||||||
| 1753 | 0 | $s =~ s/([\000-\037\177-\237\377])/sprintf("\\%03lo",ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||||
| 1754 | |||||||||||||||||||||||||||||||||||||||||||
| 1755 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 1756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1757 | |||||||||||||||||||||||||||||||||||||||||||
| 1758 | sub _trim_length { | ||||||||||||||||||||||||||||||||||||||||||
| 1759 | 17 | ▶ | my ($self, $string, $length) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim_length: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||
| 1760 | |||||||||||||||||||||||||||||||||||||||||||
| 1761 | # This is sort of a reverse truncation function | ||||||||||||||||||||||||||||||||||||||||||
| 1762 | # Mostly so we don't have to see the full output when we're using | ||||||||||||||||||||||||||||||||||||||||||
| 1763 | # Also used if Max_Accum gets set to limit the size of the accumulator | ||||||||||||||||||||||||||||||||||||||||||
| 1764 | # for matching functions. | ||||||||||||||||||||||||||||||||||||||||||
| 1765 | # exp_internal | ||||||||||||||||||||||||||||||||||||||||||
| 1766 | |||||||||||||||||||||||||||||||||||||||||||
| 1767 | 17 | ▶ | croak('No string passed') if not defined $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1768 | |||||||||||||||||||||||||||||||||||||||||||
| 1769 | # If we're not passed a length (_trim_length is being used for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 1770 | # purposes) AND debug >= 3, don't trim. | ||||||||||||||||||||||||||||||||||||||||||
| 1771 | return ($string) | ||||||||||||||||||||||||||||||||||||||||||
| 1772 | if (defined($self) | ||||||||||||||||||||||||||||||||||||||||||
| 1773 | 15 | ▶ | and ${*$self}{"exp_Debug"} >= 3 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $self and do {
*$self
}->{"exp_Debug"} >= 3 and not defined $length
defined $self and do {
*$self
}->{"exp_Debug"} >= 3
MC/DC0%0/3
defined $self and do {
*$self
}->{"exp_Debug"} >= 3 and not defined $length
defined $self
do {
*$self
}->{"exp_Debug"} >= 3
not defined $length
Truth table50%2/4
A and B and not(C)
A= defined $selfB= do {
*$self
}->{"exp_Debug"} >= 3C= not defined $length
| |||||||||||||||||||||||||||||||||||||||||||
| 1774 | and ( !( defined($length) ) ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 1775 | 15 | ▶ | my $indicate_truncation = ($length ? '' : '...'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1776 | 15 | ▶ | $length ||= 1021; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$length ||= 1021
MC/DC100%1/1
$length ||= 1021
$length
Truth table100%2/2
A
A= $length
| |||||||||||||||||||||||||||||||||||||||||||
| 1777 | 15 | ▶ | return $string if $length >= length $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1778 | |||||||||||||||||||||||||||||||||||||||||||
| 1779 | # We wouldn't want the accumulator to begin with '...' if max_accum is passed | ||||||||||||||||||||||||||||||||||||||||||
| 1780 | # This is because this funct. gets called internally w/ max_accum | ||||||||||||||||||||||||||||||||||||||||||
| 1781 | # and is also used to print information back to the user. | ||||||||||||||||||||||||||||||||||||||||||
| 1782 | 8 | return $indicate_truncation . substr( $string, ( length($string) - $length ), $length ); | |||||||||||||||||||||||||||||||||||||||||
| 1783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1784 | |||||||||||||||||||||||||||||||||||||||||||
| 1785 | sub _print_handles { | ||||||||||||||||||||||||||||||||||||||||||
| 1786 | 4870 | ▶ | my ($self, $print_this) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print_handles: called CC=6 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1787 | |||||||||||||||||||||||||||||||||||||||||||
| 1788 | # Given crap from 'self' and the handles self wants to print to, print to | ||||||||||||||||||||||||||||||||||||||||||
| 1789 | # them. these are indicated by the handle's 'group' | ||||||||||||||||||||||||||||||||||||||||||
| 1790 | 4870 | ▶ | if ( ${*$self}{exp_Log_Group} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1791 | 4870 | foreach my $handle ( @{ ${*$self}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1792 | 0 | ▶ | $print_this = '' unless defined($print_this); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1793 | |||||||||||||||||||||||||||||||||||||||||||
| 1794 | # Appease perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 1795 | print STDERR "Printed '" | ||||||||||||||||||||||||||||||||||||||||||
| 1796 | . $self->_trim_length( _make_readable($print_this) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1797 | 0 | . "' to ${*$handle}{exp_Pty_Handle} from ${*$self}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1798 | 0 | ▶ | if ( ${*$handle}{"exp_Debug"} > 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1799 | 0 | print $handle $print_this; | |||||||||||||||||||||||||||||||||||||||||
| 1800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1802 | |||||||||||||||||||||||||||||||||||||||||||
| 1803 | # If ${*$self}{exp_Pty_Handle} is STDIN this would make it echo. | ||||||||||||||||||||||||||||||||||||||||||
| 1804 | print STDOUT $print_this | ||||||||||||||||||||||||||||||||||||||||||
| 1805 | 4870 | ▶ | if ${*$self}{"exp_Log_Stdout"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1806 | 4870 | $self->print_log_file($print_this); | |||||||||||||||||||||||||||||||||||||||||
| 1807 | 4870 | $| = 1; # This should not be necessary but autoflush() doesn't always work. | |||||||||||||||||||||||||||||||||||||||||
| 1808 | |||||||||||||||||||||||||||||||||||||||||||
| 1809 | 4870 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1810 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1811 | |||||||||||||||||||||||||||||||||||||||||||
| 1812 | sub _get_mode { | ||||||||||||||||||||||||||||||||||||||||||
| 1813 | 0 | ▶ | my ($handle) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_mode: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1814 | |||||||||||||||||||||||||||||||||||||||||||
| 1815 | 0 | my ($fcntl_flags) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1816 | |||||||||||||||||||||||||||||||||||||||||||
| 1817 | # What mode are we opening with? use fcntl to find out. | ||||||||||||||||||||||||||||||||||||||||||
| 1818 | 0 | $fcntl_flags = fcntl( \*{$handle}, Fcntl::F_GETFL, $fcntl_flags ); | |||||||||||||||||||||||||||||||||||||||||
| 1819 | 0 | ▶ | die "fcntl returned undef during exp_init of $handle, $!\r\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1820 | unless defined($fcntl_flags); | ||||||||||||||||||||||||||||||||||||||||||
| 1821 | 0 | ▶ | if ( $fcntl_flags | (Fcntl::O_RDWR) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1822 | 0 | return 'rw'; | |||||||||||||||||||||||||||||||||||||||||
| 1823 | } elsif ( $fcntl_flags | (Fcntl::O_WRONLY) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1824 | 0 | return 'w'; | |||||||||||||||||||||||||||||||||||||||||
| 1825 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1826 | |||||||||||||||||||||||||||||||||||||||||||
| 1827 | # Under Solaris (among others?) O_RDONLY is implemented as 0. so |O_RDONLY would fail. | ||||||||||||||||||||||||||||||||||||||||||
| 1828 | 0 | return 'r'; | |||||||||||||||||||||||||||||||||||||||||
| 1829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1830 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1831 | |||||||||||||||||||||||||||||||||||||||||||
| 1832 | sub _undef { | ||||||||||||||||||||||||||||||||||||||||||
| 1833 | 0 | ▶ | return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_undef: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1834 | |||||||||||||||||||||||||||||||||||||||||||
| 1835 | # Seems a little retarded but &CORE::undef fails in interconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 1836 | # This is used for the default escape sequence function. | ||||||||||||||||||||||||||||||||||||||||||
| 1837 | # w/out the leading & it won't compile. | ||||||||||||||||||||||||||||||||||||||||||
| 1838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1839 | |||||||||||||||||||||||||||||||||||||||||||
| 1840 | # clean up child processes | ||||||||||||||||||||||||||||||||||||||||||
| 1841 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||
| 1842 | 109 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1843 | |||||||||||||||||||||||||||||||||||||||||||
| 1844 | 109 | my $status = $?; # save this as it gets mangled by the terminating spawned children | |||||||||||||||||||||||||||||||||||||||||
| 1845 | 109 | ▶ | if ( ${*$self}{exp_Do_Soft_Close} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1846 | 0 | $self->soft_close(); | |||||||||||||||||||||||||||||||||||||||||
| 1847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1848 | 109 | $self->hard_close(); | |||||||||||||||||||||||||||||||||||||||||
| 1849 | 109 | $? = $status; # restore it. otherwise deleting an Expect object may mangle $?, which is unintuitive | |||||||||||||||||||||||||||||||||||||||||
| 1850 | |||||||||||||||||||||||||||||||||||||||||||
| 1851 | 109 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1852 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1853 | |||||||||||||||||||||||||||||||||||||||||||
| 1854 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1855 | __END__ | ||||||||||||||||||||||||||||||||||||||||||