diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-10-10 01:02:26 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-10-10 01:02:26 -0500 |
commit | 4456438e4b5391e35cca9080b4bd1b13c2280870 (patch) | |
tree | a0ce4f1cb8b6120ff9b51ab65aa001980cb410bb /lib | |
parent | 58e96bde43e0abc92484464a134204018af45d76 (diff) | |
download | io-pty-easy-4456438e4b5391e35cca9080b4bd1b13c2280870.tar.gz io-pty-easy-4456438e4b5391e35cca9080b4bd1b13c2280870.zip |
break some circular references
Diffstat (limited to 'lib')
-rw-r--r-- | lib/IO/Pty/Easy.pm | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/IO/Pty/Easy.pm b/lib/IO/Pty/Easy.pm index 7ed1be0..e29f25b 100644 --- a/lib/IO/Pty/Easy.pm +++ b/lib/IO/Pty/Easy.pm @@ -4,6 +4,7 @@ use strict; use base 'IO::Pty'; use Carp; use POSIX (); +use Scalar::Util qw(weaken); =head1 NAME @@ -91,6 +92,7 @@ sub new { $self->def_max_read_chars($def_max_read_chars); ${*{$self}}{io_pty_easy_raw} = $raw; ${*{$self}}{io_pty_easy_final_output} = ''; + ${*{$self}}{io_pty_easy_did_handle_pty_size} = 0; return $self; } @@ -172,13 +174,15 @@ sub spawn { croak "Cannot exec(@_): $errno"; } - my $winch; - $winch = sub { - $self->slave->clone_winsize_from(\*STDIN); - kill WINCH => $self->pid if $self->is_active; - $SIG{WINCH} = $winch; - }; - $SIG{WINCH} = $winch if $self->handle_pty_size; + if ($self->handle_pty_size) { + my $weakself = weaken($self); + $SIG{WINCH} = sub { + return unless $weakself; + $weakself->slave->clone_winsize_from(\*STDIN); + kill WINCH => $weakself->pid if $weakself->is_active; + }; + ${*{$self}}{io_pty_easy_did_handle_pty_size} = 1; + } } =head2 read() @@ -274,7 +278,9 @@ sub is_active { $active = 0 if $pid == $self->pid; } if (!$active) { - $SIG{WINCH} = 'DEFAULT' if $self->handle_pty_size; + $SIG{WINCH} = 'DEFAULT' + if ${*{$self}}{io_pty_easy_did_handle_pty_size}; + ${*{$self}}{io_pty_easy_did_handle_pty_size} = 0; delete ${*{$self}}{io_pty_easy_pid}; } return $active; |