From 35e015fd125c305380291b44086d4781d41a5e76 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 5 Mar 2012 22:24:17 -0600 Subject: add remove_input_handle method --- lib/Term/Filter.pm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/Term/Filter.pm b/lib/Term/Filter.pm index e82c94e..3f161a1 100644 --- a/lib/Term/Filter.pm +++ b/lib/Term/Filter.pm @@ -77,15 +77,21 @@ sub _build_output { \*STDOUT } =cut +=method remove_input_handle + +=cut + has input_handles => ( traits => ['Array'], isa => 'ArrayRef[FileHandle]', lazy => 1, init_arg => undef, builder => '_build_input_handles', + writer => '_set_input_handles', handles => { - input_handles => 'elements', - add_input_handle => 'push', + input_handles => 'elements', + add_input_handle => 'push', + _grep_input_handles => 'grep', }, ); @@ -94,6 +100,15 @@ sub _build_input_handles { [ $self->input, $self->pty ] } +sub remove_input_handle { + my $self = shift; + my ($fh) = @_; + $self->_set_input_handles( + [ $self->_grep_input_handles(sub { $_ != $fh }) ] + ); + $self->_clear_select; +} + =attr pty =cut @@ -108,10 +123,11 @@ has pty => ( sub _build_pty { IO::Pty::Easy->new(raw => 0) } has _select => ( - is => 'ro', - isa => 'IO::Select', - lazy => 1, + is => 'ro', + isa => 'IO::Select', + lazy => 1, builder => '_build_select', + clearer => '_clear_select', ); sub _build_select { -- cgit v1.2.3