summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-04-18 17:20:06 -0500
committerJesse Luehrs <doy@tozt.net>2010-04-18 17:20:06 -0500
commitc2340699c7caea722dd43210cd8bca5fcea22a00 (patch)
tree53e77c717d1a5b94ad8cb1369f60e8ea88057f96
parent0f592e5cc31a442e282c29352082b0478c8878ab (diff)
downloadapp-termcast-c2340699c7caea722dd43210cd8bca5fcea22a00.tar.gz
app-termcast-c2340699c7caea722dd43210cd8bca5fcea22a00.zip
stop using extra_argv directly, pass command to run to the run method
-rw-r--r--bin/termcast5
-rw-r--r--lib/App/Termcast.pm10
-rw-r--r--t/001-basic.t5
-rw-r--r--t/002-read-write.t5
4 files changed, 12 insertions, 13 deletions
diff --git a/bin/termcast b/bin/termcast
index 0dd2e0b..b97c2dd 100644
--- a/bin/termcast
+++ b/bin/termcast
@@ -17,7 +17,10 @@ See L<App::Termcast> for documentation.
=cut
-App::Termcast->new_with_options->run;
+my $tc = App::Termcast->new_with_options;
+my @argv = @{ $tc->extra_argv };
+push @argv, ($ENV{SHELL} || '/bin/sh') if !@argv;
+App::Termcast->new_with_options->run(@argv);
=head1 AUTHOR
diff --git a/lib/App/Termcast.pm b/lib/App/Termcast.pm
index bc0ff94..e0e2ec9 100644
--- a/lib/App/Termcast.pm
+++ b/lib/App/Termcast.pm
@@ -101,12 +101,7 @@ has pty => (
);
sub _build_pty {
- my $self = shift;
- my @argv = @{ $self->extra_argv };
- push @argv, ($ENV{SHELL} || '/bin/sh') if !@argv;
- my $pty = IO::Pty::Easy->new(raw => 0);
- $pty->spawn(@argv);
- return $pty;
+ IO::Pty::Easy->new(raw => 0);
}
sub _build_select_args {
@@ -168,10 +163,13 @@ sub write_to_termcast {
sub run {
my $self = shift;
+ my @cmd = @_;
ReadMode 5;
my $guard = Scope::Guard->new(sub { ReadMode 0 });
+ $self->pty->spawn(@cmd) || die "Couldn't spawn @cmd: $!";
+
local $SIG{WINCH} = sub { $self->_got_winch(1) };
while (1) {
my ($rin, $win, $ein) = $self->_build_select_args;
diff --git a/t/001-basic.t b/t/001-basic.t
index 6ec549d..7dd9a7e 100644
--- a/t/001-basic.t
+++ b/t/001-basic.t
@@ -16,9 +16,8 @@ test_tcp(
my $client_script = <<EOF;
use App::Termcast;
my \$tc = App::Termcast->new(host => '127.0.0.1', port => $port,
- user => 'test', password => 'tset',
- extra_argv => ['$^X', "-e", "print 'foo'"]);
- \$tc->run;
+ user => 'test', password => 'tset');
+ \$tc->run('$^X', "-e", "print 'foo'");
EOF
my $pty = IO::Pty::Easy->new;
$pty->spawn("$^X", "-e", $client_script);
diff --git a/t/002-read-write.t b/t/002-read-write.t
index 153f8c6..a03effb 100644
--- a/t/002-read-write.t
+++ b/t/002-read-write.t
@@ -17,9 +17,8 @@ test_tcp(
use App::Termcast;
my \$tc = App::Termcast->new(
host => '127.0.0.1', port => $port,
- user => 'test', password => 'tset',
- extra_argv => ['$^X', "-e", "while (<>) { last if /\\\\./; print }"]);
- \$tc->run;
+ user => 'test', password => 'tset');
+ \$tc->run('$^X', "-e", "while (<>) { last if /\\\\./; print }");
EOF
my $pty = IO::Pty::Easy->new;
$pty->spawn("$^X", "-e", $client_script);