From 4456438e4b5391e35cca9080b4bd1b13c2280870 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 10 Oct 2009 01:02:26 -0500 Subject: break some circular references --- dist.ini | 3 ++- lib/IO/Pty/Easy.pm | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/dist.ini b/dist.ini index 8444990..0aa7a76 100644 --- a/dist.ini +++ b/dist.ini @@ -8,4 +8,5 @@ abstract = Easy interface to IO::Pty [@Classic] [Prereq] -IO::Pty = 0 +IO::Pty = 0 +Scalar::Util = 0 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; -- cgit v1.2.3