Subject: | POE::Wheel::ReadLine not restoring terminal state |
When running the small attached program, it will prompt for a line via
POE::Wheel::ReadLine. If you enter a line, the program will display a
message and exit properly. No problem. If instead you hit Ctrl+C or
Ctrl+D (SIGINT or EOF), then it displays that an exception has been
received and exits. But this time it doesn't restore the terminal's
previous state, rendering it unusable (no echo, newlines not displayed
properly, ...) until you run 'reset'.
The reason for this is that in some situations no clean-up is
happening. See this piece of code taken from POE::Wheel::ReadLine-
Show quoted text
>DESTROY
# TODO - This module keeps several references to $self in anonymous
# subroutines. These $self-references keep the wheel from dying
# until well after its parent session is gone. The following
# return() statement is a cheezy workaround for this problem.
return if $poe_kernel->get_active_session == $poe_kernel;
[... clean up code follows ...]
For some reason, execution gets past this return if you entered a line,
but not when there was an exception.
I'm on linux 2.6.16 / i686 / perl 5.8.8 / POE-0.37
Thanks.
Subject: | POE-Wheel-ReadLine-problem.pl |
#!/usr/bin/perl -w
use strict;
use warnings;
use POE;
use POE::Wheel::ReadLine;
POE::Session->create(
inline_states => {
_start => \&_start,
input => \&input
}
);
sub _start {
$_[HEAP]{wheel} = POE::Wheel::ReadLine->new(InputEvent => 'input');
$_[HEAP]{wheel}->get('prompt> ');
}
sub input {
my ($input, $exception) = @_[ARG0, ARG1];
if (defined $input) {
$_[HEAP]{wheel}->put("Got line: $input");
} else {
$_[HEAP]{wheel}->put("Got exception: $exception");
}
}
$poe_kernel->run();