Thread STDOUT in einen eigenen Puffer
(7 answers)
Opened by rosti at 2012-12-16 11:20 2012-12-17T10:43:37 payx Oh, sorry, OutBuffer ist ein eigenes Modul, das verwendet File::Temp ;) Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 package OutBuffer; use strict; use warnings; use File::Temp qw(tempfile); use Carp; sub new{ my $class = shift; my %in = ( tmpdir => '/tmp', @_); my $self = bless{}, $class; return eval{ croak "Dir '$in{tmpdir}' does'nt exists" if not -d $in{tmpdir}; croak "No write permission to '$in{tmpdir}'" if not -w $in{tmpdir}; ($self->{FH}, $self->{FN}) = tempfile(DIR => $in{tmpdir}) or croak "Can't create tmp FH, FN"; $self; }; } sub start{ my $self = shift; select $self->{FH}; } # from temp Handle to STDOUT sub out{ my $self = shift; seek $self->{FH}, 0,0; select STDOUT; while(read $self->{FH}, my $buffer, 1024){ print $buffer } } # delete tmp File sub DESTROY{ my $self = shift; close $self->{FH} if defined $self->{FH}; unlink $self->{FN} if defined $self->{FN}; select STDOUT; } 1;################################################################################################## |