From c2340699c7caea722dd43210cd8bca5fcea22a00 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 18 Apr 2010 17:20:06 -0500 Subject: stop using extra_argv directly, pass command to run to the run method --- bin/termcast | 5 ++++- lib/App/Termcast.pm | 10 ++++------ t/001-basic.t | 5 ++--- t/002-read-write.t | 5 ++--- 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 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 = <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); -- cgit v1.2.3-54-g00ecf