---
name: "Catmandu::Buffer"
section: "3pm"
platform: "linux"
package: "libcatmandu-perl"
version: "1.2024-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::Buffer"
---

# Catmandu::Buffer(3pm)

A base class for modules that need an array buffer

## NAME

Catmandu::Buffer - A base class for modules that need an array buffer

## SYNOPSIS

```
    package MyPackage;
    use Moo;
    with 'Catmandu::Buffer';
    # Print only when the buffer is full...
    sub print {
        my ($self,$str) = @_;
        if ($self->buffer_is_full) {
           print join "\n" , @{ $self->buffer };
           $self->clear_buffer;
        }
        $self->buffer_add($str);
    }
    package main;
    my $x = MyPackage->new;
    for (my $i = 0 ; $i < 1000 ; $i++) {
        $x->print($x);
    }
```

## ATTRIBUTES

### buffer

A ARRAY reference to the content of the buffer.

### buffer\_size(MAX)

The maximum size of a buffer.

## METHODS

### clear\_buffer()

Empty the buffer.

### buffer\_used()

Returns a true value when there is content in the buffer.

### buffer\_is\_full()

Returns a true value when the buffer has reached its maximum capacity.

### buffer\_add($x)

Adds `$x` to the buffer.

## SEE ALSO

Catmandu::Solr::Bag
