I've written a test that inputs keystrokes into the terminal. To do this, I create a fork of my test code. The input from the terminal modifies the object. When my fork returns, however, the object is not modified. How do I return the object from the fork to my original test process?
# CODE: my $obj = ''; lives_ok { $obj = Commander->new(valid_chars => [ qw ( a b c d ) ] ) } + 'Can pass it an array of valid chars'; lives_ok { issue_cmd("abcd\n") } 'Can get a command terminated with ne +w line'; is ($obj->last_cmd, 'abcd', 'got expected input'); # this fails, retur +ns empty string # support methods sub jam { $TIOCSTI = 0x80017472; for (split(//, $_[0])) { ioctl(STDIN, $TIOCSTI, $_) || die "bad TIOCSTI: $!"; } } sub issue_cmd { my $cmd = shift; my $pid = fork(); if (!defined $pid) { die "Cannot fork: $!"; } elsif ($pid == 0) { $obj->get_cmd; exit 0; } else { jam($cmd); waitpid $pid, 0; } }
$PM = "Perl Monk's";
$MCF = "Most CluelessFriarAbbotBishopPontiffDeaconCuratePriest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to Modifying an object in a fork by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |