| 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 | 29 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | package Expect; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 29 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 29 | ▶ | use IO::Pty 1.11; # We need make_slave_controlling_terminal() | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 29 | ▶ | use IO::Tty; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 29 | ▶ | use POSIX qw(:sys_wait_h :unistd_h); # For WNOHANG and isatty | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 29 | ▶ | use Fcntl qw(:DEFAULT); # For checking file handle settings. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 29 | ▶ | use Carp qw(cluck croak carp confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 29 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 29 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 29 | ▶ | use Errno; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 29 | ▶ | use Scalar::Util qw/ looks_like_number /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # This is necessary to make routines within Expect work. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 29 | @Expect::ISA = qw(IO::Pty); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 29 | @Expect::EXPORT = qw(expect exp_continue exp_continue_timeout); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 29 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 29 | $Expect::VERSION = '1.38'; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # These are defaults which may be changed per object, or set as | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # the user wishes. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # This will be unset, since the default behavior differs between | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # spawned processes and initialized filehandles. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # $Expect::Log_Stdout = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 29 | $Expect::Log_Group = 1; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 29 | $Expect::Debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 29 | $Expect::Exp_Max_Accum = 0; # unlimited | |||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | $Expect::Exp_Internal = 0; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 29 | $Expect::IgnoreEintr = 0; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 29 | $Expect::Manual_Stty = 0; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | $Expect::Multiline_Matching = 1; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 29 | $Expect::Do_Soft_Close = 0; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 29 | @Expect::Before_List = (); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 29 | @Expect::After_List = (); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 29 | %Expect::Spawned_PIDs = (); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($version) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | if ( defined($version) && ( $version > $Expect::VERSION ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | if ( ( defined($version) ) && ( $version < 1.03 ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $Expect::VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 151 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 151 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 151 | ▶ | $class = ref($class) if ref($class); # so we can be called as $exp->new() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # Create the pty which we will use to pass process info. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 151 | my ($self) = IO::Pty->new; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 151 | ▶ | die "$class: Could not assign a pty" unless $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 151 | bless $self => $class; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 151 | $self->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # This is defined here since the default is different for | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # initialized handles as opposed to spawned processes. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 151 | ${*$self}{exp_Log_Stdout} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 151 | $self->_init_vars(); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 151 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # we got add'l parms, so pass them to spawn | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 72 | return $self->spawn(@args); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 79 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | ▶ | sub timeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 14 | ▶ | ${*$self}{expect_timeout} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 14 | return ${*$self}{expect_timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 152 | ▶ | sub spawn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=21 SCAR=32.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 152 | my ($class, @cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | # spawn is passed command line args. | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 152 | my $self; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 152 | ▶ | if ( ref($class) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 125 | $self = $class; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 27 | $self = $class->new(); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | croak "Cannot reuse an object with an already spawned command" | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 152 | ▶ | if exists ${*$self}{"exp_Command"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 150 | ${*$self}{"exp_Command"} = \@cmd; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # set up pipe to detect childs exec error | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 150 | ▶ | pipe( FROM_CHILD, TO_PARENT ) or die "Cannot open pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 150 | ▶ | pipe( FROM_PARENT, TO_CHILD ) or die "Cannot open pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 150 | TO_PARENT->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 150 | TO_CHILD->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 150 | eval { fcntl( TO_PARENT, Fcntl::F_SETFD, Fcntl::FD_CLOEXEC ); }; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 150 | my $pid = fork; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 150 | ▶ | unless ( defined($pid) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | warn "Cannot fork: $!" if $^W; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 150 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # parent | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 129 | my $errno; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 129 | ${*$self}{exp_Pid} = $pid; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 129 | close TO_PARENT; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 129 | close FROM_PARENT; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 129 | $self->close_slave(); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 129 | ▶ | $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)
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 129 | close TO_CHILD; # so child gets EOF and can go ahead | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # now wait for child exec (eof due to close-on-exit) or exec error | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 129 | my $errstatus = sysread( FROM_CHILD, $errno, 256 ); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 129 | ▶ | die "Cannot sync with child: $!" if not defined $errstatus; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 129 | close FROM_CHILD; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 129 | ▶ | if ($errstatus) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 14 | $! = $errno + 0; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 14 | ▶ | warn "Cannot exec(@cmd): $!\n" if $^W; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # child | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 21 | close FROM_CHILD; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 21 | close TO_CHILD; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 21 | $self->make_slave_controlling_terminal(); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 21 | ▶ | my $slv = $self->slave() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | or die "Cannot get slave: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 21 | ▶ | $slv->set_raw() if $self->raw_pty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 21 | close($self); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # wait for parent before we detach | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 21 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 21 | my $errstatus = sysread( FROM_PARENT, $buffer, 256 ); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 21 | ▶ | die "Cannot sync with parent: $!" if not defined $errstatus; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 21 | close FROM_PARENT; | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 21 | close(STDIN); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 21 | ▶ | open( STDIN, "<&" . $slv->fileno() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | or die "Couldn't reopen STDIN for reading, $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 21 | close(STDOUT); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | open( STDOUT, ">&" . $slv->fileno() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | or die "Couldn't reopen STDOUT for writing, $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 21 | close(STDERR); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 21 | ▶ | open( STDERR, ">&" . $slv->fileno() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | or die "Couldn't reopen STDERR for writing, $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 21 | { exec(@cmd) }; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | print TO_PARENT $! + 0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | die "Cannot exec(@cmd): $!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | # This is sort of for code compatibility, and to make debugging a little | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # easier. By code compatibility I mean that previously the process's | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # handle was referenced by $process{Pty_Handle} instead of just $process. | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # This is almost like 'naming' the handle to the process. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # I think this also reflects Tcl Expect-like behavior. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 115 | ${*$self}{exp_Pty_Handle} = "spawn id(" . $self->fileno() . ")"; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 115 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | cluck( | |||||||||||||||||||||||||||||||||||||||||
| 193 | "Spawned '@cmd'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | "\t${*$self}{exp_Pty_Handle}\r\n", | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | "\tPid: ${*$self}{exp_Pid}\r\n", | |||||||||||||||||||||||||||||||||||||||||
| 196 | "\tTty: " . $self->SUPER::ttyname() . "\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 115 | $Expect::Spawned_PIDs{ ${*$self}{exp_Pid} } = undef; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 115 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub exp_init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_init: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($class, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # take a filehandle, for use later with expect() or interconnect() . | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # All the functions are written for reading from a tty, so if the naming | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # scheme looks odd, that's why. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | croak "exp_init not passed a file object, stopped" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | unless defined( $self->fileno() ); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $self->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | # Define standard variables.. debug states, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->_init_vars(); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | # Turn of logging. By default we don't want crap from a file to get spewed | ||||||||||||||||||||||||||||||||||||||||||
| 218 | # on screen as we read it. | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ${*$self}{exp_Log_Stdout} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ${*$self}{exp_Pty_Handle} = "handle id(" . $self->fileno() . ")"; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | ${*$self}{exp_Pty_Handle} = "STDIN" if $self->fileno() == fileno(STDIN); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | print STDERR "Initialized ${*$self}{exp_Pty_Handle}.'\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ${*$self}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | # make an alias | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 29 | *init = \&exp_init; | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 231 | # We're happy OOP people. No direct access to stuff. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # For standard read-writeable parameters, we define some autoload magic... | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 29 | my %Writeable_Vars = ( | |||||||||||||||||||||||||||||||||||||||||
| 234 | debug => 'exp_Debug', | ||||||||||||||||||||||||||||||||||||||||||
| 235 | exp_internal => 'exp_Exp_Internal', | ||||||||||||||||||||||||||||||||||||||||||
| 236 | do_soft_close => 'exp_Do_Soft_Close', | ||||||||||||||||||||||||||||||||||||||||||
| 237 | max_accum => 'exp_Max_Accum', | ||||||||||||||||||||||||||||||||||||||||||
| 238 | match_max => 'exp_Max_Accum', | ||||||||||||||||||||||||||||||||||||||||||
| 239 | notransfer => 'exp_NoTransfer', | ||||||||||||||||||||||||||||||||||||||||||
| 240 | log_stdout => 'exp_Log_Stdout', | ||||||||||||||||||||||||||||||||||||||||||
| 241 | log_user => 'exp_Log_Stdout', | ||||||||||||||||||||||||||||||||||||||||||
| 242 | log_group => 'exp_Log_Group', | ||||||||||||||||||||||||||||||||||||||||||
| 243 | manual_stty => 'exp_Manual_Stty', | ||||||||||||||||||||||||||||||||||||||||||
| 244 | restart_timeout_upon_receive => 'exp_Continue', | ||||||||||||||||||||||||||||||||||||||||||
| 245 | raw_pty => 'exp_Raw_Pty', | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 29 | my %Readable_Vars = ( | |||||||||||||||||||||||||||||||||||||||||
| 248 | pid => 'exp_Pid', | ||||||||||||||||||||||||||||||||||||||||||
| 249 | exp_pid => 'exp_Pid', | ||||||||||||||||||||||||||||||||||||||||||
| 250 | exp_match_number => 'exp_Match_Number', | ||||||||||||||||||||||||||||||||||||||||||
| 251 | match_number => 'exp_Match_Number', | ||||||||||||||||||||||||||||||||||||||||||
| 252 | exp_error => 'exp_Error', | ||||||||||||||||||||||||||||||||||||||||||
| 253 | error => 'exp_Error', | ||||||||||||||||||||||||||||||||||||||||||
| 254 | exp_command => 'exp_Command', | ||||||||||||||||||||||||||||||||||||||||||
| 255 | command => 'exp_Command', | ||||||||||||||||||||||||||||||||||||||||||
| 256 | exp_match => 'exp_Match', | ||||||||||||||||||||||||||||||||||||||||||
| 257 | match => 'exp_Match', | ||||||||||||||||||||||||||||||||||||||||||
| 258 | exp_matchlist => 'exp_Matchlist', | ||||||||||||||||||||||||||||||||||||||||||
| 259 | matchlist => 'exp_Matchlist', | ||||||||||||||||||||||||||||||||||||||||||
| 260 | exp_before => 'exp_Before', | ||||||||||||||||||||||||||||||||||||||||||
| 261 | before => 'exp_Before', | ||||||||||||||||||||||||||||||||||||||||||
| 262 | exp_after => 'exp_After', | ||||||||||||||||||||||||||||||||||||||||||
| 263 | after => 'exp_After', | ||||||||||||||||||||||||||||||||||||||||||
| 264 | exp_exitstatus => 'exp_Exit', | ||||||||||||||||||||||||||||||||||||||||||
| 265 | exitstatus => 'exp_Exit', | ||||||||||||||||||||||||||||||||||||||||||
| 266 | exp_pty_handle => 'exp_Pty_Handle', | ||||||||||||||||||||||||||||||||||||||||||
| 267 | pty_handle => 'exp_Pty_Handle', | ||||||||||||||||||||||||||||||||||||||||||
| 268 | exp_logfile => 'exp_Log_File', | ||||||||||||||||||||||||||||||||||||||||||
| 269 | logfile => 'exp_Log_File', | ||||||||||||||||||||||||||||||||||||||||||
| 270 | %Writeable_Vars, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 374 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=13 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 374 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 374 | ▶ | my $type = ref($self) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | or croak "$self is not an object"; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 29 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 374 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 374 | $name =~ s/.*:://; # strip fully-qualified portion | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 374 | ▶ | unless ( exists $Readable_Vars{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | croak "ERROR: cannot find method `$name' in class $type"; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 374 | my $varname = $Readable_Vars{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 374 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 374 | ▶ | $tmp = ${*$self}{$varname} if exists ${*$self}{$varname}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 374 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 90 | ▶ | if ( exists $Writeable_Vars{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 90 | my $ref = ref($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 90 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ${*$self}{$varname} = [@args]; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } elsif ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ${*$self}{$varname} = {@args}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 90 | ${*$self}{$varname} = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | carp "Trying to set read-only variable `$name'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | if $^W; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 374 | my $ref = ref($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 374 | ▶ | return ( wantarray ? @{$tmp} : $tmp ) if ( $ref eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | return ( wantarray ? %{$tmp} : $tmp ) if ( $ref eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 367 | return $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | sub set_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_seq: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my ( $self, $escape_sequence, $function, $params, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | # Set an escape sequence/function combo for a read handle for interconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # Ex: $read_handle->set_seq('',\&function,\@parameters); | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ${ ${*$self}{exp_Function} }{$escape_sequence} = $function; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ${ ${*$self}{exp_Function} }{$escape_sequence} = \&_undef; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ${ ${*$self}{exp_Parameters} }{$escape_sequence} = $params; | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # This'll be a joy to execute. :) | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ( ${*$self}{"exp_Debug"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | print STDERR "Escape seq. '" . $escape_sequence; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | print STDERR "' function for ${*$self}{exp_Pty_Handle} set to '"; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | print STDERR ${ ${*$self}{exp_Function} }{$escape_sequence}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | print STDERR "(" . join( ',', @args ) . ")'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub set_group { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_group: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # Make sure we can read from the read handle | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ( !defined( $args[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ( defined( ${*$self}{exp_Listen_Group} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return @{ ${*$self}{exp_Listen_Group} }; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # Refrain from referencing an undef | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | @{ ${*$self}{exp_Listen_Group} } = (); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $self->_get_mode() !~ 'r' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | warn( | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | "Attempting to set a handle group on ${*$self}{exp_Pty_Handle}, ", | |||||||||||||||||||||||||||||||||||||||||
| 351 | "a non-readable handle!\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | while ( my $write_handle = shift @args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ( $write_handle->_get_mode() !~ 'w' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | warn( | |||||||||||||||||||||||||||||||||||||||||
| 357 | "Attempting to set a non-writeable listen handle ", | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | "${*$write_handle}{exp_Pty_handle} for ", | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | "${*$self}{exp_Pty_Handle}!\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 360 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | push( @{ ${*$self}{exp_Listen_Group} }, $write_handle ); | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 73 | ▶ | sub log_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_file: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 73 | my ($self, $file, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 73 | ▶ | $mode ||= "a"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mode ||= "a"
MC/DC100%1/1
$mode ||= "a"
$mode
Truth table100%2/2
A
A= $mode
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return ( ${*$self}{exp_Log_File} ) | |||||||||||||||||||||||||||||||||||||||||
| 371 | 73 | ▶ | if @_ < 2; # we got no param, return filehandle | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | # $e->log_file(undef) is an acceptable call hence we need to check the number of parameters here | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 73 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 10 | close( ${*$self}{exp_Log_File} ); | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 73 | ${*$self}{exp_Log_File} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 73 | ▶ | return if ( not $file ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 44 | my $fh = $file; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 44 | ▶ | if ( not ref($file) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | # it's a filename | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 26 | ▶ | $fh = IO::File->new( $file, $mode ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | or croak "Cannot open logfile $file: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 44 | ▶ | if ( ref($file) ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 26 | ▶ | croak "Given logfile doesn't have a 'print' method" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | if not $fh->can("print"); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 26 | $fh->autoflush(1); # so logfile is up to date | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 44 | ${*$self}{exp_Log_File} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 44 | return $fh; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | # I'm going to leave this here in case I might need to change something. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # Previously this was calling `stty`, in a most bastardized manner. | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub exp_stty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_stty: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my ($mode) = "@_"; | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | return unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if ( not defined $INC{"IO/Stty.pm"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | carp "IO::Stty not installed, cannot change mode"; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ( ${*$self}{"exp_Debug"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | print STDERR "Setting ${*$self}{exp_Pty_Handle} to tty mode '$mode'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | unless ( POSIX::isatty($self) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | warn "${*$self}{exp_Pty_Handle} is not a tty. Not changing mode"; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | return ''; # No undef to avoid warnings elsewhere. | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | IO::Stty::stty( $self, split( /\s/, $mode ) ); | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 29 | *stty = \&exp_stty; | |||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | # If we want to clear the buffer. Otherwise Accum will grow during send_slow | ||||||||||||||||||||||||||||||||||||||||||
| 424 | # etc. and contain the remainder after matches. | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 41 | ▶ | sub clear_accum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_accum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 41 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 41 | return $self->set_accum(''); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 61 | ▶ | sub set_accum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_accum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 61 | my ($self, $accum) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 61 | my $old_accum = ${*$self}{exp_Accum}; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 61 | ${*$self}{exp_Accum} = $accum; | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | # return the contents of the accumulator. | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 61 | return $old_accum; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | ▶ | sub get_accum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_accum: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | return ${*$self}{exp_Accum}; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 445 | # define constants for pattern subs | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 11343 | ▶ | sub exp_continue {"exp_continue"} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_continue: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 5473 | ▶ | sub exp_continue_timeout {"exp_continue_timeout"} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exp_continue_timeout: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 450 | # Expect on multiple objects at once. | ||||||||||||||||||||||||||||||||||||||||||
| 451 | # | ||||||||||||||||||||||||||||||||||||||||||
| 452 | # Call as Expect::expect($timeout, -i => \@exp_list, @patternlist, | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # -i => $exp, @pattern_list, ...); | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # or $exp->expect($timeout, @patternlist, -i => \@exp_list, @patternlist, | ||||||||||||||||||||||||||||||||||||||||||
| 455 | # -i => $exp, @pattern_list, ...); | ||||||||||||||||||||||||||||||||||||||||||
| 456 | # | ||||||||||||||||||||||||||||||||||||||||||
| 457 | # Patterns are arrays that consist of | ||||||||||||||||||||||||||||||||||||||||||
| 458 | # [ $pattern_type, $pattern, $sub, @subparms ] | ||||||||||||||||||||||||||||||||||||||||||
| 459 | # | ||||||||||||||||||||||||||||||||||||||||||
| 460 | # Optional $pattern_type is '-re' (RegExp, default) or '-ex' (exact); | ||||||||||||||||||||||||||||||||||||||||||
| 461 | # | ||||||||||||||||||||||||||||||||||||||||||
| 462 | # $sub is optional CODE ref, which is called as &{$sub}($exp, @subparms) | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # if pattern matched; may return exp_continue or exp_continue_timeout. | ||||||||||||||||||||||||||||||||||||||||||
| 464 | # | ||||||||||||||||||||||||||||||||||||||||||
| 465 | # Old-style syntax (pure pattern strings with optional type) also supported. | ||||||||||||||||||||||||||||||||||||||||||
| 466 | # | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 5521 | ▶ | sub expect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expect: called CC=47 SCAR=55.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 5521 | my $self; | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 5521 | ▶ | print STDERR ("expect(@_) called...\n") if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 5521 | ▶ | if ( defined( $_[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 5521 | ▶ | 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")
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 5521 | $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 475 | } elsif ( $_[0] eq 'Expect' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | shift; # or as Expect->expect | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 5521 | ▶ | croak "expect(): not enough arguments, should be expect(timeout, [patterns...])" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 5521 | my $timeout; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 5521 | ▶ | if ( looks_like_number($_[0]) or not defined $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&looks_like_number($_[0]) or not defined $_[0]
MC/DC100%2/2
&looks_like_number($_[0]) or not defined $_[0]
&looks_like_number($_[0])
not defined $_[0]
Truth table100%3/3
A or not(B)
A= &looks_like_number($_[0])B= not defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 5513 | $timeout = shift; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 8 | $timeout = $self->timeout; | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 5521 | my $timeout_hook = undef; | |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 5521 | my @object_list; | |||||||||||||||||||||||||||||||||||||||||
| 491 | my %patterns; | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 5521 | my @pattern_list; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 5521 | my @timeout_list; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 5521 | my $curr_list; | |||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 5521 | ▶ | if ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 5521 | $curr_list = [$self]; | |||||||||||||||||||||||||||||||||||||||||
| 499 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | # called directly, so first parameter must be '-i' to establish | ||||||||||||||||||||||||||||||||||||||||||
| 502 | # object list. | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $curr_list = []; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | croak | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | "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." | ||||||||||||||||||||||||||||||||||||||||||
| 506 | if ( $_[0] ne '-i' ); | ||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | # Let's make a list of patterns wanting to be evaled as regexps. | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 5521 | my $parm; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 5521 | my $parm_nr = 1; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 5521 | ▶ | while ( defined( $parm = shift ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 16429 | ▶ | print STDERR ("expect(): handling param '$parm'...\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 16429 | ▶ | if ( ref($parm) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 16310 | ▶ | if ( ref($parm) eq 'Regexp' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | push @pattern_list, [ $parm_nr, '-re', $parm, undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | elsif ( ref($parm) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 520 | # if ( ref($parm) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 16309 | my $err = _add_patterns_to_list( | |||||||||||||||||||||||||||||||||||||||||
| 522 | \@pattern_list, \@timeout_list, | ||||||||||||||||||||||||||||||||||||||||||
| 523 | $parm_nr, $parm | ||||||||||||||||||||||||||||||||||||||||||
| 524 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 16309 | ▶ | carp( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | "expect(): Warning: multiple `timeout' patterns (", | ||||||||||||||||||||||||||||||||||||||||||
| 527 | scalar(@timeout_list), ").\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 528 | ) if @timeout_list > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 16309 | ▶ | $timeout_hook = $timeout_list[-1] if $timeout_list[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 16309 | ▶ | croak $err if $err; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 16309 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | croak("expect(): Unknown pattern ref $parm"); | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | # not a ref, is an option or raw pattern | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 119 | ▶ | if ( substr( $parm, 0, 1 ) eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | # it's an option | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 22 | ▶ | print STDERR ("expect(): handling option '$parm'...\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 22 | ▶ | if ( $parm eq '-i' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | # first add collected patterns to object list | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ( scalar(@$curr_list) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | push @object_list, $curr_list | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if not exists $patterns{"$curr_list"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | push @{ $patterns{"$curr_list"} }, @pattern_list; | |||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | @pattern_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | # now put parm(s) into current object list | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | if ( ref( $_[0] ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $curr_list = shift; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $curr_list = [shift]; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | ▶ | } 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | or $parm eq '-ex' ) | ||||||||||||||||||||||||||||||||||||||||||
| 561 | { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 22 | ▶ | if ( ref( $_[1] ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | push @pattern_list, [ $parm_nr, $parm, shift, shift ]; | |||||||||||||||||||||||||||||||||||||||||
| 564 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 22 | push @pattern_list, [ $parm_nr, $parm, shift, undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | 22 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | croak("Unknown option $parm"); | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | # a plain pattern, check if it is followed by a CODE ref | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 97 | ▶ | if ( ref( $_[0] ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | if ( $parm eq 'timeout' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | push @timeout_list, shift; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | carp( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | "expect(): Warning: multiple `timeout' patterns (", | ||||||||||||||||||||||||||||||||||||||||||
| 579 | scalar(@timeout_list), | ||||||||||||||||||||||||||||||||||||||||||
| 580 | ").\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 581 | ) if @timeout_list > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | $timeout_hook = $timeout_list[-1] if $timeout_list[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | } elsif ( $parm eq 'eof' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | push @pattern_list, [ $parm_nr, "-$parm", undef, shift ]; | |||||||||||||||||||||||||||||||||||||||||
| 585 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | push @pattern_list, [ $parm_nr, '-ex', $parm, shift ]; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 97 | ▶ | print STDERR ("expect(): exact match '$parm'...\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 97 | push @pattern_list, [ $parm_nr, '-ex', $parm, undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 97 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | # add rest of collected patterns to object list | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 5521 | ▶ | carp "expect(): Empty object list" unless $curr_list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 5521 | ▶ | push @object_list, $curr_list if not exists $patterns{"$curr_list"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 5521 | push @{ $patterns{"$curr_list"} }, @pattern_list; | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 5521 | ▶ | my $debug = $self ? ${*$self}{exp_Debug} : $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 5521 | ▶ | my $internal = $self ? ${*$self}{exp_Exp_Internal} : $Expect::Exp_Internal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | # now start matching... | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 5521 | ▶ | if (@Expect::Before_List) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | if ( $debug or $internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | _multi_expect( 0, undef, @Expect::Before_List ); | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 5521 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | if ( $debug or $internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 5521 | my @ret; | |||||||||||||||||||||||||||||||||||||||||
| 617 | @ret = _multi_expect( | ||||||||||||||||||||||||||||||||||||||||||
| 618 | $timeout, $timeout_hook, | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 5521 | map { [ $_, @{ $patterns{"$_"} } ] } @object_list | |||||||||||||||||||||||||||||||||||||||||
| 620 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 5521 | ▶ | if (@Expect::After_List) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | if ( $debug or $internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | _multi_expect( 0, undef, @Expect::After_List ); | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 5521 | ▶ | return wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 632 | # the real workhorse | ||||||||||||||||||||||||||||||||||||||||||
| 633 | # | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 5521 | ▶ | sub _multi_expect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multi_expect: called CC=109 SCAR=63.5
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 5521 | my ($timeout, $timeout_hook, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 5521 | ▶ | if ($timeout_hook) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 5415 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | unless ( ref($timeout_hook) eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||
| 640 | or ref($timeout_hook) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | 5521 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 644 | 5521 | my @patterns = @{$pat}[ 1 .. $#{$pat} ]; | |||||||||||||||||||||||||||||||||||||||||
| 645 | 5521 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 646 | 5521 | ${*$exp}{exp_New_Data} = 1; # first round we always try to match | |||||||||||||||||||||||||||||||||||||||||
| 647 | 5521 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | 5521 | and ${*$exp}{"exp_Max_Accum"} ) | |||||||||||||||||||||||||||||||||||||||||
| 649 | { | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ${*$exp}{exp_Accum} = $exp->_trim_length( | |||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ${*$exp}{exp_Max_Accum} | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 5521 | ▶ | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | "${*$exp}{exp_Pty_Handle}: beginning expect.\r\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | "\tTimeout: ", | ||||||||||||||||||||||||||||||||||||||||||
| 658 | ( defined($timeout) ? $timeout : "unlimited" ), | ||||||||||||||||||||||||||||||||||||||||||
| 659 | " seconds.\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 660 | "\tCurrent time: " . localtime() . "\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 661 | ) if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | # What are we expecting? What do you expect? :-) | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 5521 | ▶ | if ( ${*$exp}{exp_Exp_Internal} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | print STDERR "${*$exp}{exp_Pty_Handle}: list of patterns:\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | foreach my $pattern (@patterns) { | |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | ' ', | ||||||||||||||||||||||||||||||||||||||||||
| 669 | defined( $pattern->[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 670 | ? '#' . $pattern->[0] . ': ' | ||||||||||||||||||||||||||||||||||||||||||
| 671 | : '', | ||||||||||||||||||||||||||||||||||||||||||
| 672 | $pattern->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 673 | " `", | ||||||||||||||||||||||||||||||||||||||||||
| 674 | _make_readable( $pattern->[2] ), | ||||||||||||||||||||||||||||||||||||||||||
| 675 | "'\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 676 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | print STDERR "\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | 5521 | my $successful_pattern; | |||||||||||||||||||||||||||||||||||||||||
| 684 | my $exp_matched; | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 5521 | my $err; | |||||||||||||||||||||||||||||||||||||||||
| 686 | 5521 | my $before; | |||||||||||||||||||||||||||||||||||||||||
| 687 | 5521 | my $after; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 5521 | my $match; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 5521 | my @matchlist; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | # Set the last loop time to now for time comparisons at end of loop. | ||||||||||||||||||||||||||||||||||||||||||
| 692 | 5521 | my $start_loop_time = time(); | |||||||||||||||||||||||||||||||||||||||||
| 693 | 5521 | my $exp_cont = 1; | |||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | READLOOP: | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 5521 | ▶ | while ($exp_cont) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 11270 | $exp_cont = 1; | |||||||||||||||||||||||||||||||||||||||||
| 698 | 11270 | $err = ""; | |||||||||||||||||||||||||||||||||||||||||
| 699 | 11270 | my $rmask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 11270 | my $time_left = undef; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 11270 | ▶ | if ( defined $timeout ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 11267 | $time_left = $timeout - ( time() - $start_loop_time ); | |||||||||||||||||||||||||||||||||||||||||
| 703 | 11267 | ▶ | $time_left = 0 if $time_left < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 11270 | $exp_matched = undef; | |||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | # Test for a match first so we can test the current Accum w/out | ||||||||||||||||||||||||||||||||||||||||||
| 709 | # worrying about an EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 11270 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 712 | 11270 | my @patterns = @{$pat}[ 1 .. $#{$pat} ]; | |||||||||||||||||||||||||||||||||||||||||
| 713 | 11270 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | # build mask for select in next section... | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 11270 | my $fn = $exp->fileno(); | |||||||||||||||||||||||||||||||||||||||||
| 717 | 11270 | ▶ | vec( $rmask, $fn, 1 ) = 1 if defined $fn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 11270 | ▶ | next unless ${*$exp}{exp_New_Data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | # clear error status | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 11222 | ${*$exp}{exp_Error} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 723 | 11222 | ${*$exp}{exp_After} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 11222 | ${*$exp}{exp_Match_Number} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 725 | 11222 | ${*$exp}{exp_Match} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | # This could be huge. We should attempt to do something | ||||||||||||||||||||||||||||||||||||||||||
| 728 | # about this. Because the output is used for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 729 | # I'm of the opinion that showing smaller amounts if the | ||||||||||||||||||||||||||||||||||||||||||
| 730 | # total is huge should be ok. | ||||||||||||||||||||||||||||||||||||||||||
| 731 | # Thus the 'trim_length' | ||||||||||||||||||||||||||||||||||||||||||
| 732 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | "\r\n${*$exp}{exp_Pty_Handle}: Does `", | |||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $exp->_trim_length( _make_readable( ${*$exp}{exp_Accum} ) ), | |||||||||||||||||||||||||||||||||||||||||
| 735 | "'\r\nmatch:\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 11222 | ▶ | ) if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | # we don't keep the parameter number anymore | ||||||||||||||||||||||||||||||||||||||||||
| 739 | # (clashes with before & after), instead the parameter number is | ||||||||||||||||||||||||||||||||||||||||||
| 740 | # stored inside the pattern; we keep the pattern ref | ||||||||||||||||||||||||||||||||||||||||||
| 741 | # and look up the number later. | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 11222 | foreach my $pattern (@patterns) { | |||||||||||||||||||||||||||||||||||||||||
| 743 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 744 | " pattern", | ||||||||||||||||||||||||||||||||||||||||||
| 745 | defined( $pattern->[0] ) ? ' #' . $pattern->[0] : '', | ||||||||||||||||||||||||||||||||||||||||||
| 746 | ": ", | ||||||||||||||||||||||||||||||||||||||||||
| 747 | $pattern->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 748 | " `", | ||||||||||||||||||||||||||||||||||||||||||
| 749 | _make_readable( $pattern->[2] ), | ||||||||||||||||||||||||||||||||||||||||||
| 750 | "'? " | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 16925 | ▶ | ) if ( ${*$exp}{exp_Exp_Internal} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | # Matching exactly | ||||||||||||||||||||||||||||||||||||||||||
| 754 | 16925 | ▶ | if ( $pattern->[1] eq '-ex' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | my $match_index = | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 133 | index( ${*$exp}{exp_Accum}, $pattern->[2] ); | |||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | # We matched if $match_index > -1 | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 133 | ▶ | if ( $match_index > -1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | $before = | ||||||||||||||||||||||||||||||||||||||||||
| 761 | 34 | substr( ${*$exp}{exp_Accum}, 0, $match_index ); | |||||||||||||||||||||||||||||||||||||||||
| 762 | $match = substr( | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 34 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 764 | 34 | $match_index, length( $pattern->[2] ) | |||||||||||||||||||||||||||||||||||||||||
| 765 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 766 | $after = substr( | ||||||||||||||||||||||||||||||||||||||||||
| 767 | 34 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 768 | 34 | $match_index + length( $pattern->[2] ) | |||||||||||||||||||||||||||||||||||||||||
| 769 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 34 | ${*$exp}{exp_Before} = $before; | |||||||||||||||||||||||||||||||||||||||||
| 771 | 34 | ${*$exp}{exp_Match} = $match; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 34 | ${*$exp}{exp_After} = $after; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 34 | ${*$exp}{exp_Match_Number} = $pattern->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 774 | 34 | $exp_matched = $exp; | |||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||
| 776 | } elsif ( $pattern->[1] eq '-re' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 11216 | ▶ | if ($Expect::Multiline_Matching) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | @matchlist = | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 11202 | ( ${*$exp}{exp_Accum} =~ m/($pattern->[2])/m); | |||||||||||||||||||||||||||||||||||||||||
| 781 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 782 | @matchlist = | ||||||||||||||||||||||||||||||||||||||||||
| 783 | 14 | ( ${*$exp}{exp_Accum} =~ m/($pattern->[2])/); | |||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||
| 785 | 11216 | ▶ | if (@matchlist) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | # Matching regexp | ||||||||||||||||||||||||||||||||||||||||||
| 788 | 5503 | $match = shift @matchlist; | |||||||||||||||||||||||||||||||||||||||||
| 789 | 5503 | my $start = index ${*$exp}{exp_Accum}, $match; | |||||||||||||||||||||||||||||||||||||||||
| 790 | 5503 | ▶ | die 'The match could not be found' if $start == -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 5503 | $before = substr ${*$exp}{exp_Accum}, 0, $start; | |||||||||||||||||||||||||||||||||||||||||
| 792 | 5503 | $after = substr ${*$exp}{exp_Accum}, $start + length($match); | |||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | 5503 | ${*$exp}{exp_Before} = $before; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 5503 | ${*$exp}{exp_Match} = $match; | |||||||||||||||||||||||||||||||||||||||||
| 796 | 5503 | ${*$exp}{exp_After} = $after; | |||||||||||||||||||||||||||||||||||||||||
| 797 | #pop @matchlist; # remove kludged empty bracket from end | ||||||||||||||||||||||||||||||||||||||||||
| 798 | 5503 | @{ ${*$exp}{exp_Matchlist} } = @matchlist; | |||||||||||||||||||||||||||||||||||||||||
| 799 | 5503 | ${*$exp}{exp_Match_Number} = $pattern->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 800 | 5503 | $exp_matched = $exp; | |||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 802 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | # 'timeout' or 'eof' | ||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | 16925 | ▶ | if ($exp_matched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | 5487 | ${*$exp}{exp_Accum} = $after | |||||||||||||||||||||||||||||||||||||||||
| 809 | 5537 | ▶ | unless ${*$exp}{exp_NoTransfer}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | print STDERR "YES!!\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 5537 | ▶ | if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 813 | " Before match string: `", | ||||||||||||||||||||||||||||||||||||||||||
| 814 | $exp->_trim_length( _make_readable( ($before) ) ), | ||||||||||||||||||||||||||||||||||||||||||
| 815 | "'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 816 | " Match string: `", | ||||||||||||||||||||||||||||||||||||||||||
| 817 | _make_readable($match), | ||||||||||||||||||||||||||||||||||||||||||
| 818 | "'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 819 | " After match string: `", | ||||||||||||||||||||||||||||||||||||||||||
| 820 | $exp->_trim_length( _make_readable( ($after) ) ), | ||||||||||||||||||||||||||||||||||||||||||
| 821 | "'\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 822 | " Matchlist: (", | ||||||||||||||||||||||||||||||||||||||||||
| 823 | join( | ||||||||||||||||||||||||||||||||||||||||||
| 824 | ", ", | ||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | map { "`" . $exp->_trim_length( _make_readable( ($_) ) ) . "'" } @matchlist, | |||||||||||||||||||||||||||||||||||||||||
| 826 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 827 | ")\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 5537 | ▶ | ) if ( ${*$exp}{exp_Exp_Internal} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | # call hook function if defined | ||||||||||||||||||||||||||||||||||||||||||
| 831 | 5537 | ▶ | if ( $pattern->[3] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 833 | "Calling hook $pattern->[3]...\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 834 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 5481 | if ( ${*$exp}{exp_Exp_Internal} | |||||||||||||||||||||||||||||||||||||||||
| 836 | 5481 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | 5481 | ▶ | if ( $#{$pattern} > 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | # call with parameters if given | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | $exp_cont = &{ $pattern->[3] }( $exp, @{$pattern}[ 4 .. $#{$pattern} ] ); | |||||||||||||||||||||||||||||||||||||||||
| 841 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 842 | 5481 | $exp_cont = &{ $pattern->[3] }($exp); | |||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 5537 | ▶ | if ( $exp_cont and $exp_cont eq exp_continue ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$exp_cont and $exp_cont eq exp_continue()
MC/DC100%2/2
$exp_cont and $exp_cont eq exp_continue()
$exp_cont
$exp_cont eq exp_continue()
Truth table100%3/3
A and B
A= $exp_contB= $exp_cont eq exp_continue()
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | print STDERR ("Continuing expect, restarting timeout...\r\n") | ||||||||||||||||||||||||||||||||||||||||||
| 847 | 70 | if ( ${*$exp}{exp_Exp_Internal} | |||||||||||||||||||||||||||||||||||||||||
| 848 | 70 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 849 | 70 | $start_loop_time = time(); # restart timeout count | |||||||||||||||||||||||||||||||||||||||||
| 850 | 70 | next READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 851 | ▶ | } elsif ( $exp_cont | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/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 table66%2/3
A and B
A= $exp_contB= $exp_cont eq exp_continue_timeout()
| |||||||||||||||||||||||||||||||||||||||||||
| 852 | and $exp_cont eq exp_continue_timeout ) | ||||||||||||||||||||||||||||||||||||||||||
| 853 | { | ||||||||||||||||||||||||||||||||||||||||||
| 854 | print STDERR ("Continuing expect...\r\n") | ||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | if ( ${*$exp}{exp_Exp_Internal} | |||||||||||||||||||||||||||||||||||||||||
| 856 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | next READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||
| 859 | 5467 | last READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 11388 | ▶ | print STDERR "No.\r\n" if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | 5685 | ▶ | print STDERR "\r\n" if ${*$exp}{exp_Exp_Internal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | # don't have to match again until we get new data | ||||||||||||||||||||||||||||||||||||||||||
| 866 | 5685 | ${*$exp}{exp_New_Data} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||
| 868 | } # End of matching section | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | # No match, let's see what is pending on the filehandles... | ||||||||||||||||||||||||||||||||||||||||||
| 871 | 5733 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 872 | "Waiting for new data (", | ||||||||||||||||||||||||||||||||||||||||||
| 873 | defined($time_left) ? $time_left : 'unlimited', | ||||||||||||||||||||||||||||||||||||||||||
| 874 | " seconds)...\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 875 | ) if ( $Expect::Exp_Internal or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||||
| 876 | 5733 | my $nfound; | |||||||||||||||||||||||||||||||||||||||||
| 877 | SELECT: { | ||||||||||||||||||||||||||||||||||||||||||
| 878 | 5733 | $nfound = select( $rmask, undef, undef, $time_left ); | |||||||||||||||||||||||||||||||||||||||||
| 879 | 5733 | ▶ | if ( $nfound < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 880 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | if ( $Expect::Exp_Internal or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | next SELECT; | |||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||
| 885 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | if ( $Expect::Exp_Internal or $Expect::Debug ); | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | # returned error | ||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | $err = "4:$!"; | |||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | last READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | # go until we don't find something (== timeout). | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 5733 | ▶ | if ( $nfound == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | # No pattern, no EOF. Did we time out? | ||||||||||||||||||||||||||||||||||||||||||
| 898 | 77 | $err = "1:TIMEOUT"; | |||||||||||||||||||||||||||||||||||||||||
| 899 | 77 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 900 | 77 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 901 | 77 | $before = ${*$exp}{exp_Before} = ${*$exp}{exp_Accum}; | |||||||||||||||||||||||||||||||||||||||||
| 902 | 77 | ▶ | next if not defined $exp->fileno(); # skip already closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 903 | 77 | ▶ | ${*$exp}{exp_Error} = $err unless ${*$exp}{exp_Error}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||
| 906 | 77 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 907 | if ( $Expect::Debug or $Expect::Exp_Internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 908 | 77 | ▶ | if ($timeout_hook) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 51 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 51 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | if ( $Expect::Debug or $Expect::Exp_Internal ); | ||||||||||||||||||||||||||||||||||||||||||
| 912 | 51 | ▶ | if ( ref($timeout_hook) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | $ret = &{$timeout_hook}( $params[0]->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 914 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 915 | 51 | ▶ | if ( $#{$timeout_hook} > 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $ret = &{ $timeout_hook->[3] }( | |||||||||||||||||||||||||||||||||||||||||
| 917 | $params[0]->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | @{$timeout_hook}[ 4 .. $#{$timeout_hook} ] | |||||||||||||||||||||||||||||||||||||||||
| 919 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 920 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 921 | 51 | $ret = &{ $timeout_hook->[3] }( $params[0]->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||
| 924 | 51 | ▶ | 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()
| |||||||||||||||||||||||||||||||||||||||||||
| 925 | 48 | $start_loop_time = time(); # restart timeout count | |||||||||||||||||||||||||||||||||||||||||
| 926 | 48 | next READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||
| 929 | 29 | last READLOOP; | |||||||||||||||||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | 5656 | my @bits = split( //, unpack( 'b*', $rmask ) ); | |||||||||||||||||||||||||||||||||||||||||
| 933 | 5656 | foreach my $pat (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 934 | 5656 | foreach my $exp ( @{ $pat->[0] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 935 | 5656 | ▶ | next if not defined $exp->fileno(); # skip already closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 936 | 5656 | ▶ | if ( $bits[ $exp->fileno() ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: new data.\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 938 | if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | # read in what we found. | ||||||||||||||||||||||||||||||||||||||||||
| 941 | 5656 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 942 | 5656 | my $nread = sysread( $exp, $buffer, 2048 ); | |||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | # Make errors (nread undef) show up as EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 945 | 5656 | ▶ | $nread = 0 unless defined($nread); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | 5656 | ▶ | if ( $nread == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: EOF\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 949 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 950 | 25 | $before = ${*$exp}{exp_Before} = $exp->clear_accum(); | |||||||||||||||||||||||||||||||||||||||||
| 951 | 25 | $err = "2:EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 952 | 25 | ${*$exp}{exp_Error} = $err; | |||||||||||||||||||||||||||||||||||||||||
| 953 | 25 | ${*$exp}{exp_Has_EOF} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 954 | 25 | $exp_cont = undef; | |||||||||||||||||||||||||||||||||||||||||
| 955 | 25 | foreach my $eof_pat ( grep { $_->[1] eq '-eof' } @{$pat}[ 1 .. $#{$pat} ] ) { | |||||||||||||||||||||||||||||||||||||||||
| 956 | 10 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 957 | 10 | ▶ | print STDERR ( "Calling EOF hook $eof_pat->[3]...\r\n", ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 958 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 10 | ▶ | if ( $#{$eof_pat} > 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||
| 961 | # call with parameters if given | ||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | $ret = &{ $eof_pat->[3] }( $exp, @{$eof_pat}[ 4 .. $#{$eof_pat} ] ); | |||||||||||||||||||||||||||||||||||||||||
| 963 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 964 | 10 | $ret = &{ $eof_pat->[3] }($exp); | |||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||
| 966 | 10 | ▶ | 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()
| |||||||||||||||||||||||||||||||||||||||||||
| 967 | and ( $ret eq exp_continue | ||||||||||||||||||||||||||||||||||||||||||
| 968 | or $ret eq exp_continue_timeout ) | ||||||||||||||||||||||||||||||||||||||||||
| 969 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 970 | { | ||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | $exp_cont = $ret; | |||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | # is it dead? | ||||||||||||||||||||||||||||||||||||||||||
| 976 | 25 | ▶ | if ( defined( ${*$exp}{exp_Pid} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 977 | my $ret = | ||||||||||||||||||||||||||||||||||||||||||
| 978 | 25 | waitpid( ${*$exp}{exp_Pid}, POSIX::WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 979 | 25 | ▶ | if ( $ret == ${*$exp}{exp_Pid} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 980 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 981 | "%s: exit(0x%02X)\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | ${*$exp}{exp_Pty_Handle}, $? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 983 | ) if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 984 | 25 | $err = "3:Child PID ${*$exp}{exp_Pid} exited with status $?"; | |||||||||||||||||||||||||||||||||||||||||
| 985 | 25 | ${*$exp}{exp_Error} = $err; | |||||||||||||||||||||||||||||||||||||||||
| 986 | 25 | ${*$exp}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 987 | 25 | delete $Expect::Spawned_PIDs{ ${*$exp}{exp_Pid} }; | |||||||||||||||||||||||||||||||||||||||||
| 988 | 25 | ${*$exp}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: closing...\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 992 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 993 | 25 | $exp->hard_close(); | |||||||||||||||||||||||||||||||||||||||||
| 994 | 25 | next; | |||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | ▶ | print STDERR ("${*$exp}{exp_Pty_Handle}: read $nread byte(s).\r\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 997 | if ($Expect::Debug); | ||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | # ugly hack for broken solaris ttys that spew <blank><backspace> | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | # into our pretty output | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | 5631 | ▶ | $buffer =~ s/ \cH//g if not ${*$exp}{exp_Raw_Pty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||
| 1003 | # Append it to the accumulator. | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | 5631 | ${*$exp}{exp_Accum} .= $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 1005 | 5631 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 5631 | and ${*$exp}{exp_Max_Accum} ) | |||||||||||||||||||||||||||||||||||||||||
| 1007 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | 0 | ${*$exp}{exp_Accum} = $exp->_trim_length( | |||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | ${*$exp}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | ${*$exp}{exp_Max_Accum} | |||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | 5631 | ${*$exp}{exp_New_Data} = 1; # next round we try to match again | |||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||
| 1015 | $exp_cont = exp_continue | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | 5631 | if ( exists ${*$exp}{exp_Continue} | |||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||
| 1019 | # Now propagate what we have read to other listeners... | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | 5631 | $exp->_print_handles($buffer); | |||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | # End handle reading section. | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | } # end read loop | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | $start_loop_time = time() # restart timeout count | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | 5656 | ▶ | 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()
| |||||||||||||||||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||
| 1030 | # End READLOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||||||||||
| 1032 | # Post loop. Do we have anything? | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | # Tell us status | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | 5521 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | ▶ | if ($exp_matched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1036 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1037 | "Returning from expect ", | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | 0 | ▶ | ${*$exp_matched}{exp_Error} ? 'un' : '', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1039 | "successfully.", | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | ${*$exp_matched}{exp_Error} | |||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | ? "\r\n Error: ${*$exp_matched}{exp_Error}." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1042 | : '', | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | "\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1044 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1045 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | print STDERR ("Returning from expect with TIMEOUT or EOF\r\n"); | |||||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1048 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | print STDERR " ${*$exp_matched}{exp_Pty_Handle}: accumulator: `"; | |||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | ▶ | if ( ${*$exp_matched}{exp_Error} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1051 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | $exp_matched->_trim_length( _make_readable( ${*$exp_matched}{exp_Before} ) ), | |||||||||||||||||||||||||||||||||||||||||
| 1053 | "'\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1055 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | print STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | $exp_matched->_trim_length( _make_readable( ${*$exp_matched}{exp_Accum} ) ), | |||||||||||||||||||||||||||||||||||||||||
| 1058 | "'\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||
| 1064 | 5521 | ▶ | if ($exp_matched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1065 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | ? ( | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | 5467 | ${*$exp_matched}{exp_Match_Number}, ${*$exp_matched}{exp_Error}, | |||||||||||||||||||||||||||||||||||||||||
| 1068 | 5467 | ${*$exp_matched}{exp_Match}, ${*$exp_matched}{exp_Before}, | |||||||||||||||||||||||||||||||||||||||||
| 1069 | 5467 | ${*$exp_matched}{exp_After}, $exp_matched, | |||||||||||||||||||||||||||||||||||||||||
| 1070 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 1071 | 0 | ▶ | : ${*$exp_matched}{exp_Match_Number}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||||||||||||||||
| 1074 | 54 | ▶ | return wantarray ? ( undef, $err, undef, $before, undef, undef ) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | # Patterns are arrays that consist of | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | # [ $pattern_type, $pattern, $sub, @subparms ] | ||||||||||||||||||||||||||||||||||||||||||
| 1079 | # optional $pattern_type is '-re' (RegExp, default) or '-ex' (exact); | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | # $sub is optional CODE ref, which is called as &{$sub}($exp, @subparms) | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | # if pattern matched; | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | # the $parm_nr gets unshifted onto the array for reporting purposes. | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 16309 | ▶ | sub _add_patterns_to_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_patterns_to_list: called CC=14 SCAR=30.2
| |||||||||||||||||||||||||||||||||||||||||||
| 1085 | 16309 | my ($listref, $timeoutlistref,$store_parm_nr, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||
| 1087 | # $timeoutlistref gets timeout patterns | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | 16309 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 16309 | foreach my $parm (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 1090 | 16309 | ▶ | if ( not ref($parm) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | return "Parameter #$parm_nr is not an ARRAY ref."; | |||||||||||||||||||||||||||||||||||||||||
| 1092 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | 16309 | $parm = [@$parm]; # make copy | |||||||||||||||||||||||||||||||||||||||||
| 1094 | 16309 | ▶ | if ( $parm->[0] =~ m/\A-/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||
| 1096 | # it's an option | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 1098 | and $parm->[0] ne '-ex' ) | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | 0 | return "Unknown option $parm->[0] in pattern #$parm_nr"; | |||||||||||||||||||||||||||||||||||||||||
| 1101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | 16309 | ▶ | if ( $parm->[0] eq 'timeout' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1104 | 5415 | ▶ | if ( defined $timeoutlistref ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1105 | 5415 | splice @$parm, 0, 1, ( "-$parm->[0]", undef ); | |||||||||||||||||||||||||||||||||||||||||
| 1106 | 5415 | ▶ | unshift @$parm, $store_parm_nr ? $parm_nr : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1107 | 5415 | push @$timeoutlistref, $parm; | |||||||||||||||||||||||||||||||||||||||||
| 1108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | 5415 | next; | |||||||||||||||||||||||||||||||||||||||||
| 1110 | } elsif ( $parm->[0] eq 'eof' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | 5415 | splice @$parm, 0, 1, ( "-$parm->[0]", undef ); | |||||||||||||||||||||||||||||||||||||||||
| 1112 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | 5479 | unshift @$parm, '-re'; # defaults to RegExp | |||||||||||||||||||||||||||||||||||||||||
| 1114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | 10894 | ▶ | if ( @$parm > 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1117 | 10891 | ▶ | if ( ref( $parm->[2] ) ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | croak( | |||||||||||||||||||||||||||||||||||||||||
| 1119 | "Pattern #$parm_nr doesn't have a CODE reference", | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | "after the pattern." | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | 3 | push @$parm, undef; # make sure we have three elements | |||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 10894 | ▶ | unshift @$parm, $store_parm_nr ? $parm_nr : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1128 | 10894 | push @$listref, $parm; | |||||||||||||||||||||||||||||||||||||||||
| 1129 | 10894 | $parm_nr++; | |||||||||||||||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||
| 1132 | 16309 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||
| 1135 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 1136 | # $process->interact([$in_handle],[$escape sequence]) | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | # If you don't specify in_handle STDIN will be used. | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | 0 | ▶ | sub interact { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interact: not called CC=6 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | my ($self, $infile, $escape_sequence) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | my $outfile; | |||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | my @old_group = $self->set_group(); | |||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | # If the handle is STDIN we'll | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | # $infile->fileno == 0 should be stdin.. follow stdin rules. | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | 29 | ▶ | no strict 'subs'; # Allow bare word 'STDIN' | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | ▶ | unless ( defined($infile) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1148 | # We need a handle object Associated with STDIN. | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | $infile = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | $infile->IO::File::fdopen( STDIN, 'r' ); | |||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | $outfile = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | $outfile->IO::File::fdopen( STDOUT, 'w' ); | |||||||||||||||||||||||||||||||||||||||||
| 1153 | } elsif ( fileno($infile) == fileno(STDIN) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||
| 1155 | # With STDIN we want output to go to stdout. | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | 0 | $outfile = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1157 | 0 | $outfile->IO::File::fdopen( STDOUT, 'w' ); | |||||||||||||||||||||||||||||||||||||||||
| 1158 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | 0 | undef($outfile); | |||||||||||||||||||||||||||||||||||||||||
| 1160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||
| 1162 | # Here we assure ourselves we have an Expect object. | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | my $in_object = Expect->exp_init($infile); | |||||||||||||||||||||||||||||||||||||||||
| 1164 | 0 | ▶ | if ( defined($outfile) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | # as above.. we want output to go to stdout if we're given stdin. | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | my $out_object = Expect->exp_init($outfile); | |||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | $out_object->manual_stty(1); | |||||||||||||||||||||||||||||||||||||||||
| 1169 | 0 | $self->set_group($out_object); | |||||||||||||||||||||||||||||||||||||||||
| 1170 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | $self->set_group($in_object); | |||||||||||||||||||||||||||||||||||||||||
| 1172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | $in_object->set_group($self); | |||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | ▶ | $in_object->set_seq( $escape_sequence, undef ) if defined($escape_sequence); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||||||||||||||||
| 1176 | # interconnect normally sets stty -echo raw. Interact really sort | ||||||||||||||||||||||||||||||||||||||||||
| 1177 | # of implies we don't do that by default. If anyone wanted to they could | ||||||||||||||||||||||||||||||||||||||||||
| 1178 | # set it before calling interact, of use interconnect directly. | ||||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | my $old_manual_stty_val = $self->manual_stty(); | |||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | $self->manual_stty(1); | |||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||
| 1182 | # I think this is right. Don't send stuff from in_obj to stdout by default. | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | # in theory whatever 'self' is should echo what's going on. | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | my $old_log_stdout_val = $self->log_stdout(); | |||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | $self->log_stdout(0); | |||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | $in_object->log_stdout(0); | |||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||
| 1188 | # Allow for the setting of an optional EOF escape function. | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | # $in_object->set_seq('EOF',undef); | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | # $self->set_seq('EOF',undef); | ||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | Expect::interconnect( $self, $in_object ); | |||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | $self->log_stdout($old_log_stdout_val); | |||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | $self->set_group(@old_group); | |||||||||||||||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||||||||||||||||
| 1195 | # If old_group was undef, make sure that occurs. This is a slight hack since | ||||||||||||||||||||||||||||||||||||||||||
| 1196 | # it modifies the value directly. | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | # Normally an undef passed to set_group will return the current groups. | ||||||||||||||||||||||||||||||||||||||||||
| 1198 | # It is possible that it may be of worth to make it possible to undef | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | # The current group without doing this. | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | ▶ | unless (@old_group) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | @{ ${*$self}{exp_Listen_Group} } = (); | |||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | $self->manual_stty($old_manual_stty_val); | |||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | ▶ | sub interconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interconnect: not called CC=48 SCAR=77.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | my (@handles) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||
| 1211 | # my ($handle)=(shift); call as Expect::interconnect($spawn1,$spawn2,...) | ||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | my ( $nread ); | |||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | my ( $rout, $emask, $eout ); | |||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | my ( $escape_character_buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | my ( $read_mask, $temp_mask ) = ( '', '' ); | |||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | # Get read/write handles | ||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | $temp_mask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1220 | 0 | vec( $temp_mask, $handle->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | # Under Linux w/ 5.001 the next line comes up w/ 'Uninit var.'. | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | # It appears to be impossible to make the warning go away. | ||||||||||||||||||||||||||||||||||||||||||
| 1224 | # doing something like $temp_mask='' unless defined ($temp_mask) | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | # has no effect whatsoever. This may be a bug in 5.001. | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | $read_mask = $read_mask | $temp_mask; | |||||||||||||||||||||||||||||||||||||||||
| 1227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1228 | 0 | ▶ | if ($Expect::Debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1229 | 0 | print STDERR "Read handles:\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1230 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | print STDERR "\tRead handle: "; | |||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | print STDERR "'${*$handle}{exp_Pty_Handle}'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | print STDERR "\t\tListen Handles:"; | |||||||||||||||||||||||||||||||||||||||||
| 1234 | 0 | foreach my $write_handle ( @{ ${*$handle}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1235 | 0 | print STDERR " '${*$write_handle}{exp_Pty_Handle}'"; | |||||||||||||||||||||||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1237 | 0 | print STDERR ".\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||
| 1241 | # I think if we don't set raw/-echo here we may have trouble. We don't | ||||||||||||||||||||||||||||||||||||||||||
| 1242 | # want a bunch of echoing crap making all the handles jabber at each other. | ||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | ▶ | unless ( ${*$handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||
| 1246 | # This is probably O/S specific. | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | 0 | ${*$handle}{exp_Stored_Stty} = $handle->exp_stty('-g'); | |||||||||||||||||||||||||||||||||||||||||
| 1248 | 0 | print STDERR "Setting tty for ${*$handle}{exp_Pty_Handle} to 'raw -echo'.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1249 | 0 | ▶ | if ${*$handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1250 | 0 | $handle->exp_stty("raw -echo"); | |||||||||||||||||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | 0 | foreach my $write_handle ( @{ ${*$handle}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1253 | 0 | ▶ | unless ( ${*$write_handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | ${*$write_handle}{exp_Stored_Stty} = | |||||||||||||||||||||||||||||||||||||||||
| 1255 | 0 | $write_handle->exp_stty('-g'); | |||||||||||||||||||||||||||||||||||||||||
| 1256 | 0 | print STDERR "Setting ${*$write_handle}{exp_Pty_Handle} to 'raw -echo'.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1257 | 0 | ▶ | if ${*$handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1258 | 0 | $write_handle->exp_stty("raw -echo"); | |||||||||||||||||||||||||||||||||||||||||
| 1259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | ▶ | print STDERR "Attempting interconnection\r\n" if $Expect::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||
| 1265 | # Wait until the process dies or we get EOF | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | # In the case of !${*$handle}{exp_Pid} it means | ||||||||||||||||||||||||||||||||||||||||||
| 1267 | # the handle was exp_inited instead of spawned. | ||||||||||||||||||||||||||||||||||||||||||
| 1268 | CONNECT_LOOP: | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||
| 1270 | # Go until we have a reason to stop | ||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||
| 1273 | # test each handle to see if it's still alive. | ||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | foreach my $read_handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1275 | 0 | waitpid( ${*$read_handle}{exp_Pid}, WNOHANG ) | |||||||||||||||||||||||||||||||||||||||||
| 1276 | 0 | if ( exists( ${*$read_handle}{exp_Pid} ) | |||||||||||||||||||||||||||||||||||||||||
| 1277 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1278 | 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"})
| |||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | and ( ${*$read_handle}{exp_Pid} ) | |||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | and ( !kill( 0, ${*$read_handle}{exp_Pid} ) ) ) | |||||||||||||||||||||||||||||||||||||||||
| 1281 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1282 | print STDERR | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | "Got EOF (${*$read_handle}{exp_Pty_Handle} died) reading ${*$read_handle}{exp_Pty_Handle}\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1285 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1286 | 0 | ▶ | unless defined( ${ ${*$read_handle}{exp_Function} }{"EOF"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1287 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | unless &{ ${ ${*$read_handle}{exp_Function} }{"EOF"} } | |||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | ▶ | ( @{ ${ ${*$read_handle}{exp_Parameters} }{"EOF"} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||
| 1293 | # Every second? No, go until we get something from someone. | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | 0 | my $nfound = select( $rout = $read_mask, undef, $eout = $emask, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||
| 1296 | # Is there anything to share? May be -1 if interrupted by a signal... | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||||||||||
| 1299 | # Which handles have stuff? | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | my @bits = split( //, unpack( 'b*', $rout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1301 | 0 | ▶ | $eout = 0 unless defined($eout); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1302 | 0 | my @ebits = split( //, unpack( 'b*', $eout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||
| 1304 | # print "Ebits: $eout\r\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1305 | 0 | foreach my $read_handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | ▶ | if ( $bits[ $read_handle->fileno() ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1307 | $nread = sysread( | ||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | $read_handle, ${*$read_handle}{exp_Pty_Buffer}, | |||||||||||||||||||||||||||||||||||||||||
| 1309 | 0 | 1024 | |||||||||||||||||||||||||||||||||||||||||
| 1310 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||||||||||
| 1312 | # Appease perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | ▶ | $nread = 0 unless defined($nread); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | print STDERR "interconnect: read $nread byte(s) from ${*$read_handle}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||||||||||||||||
| 1317 | # Test for escape seq. before printing. | ||||||||||||||||||||||||||||||||||||||||||
| 1318 | # Appease perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | ▶ | $escape_character_buffer = '' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1320 | unless defined($escape_character_buffer); | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | 0 | $escape_character_buffer .= ${*$read_handle}{exp_Pty_Buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | foreach my $escape_sequence ( keys( %{ ${*$read_handle}{exp_Function} } ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 1323 | 0 | print STDERR "Tested escape sequence $escape_sequence from ${*$read_handle}{exp_Pty_Handle}" | |||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1325 | |||||||||||||||||||||||||||||||||||||||||||
| 1326 | # Make sure it doesn't grow out of bounds. | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | $escape_character_buffer = $read_handle->_trim_length( | ||||||||||||||||||||||||||||||||||||||||||
| 1328 | $escape_character_buffer, | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | 0 | ${*$read_handle}{"exp_Max_Accum"} | |||||||||||||||||||||||||||||||||||||||||
| 1330 | 0 | ▶ | ) if ( ${*$read_handle}{"exp_Max_Accum"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1331 | 0 | ▶ | if ( $escape_character_buffer =~ /($escape_sequence)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1332 | 0 | my $match = $1; | |||||||||||||||||||||||||||||||||||||||||
| 1333 | 0 | ▶ | if ( ${*$read_handle}{"exp_Debug"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1334 | 0 | print STDERR | |||||||||||||||||||||||||||||||||||||||||
| 1335 | 0 | "\r\ninterconnect got escape sequence from ${*$read_handle}{exp_Pty_Handle}.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||
| 1337 | # I'm going to make the esc. seq. pretty because it will | ||||||||||||||||||||||||||||||||||||||||||
| 1338 | # probably contain unprintable characters. | ||||||||||||||||||||||||||||||||||||||||||
| 1339 | 0 | print STDERR "\tEscape Sequence: '" | |||||||||||||||||||||||||||||||||||||||||
| 1340 | . _trim_length( | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | _make_readable($escape_sequence) | ||||||||||||||||||||||||||||||||||||||||||
| 1343 | ) . "'\r\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1344 | 0 | print STDERR "\tMatched by string: '" . _trim_length( undef, _make_readable($match) ) . "'\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | |||||||||||||||||||||||||||||||||||||||||||
| 1347 | # Print out stuff before the escape. | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | # Keep in mind that the sequence may have been split up | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | # over several reads. | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | # Let's get rid of it from this read. If part of it was | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | # in the last read there's not a lot we can do about it now. | ||||||||||||||||||||||||||||||||||||||||||
| 1352 | 0 | ▶ | if ( ${*$read_handle}{exp_Pty_Buffer} =~ /([\w\W]*)($escape_sequence)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1353 | 0 | $read_handle->_print_handles($1); | |||||||||||||||||||||||||||||||||||||||||
| 1354 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | $read_handle->_print_handles( ${*$read_handle}{exp_Pty_Buffer} ); | |||||||||||||||||||||||||||||||||||||||||
| 1356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||||||||||||||||
| 1358 | # Clear the buffer so no more matches can be made and it will | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | # only be printed one time. | ||||||||||||||||||||||||||||||||||||||||||
| 1360 | 0 | ${*$read_handle}{exp_Pty_Buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1361 | 0 | $escape_character_buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||
| 1363 | # Do the function here. Must return non-zero to continue. | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | # More cool syntax. Maybe I should turn these in to objects. | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | 0 | unless &{ ${ ${*$read_handle}{exp_Function} }{$escape_sequence} } | |||||||||||||||||||||||||||||||||||||||||
| 1367 | 0 | ▶ | ( @{ ${ ${*$read_handle}{exp_Parameters} }{$escape_sequence} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1370 | 0 | ▶ | $nread = 0 unless defined($nread); # Appease perl -w? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1371 | 0 | waitpid( ${*$read_handle}{exp_Pid}, WNOHANG ) | |||||||||||||||||||||||||||||||||||||||||
| 1372 | 0 | if ( defined( ${*$read_handle}{exp_Pid} ) | |||||||||||||||||||||||||||||||||||||||||
| 1373 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1374 | 0 | ▶ | if ( $nread == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1375 | 0 | print STDERR "Got EOF reading ${*$read_handle}{exp_Pty_Handle}\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1376 | 0 | ▶ | if ${*$read_handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1377 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1378 | 0 | ▶ | unless defined( ${ ${*$read_handle}{exp_Function} }{"EOF"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1379 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | 0 | unless &{ ${ ${*$read_handle}{exp_Function} }{"EOF"} } | |||||||||||||||||||||||||||||||||||||||||
| 1381 | 0 | ▶ | ( @{ ${ ${*$read_handle}{exp_Parameters} }{"EOF"} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | 0 | ▶ | last CONNECT_LOOP if ( $nread < 0 ); # This would be an error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1384 | 0 | $read_handle->_print_handles( ${*$read_handle}{exp_Pty_Buffer} ); | |||||||||||||||||||||||||||||||||||||||||
| 1385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||
| 1387 | # I'm removing this because I haven't determined what causes exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | # consistently. | ||||||||||||||||||||||||||||||||||||||||||
| 1389 | 0 | if (0) #$ebits[$read_handle->fileno()]) | |||||||||||||||||||||||||||||||||||||||||
| 1390 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | print STDERR "Got Exception reading ${*$read_handle}{exp_Pty_Handle}\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | if ${*$read_handle}{"exp_Debug"}; | ||||||||||||||||||||||||||||||||||||||||||
| 1393 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | unless defined( ${ ${*$read_handle}{exp_Function} }{"EOF"} ); | ||||||||||||||||||||||||||||||||||||||||||
| 1395 | last CONNECT_LOOP | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | unless &{ ${ ${*$read_handle}{exp_Function} }{"EOF"} } | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | ( @{ ${ ${*$read_handle}{exp_Parameters} }{"EOF"} } ); | ||||||||||||||||||||||||||||||||||||||||||
| 1398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1401 | 0 | foreach my $handle (@handles) { | |||||||||||||||||||||||||||||||||||||||||
| 1402 | 0 | ▶ | unless ( ${*$handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1403 | 0 | $handle->exp_stty( ${*$handle}{exp_Stored_Stty} ); | |||||||||||||||||||||||||||||||||||||||||
| 1404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1405 | 0 | foreach my $write_handle ( @{ ${*$handle}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1406 | 0 | ▶ | unless ( ${*$write_handle}{"exp_Manual_Stty"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1407 | 0 | $write_handle->exp_stty( ${*$write_handle}{exp_Stored_Stty} ); | |||||||||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||||||||||||||||
| 1412 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | |||||||||||||||||||||||||||||||||||||||||||
| 1415 | # user can decide if log output gets also sent to logfile | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | 5662 | ▶ | sub print_log_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_log_file: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1417 | 5662 | my ($self, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||
| 1419 | 5662 | ▶ | if ( ${*$self}{exp_Log_File} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1420 | 5522 | ▶ | if ( ref( ${*$self}{exp_Log_File} ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1421 | 54 | ${*$self}{exp_Log_File}->(@params); | |||||||||||||||||||||||||||||||||||||||||
| 1422 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | 5468 | ${*$self}{exp_Log_File}->print(@params); | |||||||||||||||||||||||||||||||||||||||||
| 1424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1426 | |||||||||||||||||||||||||||||||||||||||||||
| 1427 | 5662 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||
| 1430 | # we provide our own print so we can debug what gets sent to the | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | # processes... | ||||||||||||||||||||||||||||||||||||||||||
| 1432 | 5308 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1433 | 5308 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||||||||||||||||
| 1435 | 5308 | ▶ | return if not defined $self->fileno(); # skip if closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1436 | 5308 | ▶ | if ( ${*$self}{exp_Exp_Internal} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1437 | 0 | my $args = _make_readable( join( '', @args ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1438 | 0 | cluck "Sending '$args' to ${*$self}{exp_Pty_Handle}\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1440 | 5308 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||
| 1441 | 5308 | ▶ | while ( length($arg) > 80 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1442 | 11814 | $self->SUPER::print( substr( $arg, 0, 80 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1443 | 11814 | $arg = substr( $arg, 80 ); | |||||||||||||||||||||||||||||||||||||||||
| 1444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1445 | 5308 | $self->SUPER::print($arg); | |||||||||||||||||||||||||||||||||||||||||
| 1446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||
| 1448 | 5308 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||
| 1451 | # make an alias for Tcl/Expect users for a DWIM experience... | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | 29 | *send = \&print; | |||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||
| 1454 | # This is an Expect standard. It's nice for talking to modems and the like | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | # where from time to time they get unhappy if you send items too quickly. | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | 27 | ▶ | sub send_slow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_slow: called CC=12 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1457 | 27 | my ($self, $sleep_time, @chunks) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||||||||||||||||
| 1459 | 27 | ▶ | return if not defined $self->fileno(); # skip if closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||
| 1461 | # Flushing makes it so each character can be seen separately. | ||||||||||||||||||||||||||||||||||||||||||
| 1462 | 27 | my $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 1463 | 27 | ▶ | while ( $chunk = shift @chunks ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1464 | 27 | my @linechars = split( '', $chunk ); | |||||||||||||||||||||||||||||||||||||||||
| 1465 | 27 | foreach my $char (@linechars) { | |||||||||||||||||||||||||||||||||||||||||
| 1466 | |||||||||||||||||||||||||||||||||||||||||||
| 1467 | # How slow? | ||||||||||||||||||||||||||||||||||||||||||
| 1468 | 1170 | select( undef, undef, undef, $sleep_time ); | |||||||||||||||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||||||||||||||||
| 1470 | 1170 | print $self $char; | |||||||||||||||||||||||||||||||||||||||||
| 1471 | 0 | print STDERR "Printed character \'" . _make_readable($char) . "\' to ${*$self}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1472 | 1170 | ▶ | if ${*$self}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||||||||||||||||
| 1474 | # I think I can get away with this if I save it in accum | ||||||||||||||||||||||||||||||||||||||||||
| 1475 | 0 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1476 | 1170 | my $rmask = ""; | |||||||||||||||||||||||||||||||||||||||||
| 1477 | 1170 | vec( $rmask, $self->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1478 | |||||||||||||||||||||||||||||||||||||||||||
| 1479 | # .01 sec granularity should work. If we miss something it will | ||||||||||||||||||||||||||||||||||||||||||
| 1480 | # probably get flushed later, maybe in an expect call. | ||||||||||||||||||||||||||||||||||||||||||
| 1481 | 1170 | ▶ | while ( select( $rmask, undef, undef, .01 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1482 | 27 | my $ret = sysread( $self, ${*$self}{exp_Pty_Buffer}, 1024 ); | |||||||||||||||||||||||||||||||||||||||||
| 1483 | 27 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||
| 1485 | # Is this necessary to keep? Probably.. # | ||||||||||||||||||||||||||||||||||||||||||
| 1486 | # if you need to expect it later. | ||||||||||||||||||||||||||||||||||||||||||
| 1487 | 27 | ${*$self}{exp_Accum} .= ${*$self}{exp_Pty_Buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 1488 | 0 | ${*$self}{exp_Accum} = $self->_trim_length( | |||||||||||||||||||||||||||||||||||||||||
| 1489 | 0 | ${*$self}{exp_Accum}, | |||||||||||||||||||||||||||||||||||||||||
| 1490 | 0 | ${*$self}{"exp_Max_Accum"} | |||||||||||||||||||||||||||||||||||||||||
| 1491 | 27 | ▶ | ) if ( ${*$self}{"exp_Max_Accum"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1492 | 27 | $self->_print_handles( ${*$self}{exp_Pty_Buffer} ); | |||||||||||||||||||||||||||||||||||||||||
| 1493 | print STDERR "Received \'" | ||||||||||||||||||||||||||||||||||||||||||
| 1494 | . $self->_trim_length( _make_readable($char) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | 0 | . "\' from ${*$self}{exp_Pty_Handle}\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1496 | 27 | ▶ | if ${*$self}{"exp_Debug"} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||
| 1502 | 27 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1504 | |||||||||||||||||||||||||||||||||||||||||||
| 1505 | 0 | ▶ | sub test_handles { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_handles: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1506 | 0 | my ($timeout, @handle_list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1507 | |||||||||||||||||||||||||||||||||||||||||||
| 1508 | # This should be called by Expect::test_handles($timeout,@objects); | ||||||||||||||||||||||||||||||||||||||||||
| 1509 | 0 | my ( $allmask, $rout ); | |||||||||||||||||||||||||||||||||||||||||
| 1510 | 0 | foreach my $handle (@handle_list) { | |||||||||||||||||||||||||||||||||||||||||
| 1511 | 0 | my $rmask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1512 | 0 | vec( $rmask, $handle->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1513 | 0 | ▶ | $allmask = '' unless defined($allmask); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1514 | 0 | $allmask = $allmask | $rmask; | |||||||||||||||||||||||||||||||||||||||||
| 1515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1516 | 0 | my $nfound = select( $rout = $allmask, undef, undef, $timeout ); | |||||||||||||||||||||||||||||||||||||||||
| 1517 | 0 | ▶ | return () unless $nfound; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1518 | |||||||||||||||||||||||||||||||||||||||||||
| 1519 | # Which handles have stuff? | ||||||||||||||||||||||||||||||||||||||||||
| 1520 | 0 | my @bits = split( //, unpack( 'b*', $rout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||
| 1522 | 0 | my $handle_num = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1523 | 0 | my @return_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 1524 | 0 | foreach my $handle (@handle_list) { | |||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||
| 1526 | # I go to great lengths to get perl -w to shut the hell up. | ||||||||||||||||||||||||||||||||||||||||||
| 1527 | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 1528 | and ( $bits[ $handle->fileno() ] ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1530 | 0 | push( @return_list, $handle_num ); | |||||||||||||||||||||||||||||||||||||||||
| 1531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1532 | } continue { | ||||||||||||||||||||||||||||||||||||||||||
| 1533 | 0 | $handle_num++; | |||||||||||||||||||||||||||||||||||||||||
| 1534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1535 | |||||||||||||||||||||||||||||||||||||||||||
| 1536 | 0 | return @return_list; | |||||||||||||||||||||||||||||||||||||||||
| 1537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||
| 1539 | # Be nice close. This should emulate what an interactive shell does after a | ||||||||||||||||||||||||||||||||||||||||||
| 1540 | # command finishes... sort of. We're not as patient as a shell. | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | 9 | ▶ | sub soft_close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
soft_close: called CC=26 SCAR=48.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1542 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1543 | |||||||||||||||||||||||||||||||||||||||||||
| 1544 | 9 | my ( $nfound, $nread, $rmask, $end_time, $temp_buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 1545 | |||||||||||||||||||||||||||||||||||||||||||
| 1546 | # Give it 15 seconds to cough up an eof. | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | 0 | ▶ | cluck "Closing ${*$self}{exp_Pty_Handle}.\r\n" if ${*$self}{exp_Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1548 | 9 | ▶ | return -1 if not defined $self->fileno(); # skip if handle already closed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1549 | 0 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1550 | 9 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1551 | 9 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1552 | 13 | my $select_time = $end_time - time(); | |||||||||||||||||||||||||||||||||||||||||
| 1553 | |||||||||||||||||||||||||||||||||||||||||||
| 1554 | # Sanity check. | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | 13 | ▶ | $select_time = 0 if $select_time < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1556 | 13 | $rmask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1557 | 13 | vec( $rmask, $self->fileno(), 1 ) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1558 | 13 | ($nfound) = select( $rmask, undef, undef, $select_time ); | |||||||||||||||||||||||||||||||||||||||||
| 1559 | 13 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1560 | 13 | $nread = sysread( $self, $temp_buffer, 8096 ); | |||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||
| 1562 | # 0 = EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | 13 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1564 | 0 | print STDERR "Got EOF from ${*$self}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1565 | 9 | ▶ | if ${*$self}{exp_Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1566 | 9 | last; | |||||||||||||||||||||||||||||||||||||||||
| 1567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1568 | 4 | $self->_print_handles($temp_buffer); | |||||||||||||||||||||||||||||||||||||||||
| 1569 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1570 | 0 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1571 | 0 | print STDERR "Timed out waiting for an EOF from ${*$self}{exp_Pty_Handle}.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | 9 | my $close_status = $self->close(); | |||||||||||||||||||||||||||||||||||||||||
| 1575 | 9 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1576 | 0 | print STDERR "${*$self}{exp_Pty_Handle} closed.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1578 | |||||||||||||||||||||||||||||||||||||||||||
| 1579 | # quit now if it isn't a process. | ||||||||||||||||||||||||||||||||||||||||||
| 1580 | 9 | ▶ | return $close_status unless defined( ${*$self}{exp_Pid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1581 | |||||||||||||||||||||||||||||||||||||||||||
| 1582 | # Now give it 15 seconds to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1583 | 9 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1584 | 9 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1585 | 9 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1586 | |||||||||||||||||||||||||||||||||||||||||||
| 1587 | # Stop here if the process dies. | ||||||||||||||||||||||||||||||||||||||||||
| 1588 | 9 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1589 | 9 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1590 | 9 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1591 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1592 | "Pid %d of %s exited, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1593 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1594 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1595 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1597 | 9 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1598 | 9 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1599 | 9 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1601 | 0 | sleep 1; # Keep loop nice. | |||||||||||||||||||||||||||||||||||||||||
| 1602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||||||||||||||||
| 1604 | # Send it a term if it isn't dead. | ||||||||||||||||||||||||||||||||||||||||||
| 1605 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1606 | 0 | print STDERR "${*$self}{exp_Pty_Handle} not exiting, sending TERM.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1608 | 0 | kill TERM => ${*$self}{exp_Pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1609 | |||||||||||||||||||||||||||||||||||||||||||
| 1610 | # Now to be anal retentive.. wait 15 more seconds for it to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1611 | 0 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1612 | 0 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1613 | 0 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1614 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1615 | 0 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1616 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1617 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1618 | "Pid %d of %s terminated, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1620 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1621 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1623 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1624 | 0 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1625 | 0 | return $?; | |||||||||||||||||||||||||||||||||||||||||
| 1626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1627 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 1628 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1629 | |||||||||||||||||||||||||||||||||||||||||||
| 1630 | # Since this is a 'soft' close, sending it a -9 would be inappropriate. | ||||||||||||||||||||||||||||||||||||||||||
| 1631 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1632 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | |||||||||||||||||||||||||||||||||||||||||||
| 1634 | # 'Make it go away' close. | ||||||||||||||||||||||||||||||||||||||||||
| 1635 | 194 | ▶ | sub hard_close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hard_close: called CC=18 SCAR=48.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1636 | 194 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||||||||||||||||
| 1638 | 0 | ▶ | cluck "Closing ${*$self}{exp_Pty_Handle}.\r\n" if ${*$self}{exp_Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1639 | |||||||||||||||||||||||||||||||||||||||||||
| 1640 | # Don't wait for an EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 1641 | 194 | my $close_status = $self->close(); | |||||||||||||||||||||||||||||||||||||||||
| 1642 | 194 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1643 | 0 | print STDERR "${*$self}{exp_Pty_Handle} closed.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | |||||||||||||||||||||||||||||||||||||||||||
| 1646 | # Return now if handle. | ||||||||||||||||||||||||||||||||||||||||||
| 1647 | 194 | ▶ | return $close_status unless defined( ${*$self}{exp_Pid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1648 | |||||||||||||||||||||||||||||||||||||||||||
| 1649 | # Now give it 5 seconds to die. Less patience here if it won't die. | ||||||||||||||||||||||||||||||||||||||||||
| 1650 | 95 | my $end_time = time() + 5; | |||||||||||||||||||||||||||||||||||||||||
| 1651 | 95 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1652 | 179 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1653 | |||||||||||||||||||||||||||||||||||||||||||
| 1654 | # Stop here if the process dies. | ||||||||||||||||||||||||||||||||||||||||||
| 1655 | 179 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1656 | 95 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1657 | 95 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1658 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1659 | "Pid %d of %s terminated, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1660 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1661 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1662 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1664 | 95 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1665 | 95 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1666 | 95 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1668 | 84 | sleep 1; # Keep loop nice. | |||||||||||||||||||||||||||||||||||||||||
| 1669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1670 | |||||||||||||||||||||||||||||||||||||||||||
| 1671 | # Send it a term if it isn't dead. | ||||||||||||||||||||||||||||||||||||||||||
| 1672 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1673 | 0 | print STDERR "${*$self}{exp_Pty_Handle} not exiting, sending TERM.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1674 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1675 | 0 | kill TERM => ${*$self}{exp_Pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1676 | |||||||||||||||||||||||||||||||||||||||||||
| 1677 | # wait 15 more seconds for it to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1678 | 0 | $end_time = time() + 15; | |||||||||||||||||||||||||||||||||||||||||
| 1679 | 0 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1680 | 0 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1681 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1682 | 0 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1683 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1684 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1685 | "Pid %d of %s terminated, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1686 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1687 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1688 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1689 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1690 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1691 | 0 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1692 | 0 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1694 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 1695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1696 | 0 | kill KILL => ${*$self}{exp_Pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1697 | |||||||||||||||||||||||||||||||||||||||||||
| 1698 | # wait 5 more seconds for it to die. | ||||||||||||||||||||||||||||||||||||||||||
| 1699 | 0 | $end_time = time() + 5; | |||||||||||||||||||||||||||||||||||||||||
| 1700 | 0 | ▶ | while ( $end_time > time() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1701 | 0 | my $returned_pid = waitpid( ${*$self}{exp_Pid}, &WNOHANG ); | |||||||||||||||||||||||||||||||||||||||||
| 1702 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1703 | 0 | delete $Expect::Spawned_PIDs{$returned_pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1704 | 0 | ▶ | if ( ${*$self}{exp_Debug} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1705 | printf STDERR ( | ||||||||||||||||||||||||||||||||||||||||||
| 1706 | "Pid %d of %s killed, Status: 0x%02X\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 1707 | 0 | ${*$self}{exp_Pid}, | |||||||||||||||||||||||||||||||||||||||||
| 1708 | 0 | ${*$self}{exp_Pty_Handle}, $? | |||||||||||||||||||||||||||||||||||||||||
| 1709 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1711 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1712 | 0 | ${*$self}{exp_Exit} = $?; | |||||||||||||||||||||||||||||||||||||||||
| 1713 | 0 | return ${*$self}{exp_Exit}; | |||||||||||||||||||||||||||||||||||||||||
| 1714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1715 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 1716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1717 | 0 | warn "Pid ${*$self}{exp_Pid} of ${*$self}{exp_Pty_Handle} is HUNG.\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1718 | 0 | ${*$self}{exp_Pid} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1719 | |||||||||||||||||||||||||||||||||||||||||||
| 1720 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1721 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1722 | |||||||||||||||||||||||||||||||||||||||||||
| 1723 | # These should not be called externally. | ||||||||||||||||||||||||||||||||||||||||||
| 1724 | |||||||||||||||||||||||||||||||||||||||||||
| 1725 | 151 | ▶ | sub _init_vars { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_vars: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1726 | 151 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1727 | |||||||||||||||||||||||||||||||||||||||||||
| 1728 | # for every spawned process or filehandle. | ||||||||||||||||||||||||||||||||||||||||||
| 1729 | 0 | ▶ | ${*$self}{exp_Log_Stdout} = $Expect::Log_Stdout | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1730 | if defined($Expect::Log_Stdout); | ||||||||||||||||||||||||||||||||||||||||||
| 1731 | 151 | ${*$self}{exp_Log_Group} = $Expect::Log_Group; | |||||||||||||||||||||||||||||||||||||||||
| 1732 | 151 | ${*$self}{exp_Debug} = $Expect::Debug; | |||||||||||||||||||||||||||||||||||||||||
| 1733 | 151 | ${*$self}{exp_Exp_Internal} = $Expect::Exp_Internal; | |||||||||||||||||||||||||||||||||||||||||
| 1734 | 151 | ${*$self}{exp_Manual_Stty} = $Expect::Manual_Stty; | |||||||||||||||||||||||||||||||||||||||||
| 1735 | 151 | ${*$self}{exp_Stored_Stty} = 'sane'; | |||||||||||||||||||||||||||||||||||||||||
| 1736 | 151 | ${*$self}{exp_Do_Soft_Close} = $Expect::Do_Soft_Close; | |||||||||||||||||||||||||||||||||||||||||
| 1737 | |||||||||||||||||||||||||||||||||||||||||||
| 1738 | # sysread doesn't like my or local vars. | ||||||||||||||||||||||||||||||||||||||||||
| 1739 | 151 | ${*$self}{exp_Pty_Buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1740 | |||||||||||||||||||||||||||||||||||||||||||
| 1741 | # Initialize accumulator. | ||||||||||||||||||||||||||||||||||||||||||
| 1742 | 151 | ${*$self}{exp_Max_Accum} = $Expect::Exp_Max_Accum; | |||||||||||||||||||||||||||||||||||||||||
| 1743 | 151 | ${*$self}{exp_Accum} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1744 | 151 | ${*$self}{exp_NoTransfer} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1745 | |||||||||||||||||||||||||||||||||||||||||||
| 1746 | # create empty expect_before & after lists | ||||||||||||||||||||||||||||||||||||||||||
| 1747 | 151 | ${*$self}{exp_expect_before_list} = []; | |||||||||||||||||||||||||||||||||||||||||
| 1748 | 151 | ${*$self}{exp_expect_after_list} = []; | |||||||||||||||||||||||||||||||||||||||||
| 1749 | |||||||||||||||||||||||||||||||||||||||||||
| 1750 | 151 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1751 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||
| 1753 | 0 | ▶ | sub _make_readable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_readable: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1754 | 0 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1755 | |||||||||||||||||||||||||||||||||||||||||||
| 1756 | 0 | ▶ | $s = '' if not defined($s); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1757 | 0 | study $s; # Speed things up? | |||||||||||||||||||||||||||||||||||||||||
| 1758 | 0 | $s =~ s/\\/\\\\/g; # So we can tell easily(?) what is a backslash | |||||||||||||||||||||||||||||||||||||||||
| 1759 | 0 | $s =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 1760 | 0 | $s =~ s/\r/\\r/g; | |||||||||||||||||||||||||||||||||||||||||
| 1761 | 0 | $s =~ s/\t/\\t/g; | |||||||||||||||||||||||||||||||||||||||||
| 1762 | 0 | $s =~ s/\'/\\\'/g; # So we can tell whassa quote and whassa notta quote. | |||||||||||||||||||||||||||||||||||||||||
| 1763 | 0 | $s =~ s/\"/\\\"/g; | |||||||||||||||||||||||||||||||||||||||||
| 1764 | |||||||||||||||||||||||||||||||||||||||||||
| 1765 | # Formfeed (does anyone use formfeed?) | ||||||||||||||||||||||||||||||||||||||||||
| 1766 | 0 | $s =~ s/\f/\\f/g; | |||||||||||||||||||||||||||||||||||||||||
| 1767 | 0 | $s =~ s/\010/\\b/g; | |||||||||||||||||||||||||||||||||||||||||
| 1768 | |||||||||||||||||||||||||||||||||||||||||||
| 1769 | # escape control chars high/low, but allow ISO 8859-1 chars | ||||||||||||||||||||||||||||||||||||||||||
| 1770 | 0 | $s =~ s/([\000-\037\177-\237\377])/sprintf("\\%03lo",ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||||
| 1771 | |||||||||||||||||||||||||||||||||||||||||||
| 1772 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 1773 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1774 | |||||||||||||||||||||||||||||||||||||||||||
| 1775 | 17 | ▶ | sub _trim_length { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim_length: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||
| 1776 | 17 | my ($self, $string, $length) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1777 | |||||||||||||||||||||||||||||||||||||||||||
| 1778 | # This is sort of a reverse truncation function | ||||||||||||||||||||||||||||||||||||||||||
| 1779 | # Mostly so we don't have to see the full output when we're using | ||||||||||||||||||||||||||||||||||||||||||
| 1780 | # Also used if Max_Accum gets set to limit the size of the accumulator | ||||||||||||||||||||||||||||||||||||||||||
| 1781 | # for matching functions. | ||||||||||||||||||||||||||||||||||||||||||
| 1782 | # exp_internal | ||||||||||||||||||||||||||||||||||||||||||
| 1783 | |||||||||||||||||||||||||||||||||||||||||||
| 1784 | 17 | ▶ | croak('No string passed') if not defined $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1785 | |||||||||||||||||||||||||||||||||||||||||||
| 1786 | # If we're not passed a length (_trim_length is being used for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 1787 | # purposes) AND debug >= 3, don't trim. | ||||||||||||||||||||||||||||||||||||||||||
| 1788 | return ($string) | ||||||||||||||||||||||||||||||||||||||||||
| 1789 | if (defined($self) | ||||||||||||||||||||||||||||||||||||||||||
| 1790 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 1791 | and ( !( defined($length) ) ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 1792 | 15 | ▶ | my $indicate_truncation = ($length ? '' : '...'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1793 | 15 | ▶ | $length ||= 1021; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$length ||= 1021
MC/DC100%1/1
$length ||= 1021
$length
Truth table100%2/2
A
A= $length
| |||||||||||||||||||||||||||||||||||||||||||
| 1794 | 15 | ▶ | return $string if $length >= length $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1795 | |||||||||||||||||||||||||||||||||||||||||||
| 1796 | # We wouldn't want the accumulator to begin with '...' if max_accum is passed | ||||||||||||||||||||||||||||||||||||||||||
| 1797 | # This is because this funct. gets called internally w/ max_accum | ||||||||||||||||||||||||||||||||||||||||||
| 1798 | # and is also used to print information back to the user. | ||||||||||||||||||||||||||||||||||||||||||
| 1799 | 8 | return $indicate_truncation . substr( $string, ( length($string) - $length ), $length ); | |||||||||||||||||||||||||||||||||||||||||
| 1800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1801 | |||||||||||||||||||||||||||||||||||||||||||
| 1802 | 5662 | ▶ | sub _print_handles { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print_handles: called CC=6 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1803 | 5662 | my ($self, $print_this) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1804 | |||||||||||||||||||||||||||||||||||||||||||
| 1805 | # Given crap from 'self' and the handles self wants to print to, print to | ||||||||||||||||||||||||||||||||||||||||||
| 1806 | # them. these are indicated by the handle's 'group' | ||||||||||||||||||||||||||||||||||||||||||
| 1807 | 5662 | ▶ | if ( ${*$self}{exp_Log_Group} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1808 | 5662 | foreach my $handle ( @{ ${*$self}{exp_Listen_Group} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1809 | 0 | ▶ | $print_this = '' unless defined($print_this); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1810 | |||||||||||||||||||||||||||||||||||||||||||
| 1811 | # Appease perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 1812 | print STDERR "Printed '" | ||||||||||||||||||||||||||||||||||||||||||
| 1813 | . $self->_trim_length( _make_readable($print_this) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1814 | 0 | . "' to ${*$handle}{exp_Pty_Handle} from ${*$self}{exp_Pty_Handle}.\r\n" | |||||||||||||||||||||||||||||||||||||||||
| 1815 | 0 | ▶ | if ( ${*$handle}{"exp_Debug"} > 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1816 | 0 | print $handle $print_this; | |||||||||||||||||||||||||||||||||||||||||
| 1817 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1818 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1819 | |||||||||||||||||||||||||||||||||||||||||||
| 1820 | # If ${*$self}{exp_Pty_Handle} is STDIN this would make it echo. | ||||||||||||||||||||||||||||||||||||||||||
| 1821 | print STDOUT $print_this | ||||||||||||||||||||||||||||||||||||||||||
| 1822 | 5662 | ▶ | if ${*$self}{"exp_Log_Stdout"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1823 | 5662 | $self->print_log_file($print_this); | |||||||||||||||||||||||||||||||||||||||||
| 1824 | 5662 | $| = 1; # This should not be necessary but autoflush() doesn't always work. | |||||||||||||||||||||||||||||||||||||||||
| 1825 | |||||||||||||||||||||||||||||||||||||||||||
| 1826 | 5662 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1828 | |||||||||||||||||||||||||||||||||||||||||||
| 1829 | 0 | ▶ | sub _get_mode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_mode: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1830 | 0 | my ($handle) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1831 | |||||||||||||||||||||||||||||||||||||||||||
| 1832 | 0 | my ($fcntl_flags) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1833 | |||||||||||||||||||||||||||||||||||||||||||
| 1834 | # What mode are we opening with? use fcntl to find out. | ||||||||||||||||||||||||||||||||||||||||||
| 1835 | 0 | $fcntl_flags = fcntl( \*{$handle}, Fcntl::F_GETFL, $fcntl_flags ); | |||||||||||||||||||||||||||||||||||||||||
| 1836 | 0 | ▶ | die "fcntl returned undef during exp_init of $handle, $!\r\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1837 | unless defined($fcntl_flags); | ||||||||||||||||||||||||||||||||||||||||||
| 1838 | 0 | ▶ | if ( $fcntl_flags | (Fcntl::O_RDWR) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1839 | 0 | return 'rw'; | |||||||||||||||||||||||||||||||||||||||||
| 1840 | } elsif ( $fcntl_flags | (Fcntl::O_WRONLY) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1841 | 0 | return 'w'; | |||||||||||||||||||||||||||||||||||||||||
| 1842 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1843 | |||||||||||||||||||||||||||||||||||||||||||
| 1844 | # Under Solaris (among others?) O_RDONLY is implemented as 0. so |O_RDONLY would fail. | ||||||||||||||||||||||||||||||||||||||||||
| 1845 | 0 | return 'r'; | |||||||||||||||||||||||||||||||||||||||||
| 1846 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1848 | |||||||||||||||||||||||||||||||||||||||||||
| 1849 | 0 | ▶ | sub _undef { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_undef: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1850 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 1851 | |||||||||||||||||||||||||||||||||||||||||||
| 1852 | # Seems a little retarded but &CORE::undef fails in interconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 1853 | # This is used for the default escape sequence function. | ||||||||||||||||||||||||||||||||||||||||||
| 1854 | # w/out the leading & it won't compile. | ||||||||||||||||||||||||||||||||||||||||||
| 1855 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1856 | |||||||||||||||||||||||||||||||||||||||||||
| 1857 | # clean up child processes | ||||||||||||||||||||||||||||||||||||||||||
| 1858 | 130 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1859 | 130 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1860 | |||||||||||||||||||||||||||||||||||||||||||
| 1861 | 130 | my $status = $?; # save this as it gets mangled by the terminating spawned children | |||||||||||||||||||||||||||||||||||||||||
| 1862 | 130 | ▶ | if ( ${*$self}{exp_Do_Soft_Close} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1863 | 0 | $self->soft_close(); | |||||||||||||||||||||||||||||||||||||||||
| 1864 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1865 | 130 | $self->hard_close(); | |||||||||||||||||||||||||||||||||||||||||
| 1866 | 130 | $? = $status; # restore it. otherwise deleting an Expect object may mangle $?, which is unintuitive | |||||||||||||||||||||||||||||||||||||||||
| 1867 | |||||||||||||||||||||||||||||||||||||||||||
| 1868 | 130 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1869 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1870 | |||||||||||||||||||||||||||||||||||||||||||
| 1871 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1872 | __END__ | ||||||||||||||||||||||||||||||||||||||||||