| String-Buffer documentation | Contained in the String-Buffer distribution. |
String::Buffer - a simple string buffer class.
use String::Buffer;
my $buf = String::Buffer->new();
$buf->writeln('Foo');
print $buf->read();
$buf->flush();
$buf->write('Bar');
print $buf->flush();
String::Buffer provides a simple string buffer class.
Create a new buffer object. Accepts a string as an argument.
Add some text to the buffer.
Add some text to the buffer, with a new line at the end.
Return the here-to-forth buffered content.
Empty out the output buffer.
Steve McKay, steve@colgreen.com
Copyright 2001 by Steve McKay. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl(1).
| String-Buffer documentation | Contained in the String-Buffer distribution. |
package String::Buffer; # Copyright 2001 by Steve McKay. All rights reserved. # This library is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. use strict; use vars qw( @ISA $VERSION ); $VERSION = 0.05; *append = \&write; *appendln = \&writeln; sub new { my ( $proto, $str ) = @_; my $class = ref( $proto ) || $proto; my $self = { buffer => undef, }; $self->{buffer} = $str if $str; bless( $self, $class ); return $self; } sub write { my( $self, @val ) = @_; $self->{buffer} .= join( '', @val ); return undef; } sub writeln { my( $self, @val ) = @_; return $self->write( @val, "\n" ); } sub read { my( $self ) = @_; return $self->{buffer}; } sub flush { my( $self ) = @_; my $flushed = $self->read(); $self->{buffer} = undef; return $flushed; } 1; __END__