From 094e296335e1d6d5e3de0d0d5484cba83c8a85ae Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 24 Feb 2012 03:10:31 -0600 Subject: initial implementation --- lib/App/Ttyrec.pm | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'lib') diff --git a/lib/App/Ttyrec.pm b/lib/App/Ttyrec.pm index e69de29..e1ac0ae 100644 --- a/lib/App/Ttyrec.pm +++ b/lib/App/Ttyrec.pm @@ -0,0 +1,65 @@ +package App::Ttyrec; +use Moose; + +use Scalar::Util 'weaken'; +use Term::Filter; +use Tie::Handle::TtyRec; + +has ttyrec_file => ( + is => 'ro', + isa => 'Str', + default => 'ttyrecord', +); + +has append => ( + is => 'ro', + isa => 'Bool', + default => 0, +); + +has ttyrec => ( + is => 'ro', + isa => 'FileHandle', + lazy => 1, + default => sub { Tie::Handle::TtyRec->new(shift->ttyrec_file) }, +); + +has term => ( + is => 'ro', + isa => 'Term::Filter', + lazy => 1, + default => sub { + my $self = shift; + weaken(my $weakself = $self); + Term::Filter->new( + callbacks => { + munge_output => sub { + my ($event, $got) = @_; + + print { $weakself->ttyrec } $got; + + $got; + }, + }, + ); + }, +); + +sub BUILD { + my $self = shift; + + die "Appending is not currently supported" + if $self->append; +} + +sub run { + my $self = shift; + my (@cmd) = @_; + + $self->term->run(@cmd); +} + +__PACKAGE__->meta->make_immutable; +no Moose; + +1; -- cgit v1.2.3-54-g00ecf