diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-02-24 03:10:31 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-02-24 03:10:31 -0600 |
commit | 094e296335e1d6d5e3de0d0d5484cba83c8a85ae (patch) | |
tree | d9daa65d83e5a5b88083861bb193c31d97badc72 /lib | |
parent | db52c05fded92da62425482a96b9bf2a4f1495ea (diff) | |
download | app-ttyrec-094e296335e1d6d5e3de0d0d5484cba83c8a85ae.tar.gz app-ttyrec-094e296335e1d6d5e3de0d0d5484cba83c8a85ae.zip |
initial implementation
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/Ttyrec.pm | 65 |
1 files changed, 65 insertions, 0 deletions
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; |