line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/coderepos/lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/Memory.pm 66567 2008-07-22T08:55:23.819173Z daisuke $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Data::Valve::BucketStore::Memory; |
4
|
1
|
|
|
1
|
|
2553
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'Data::Valve::BucketStore'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'store' => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'HashRef', |
11
|
|
|
|
|
|
|
required => 1, |
12
|
|
|
|
|
|
|
default => sub { +{} } |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
no Moose; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub fill { |
20
|
|
|
|
|
|
|
my ($self, %args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $bucket = $self->store()->{ $args{key} }; |
23
|
|
|
|
|
|
|
if (! $bucket) { |
24
|
|
|
|
|
|
|
$bucket = $self->create_bucket; |
25
|
|
|
|
|
|
|
$self->store()->{ $args{key} } = $bucket; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1 while ( $bucket->try_push() ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub reset { |
32
|
|
|
|
|
|
|
my ($self, %args) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $bucket = $self->store->{ $args{key} }; |
35
|
|
|
|
|
|
|
$bucket->reset(); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub create_bucket |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
return Data::Valve::Bucket->new( |
42
|
|
|
|
|
|
|
max_items => $self->max_items, |
43
|
|
|
|
|
|
|
interval => $self->interval, |
44
|
|
|
|
|
|
|
strict_interval => $self->strict_interval, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub try_push { |
49
|
|
|
|
|
|
|
my ($self, %args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $bucket = $self->store()->{ $args{key} }; |
52
|
|
|
|
|
|
|
if (! $bucket) { |
53
|
|
|
|
|
|
|
$bucket = $self->create_bucket; |
54
|
|
|
|
|
|
|
$self->store()->{ $args{key} } = $bucket; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return $bucket->try_push(); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Data::Valve::BucketStore::Memory - An In-Memory Bucket Store |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 METHODS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 fill |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 reset |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 create_bucket |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 try_push |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |