Catmandu::Buffer(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– Catmandu::Buffer πŸ’–

okay so bestie, welcome to Catmandu::Buffer β€” it's a base class for modules that need an array buffer. that's the whole vibe. it's giving "scaffolding, but make it chic" 🫢

this page lives in the User Contributed Perl Documentation section, and it's filed under Catmandu::Buffer(3pm), iykyk.


✨ SYNOPSIS ✨

here's the whole thing, copied with love (and zero edits, because we do NOT play with code):

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);
}

see how it works? you with 'Catmandu::Buffer' (Moo role energy πŸ’…), and then your print sub only actually prints when the buffer is full. the comment in the source literally says # Print only when the buffer is full... so that's the whole point, no cap. when it IS full you print join "\n" , @{ $self->buffer };, then $self->clear_buffer;, and either way you always $self->buffer_add($str); at the end. then in package main we make a MyPackage->new and loop for (my $i = 0 ; $i < 1000 ; $i++) calling $x->print($x);. iconic. runs 1000 times. periodt.


πŸŽ€ ATTRIBUTES πŸŽ€

buffer

a ARRAY reference to the content of the buffer. yes, "a ARRAY", we're quoting the original grammar and we're not sorry, it's part of the lore. 🌸

buffer_size(MAX)

the maximum size of a buffer. so like, the cap. the limit. the "bestie we're full" moment. MAX is what you pass in. πŸ’œ


πŸ¦‹ METHODS πŸ¦‹

clear_buffer()

empty the buffer. poof. gone. ✨

buffer_used()

returns a true value when there is content in the buffer. so it's basically asking "is there anything in there??" and getting a yes or a nothing. πŸ™ˆ

buffer_is_full()

returns a true value when the buffer has reached its maximum capacity. this is the vibe check your print sub does before it dumps everything out. πŸ”₯

buffer_add($x)

adds $x to the buffer. that's it. that's the method. little king behavior πŸ‘‘


🌈 SEE ALSO 🌈

  • Catmandu::Solr::Bag

go look at it, it's right there, be nosy. πŸ‘€


and that's the page, bestie!! this one was perl v5.40.1, dated 2026-01-24, and it's the Catmandu::Buffer(3pm) manpage β€” mwah, go buffer something responsibly 🩷✨

πŸ“¦ where this page comes from