From 9a1ed31cfdfa3556e2b22c5abb431f9dd1939ef3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 5 Mar 2012 02:30:24 -0600 Subject: actually, move the error to construction time --- lib/Term/Filter.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Term/Filter.pm b/lib/Term/Filter.pm index 9172fc2..6436478 100644 --- a/lib/Term/Filter.pm +++ b/lib/Term/Filter.pm @@ -4,9 +4,15 @@ use Moose; use IO::Pty::Easy; use IO::Select; +use Moose::Util::TypeConstraints 'subtype', 'as', 'where', 'message'; use Scope::Guard; use Term::ReadKey; +subtype 'Term::Filter::TtyFileHandle', + as 'FileHandle', + where { -t $_ }, + message { "Term::Filter requires input and output filehandles to be attached to a terminal" }; + has callbacks => ( is => 'ro', isa => 'HashRef[CodeRef]', @@ -38,7 +44,7 @@ sub _build_pty { IO::Pty::Easy->new(raw => 0) } has input => ( is => 'ro', - isa => 'FileHandle', + isa => 'Term::Filter::TtyFileHandle', lazy => 1, builder => '_build_input', ); @@ -47,7 +53,7 @@ sub _build_input { \*STDIN } has output => ( is => 'ro', - isa => 'FileHandle', + isa => 'Term::Filter::TtyFileHandle', lazy => 1, builder => '_build_output', ); @@ -197,5 +203,6 @@ sub _read_from_handle { __PACKAGE__->meta->make_immutable; no Moose; +no Moose::Util::TypeConstraints; 1; -- cgit v1.2.3