line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Alice::MessageStore::Memory; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use Any::Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has msgbuffer => ( |
6
|
|
|
|
|
|
|
is => 'rw', |
7
|
|
|
|
|
|
|
isa => 'ArrayRef', |
8
|
|
|
|
|
|
|
default => sub {[]} |
9
|
|
|
|
|
|
|
); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has buffersize => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
default => 100 |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub add { |
17
|
18
|
|
|
18
|
0
|
35
|
my ($self, $message) = @_; |
18
|
18
|
|
|
|
|
27
|
push @{$self->msgbuffer}, $message; |
|
18
|
|
|
|
|
81
|
|
19
|
18
|
50
|
|
|
|
28
|
if (@{$self->msgbuffer} > $self->buffersize) { |
|
18
|
|
|
|
|
174
|
|
20
|
0
|
|
|
|
|
|
shift @{$self->msgbuffer}; |
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub clear { |
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
26
|
0
|
|
|
|
|
|
$self->msgbuffer([]); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub with_messages { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, $cb, $start, $complete_cb) = @_; |
31
|
0
|
|
|
|
|
|
$cb->(@{ $self->msgbuffer }); |
|
0
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
$complete_cb->() if $complete_cb; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
36
|
|
|
|
|
|
|
1; |