
Mojo::Buffer - A Simple In-Memory Buffer

use Mojo::Buffer;
my $buffer = Mojo::Buffer->new('foo');
$buffer->add_chunk('bar');
my $foo = $buffer->remove(3);
my $bar = $buffer->empty;

Mojo::Buffer is a simple in-memory buffer. Functionality includes keeping track of the cumulative raw character length that has been in the buffer. Content may removed from the buffer by line or character count.

lengthmy $length = $buffer->length;
raw_lengthmy $raw_length = $buffer->raw_length;
Returns the cumulative length of the buffer. It never decreases.

Mojo::Buffer inherits all methods from Mojo::Base and implements the following new ones.
new my $buffer = Mojo::Buffer->new;
my $buffer = Mojo::Buffer->new('foobarbaz');
Returns a new Mojo::Buffer object, and possibly adds content to it.
add_chunk $buffer = $buffer->add_chunk('foo');
Returns the invocant and adds additional content to the buffer.
emptymy $string = $buffer->empty;
Returns the whole content of the buffer and empties it.
get_linemy $line = $buffer->get_line;
Returns a whole line if a newline is present in the buffer or undef, even if there is content in the buffer.
removemy $string = $buffer->remove(4);
Returns and removes a specific number of bytes from the buffer.
to_stringmy $string = $buffer->to_string;
Returns the whole buffer content at once.