line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Buffer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
105233
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
393
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has buffer_size => (is => 'ro', lazy => 1, builder => 'default_buffer_size'); |
11
|
|
|
|
|
|
|
has buffer => (is => 'rwp', lazy => 1, default => sub {[]}); |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
0
|
6327
|
sub default_buffer_size {100} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub clear_buffer { |
16
|
1
|
|
|
1
|
1
|
10
|
$_[0]->_set_buffer([]); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub buffer_used { |
20
|
7
|
|
|
7
|
1
|
677
|
scalar @{$_[0]->buffer}; |
|
7
|
|
|
|
|
182
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub buffer_is_full { |
24
|
3
|
|
|
3
|
1
|
3647
|
my $self = $_[0]; |
25
|
3
|
100
|
|
|
|
11
|
$self->buffer_used >= $self->buffer_size ? 1 : 0; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub buffer_add { |
29
|
2
|
|
|
2
|
1
|
47
|
my $buffer = shift->buffer; |
30
|
2
|
|
|
|
|
20
|
push @$buffer, @_; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Catmandu::Buffer - A base class for modules that need an array buffer |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
package MyPackage; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Moo; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
with 'Catmandu::Buffer'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Print only when the buffer is full... |
52
|
|
|
|
|
|
|
sub print { |
53
|
|
|
|
|
|
|
my ($self,$str) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($self->buffer_is_full) { |
56
|
|
|
|
|
|
|
print join "\n" , @{ $self->buffer }; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->clear_buffer; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->buffer_add($str); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
package main; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $x = MyPackage->new; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
for (my $i = 0 ; $i < 1000 ; $i++) { |
69
|
|
|
|
|
|
|
$x->print($x); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 buffer |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
A ARRAY reference to the content of the buffer. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 buffer_size(MAX) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The maximum size of a buffer. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 clear_buffer() |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Empty the buffer. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 buffer_used() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns a true value when there is content in the buffer. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 buffer_is_full() |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns a true value when the buffer has reached its maximum capacity. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 buffer_add($x) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Adds $x to the buffer. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L<Catmandu::Solr::Bag> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |