summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-09-27 21:43:31 -0500
committerJesse Luehrs <doy@tozt.net>2009-09-27 21:49:08 -0500
commit1afe3a88e4b61d92469fcafb648a7a907f467fe1 (patch)
tree89d5fa343e20c77e739aa66af95a8a0f6ebabd0e
parent873124695bbbdd85c144f2983ce38ab92d2e13fd (diff)
downloadapp-termcast-1afe3a88e4b61d92469fcafb648a7a907f467fe1.tar.gz
app-termcast-1afe3a88e4b61d92469fcafb648a7a907f467fe1.zip
use Scope::Guard to clean up ReadMode
-rw-r--r--dist.ini1
-rw-r--r--lib/App/Termcast.pm12
2 files changed, 9 insertions, 4 deletions
diff --git a/dist.ini b/dist.ini
index 426a04b..e5dc748 100644
--- a/dist.ini
+++ b/dist.ini
@@ -12,3 +12,4 @@ Moose = 0
IO::Pty::Easy = 0.07
Term::ReadKey = 0
MooseX::Getopt = 0
+Scope::Guard = 0
diff --git a/lib/App/Termcast.pm b/lib/App/Termcast.pm
index b65a691..05dac86 100644
--- a/lib/App/Termcast.pm
+++ b/lib/App/Termcast.pm
@@ -2,6 +2,7 @@ package App::Termcast;
use Moose;
use IO::Pty::Easy;
use IO::Socket::INET;
+use Scope::Guard;
use Term::ReadKey;
with 'MooseX::Getopt::Dashes';
@@ -85,6 +86,7 @@ sub run {
vec($rin, $ptyfd, 1) = 1;
vec($rin, $sockfd, 1) = 1;
ReadMode 5;
+ my $guard = Scope::Guard->new(sub { ReadMode 0 });
local $SIG{WINCH} = sub { $self->_got_winch(1) };
while (1) {
my $ready = select($rout = $rin, undef, undef, undef);
@@ -96,7 +98,8 @@ sub run {
$self->_got_winch(0);
redo;
}
- warn "Error reading from stdin: $!" unless defined $buf;
+ Carp::croak("Error reading from stdin: $!")
+ unless defined $buf;
last;
}
$pty->write($buf);
@@ -108,7 +111,8 @@ sub run {
$self->_got_winch(0);
redo;
}
- warn "Error reading from pty: $!" unless defined $buf;
+ Carp::croak("Error reading from pty: $!")
+ unless defined $buf;
last;
}
syswrite STDOUT, $buf;
@@ -122,7 +126,8 @@ sub run {
$self->_got_winch(0);
redo;
}
- warn "Error reading from socket: $!" unless defined $buf;
+ Carp::croak("Error reading from socket: $!")
+ unless defined $buf;
last;
}
if ($self->bell_on_watcher) {
@@ -131,7 +136,6 @@ sub run {
}
}
}
- ReadMode 0;
}
__PACKAGE__->meta->make_immutable;