/usr/share/perl5/Catmandu/Buffer.pm is in libcatmandu-perl 0.9206-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | package Catmandu::Buffer;
=head1 NAME
Catmandu::Buffer - A base class for modules that need an array buffer
=head1 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);
}
=head1 ATTRIBUTES
=head2 buffer
A ARRAY reference to the content of the buffer.
=head2 buffer_size(MAX)
The maximum size of a buffer.
=head1 METHODS
=head2 clear_buffer()
Empty the buffer.
=head2 buffer_used()
Returns a true value when there is content in the buffer.
=head2 buffer_is_full()
Returns a true value when the buffer has reached its maximum capacity.
=head2 buffer_add($x)
Adds $x to the buffer.
=head1 SEE ALSO
L<Catmandu::Solr::Bag>
=cut
use namespace::clean;
use Catmandu::Sane;
use Moo::Role;
has buffer_size => (is => 'ro', lazy => 1, builder => 'default_buffer_size');
has buffer => (is => 'rwp', lazy => 1, default => sub { [] });
sub default_buffer_size { 100 }
sub clear_buffer {
$_[0]->_set_buffer([]);
}
sub buffer_used {
scalar @{$_[0]->buffer};
}
sub buffer_is_full {
my $self = $_[0];
$self->buffer_used >= $self->buffer_size ? 1 : 0;
}
sub buffer_add {
my $buffer = shift->buffer;
push @$buffer, @_;
}
1;
|