summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-03-05 02:30:24 -0600
committerJesse Luehrs <doy@tozt.net>2012-03-05 02:30:24 -0600
commit9a1ed31cfdfa3556e2b22c5abb431f9dd1939ef3 (patch)
tree3cc423304615afe34dfe6452ac6d20ca9c39bcc8
parentb3f1bda4fc4015d1fef9e6ba07e5340b7b41308c (diff)
downloadterm-filter-9a1ed31cfdfa3556e2b22c5abb431f9dd1939ef3.tar.gz
term-filter-9a1ed31cfdfa3556e2b22c5abb431f9dd1939ef3.zip
actually, move the error to construction time
-rw-r--r--lib/Term/Filter.pm11
1 files 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;