| 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 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | with 'Data::Valve::BucketStore'; | |||||||||
| 7 | |||||||||||
| 8 | has 'store' => ( | ||||||||||
| 9 | is => 'rw', | ||||||||||
| 10 | isa => 'HashRef', | ||||||||||
| 11 | required => 1, | ||||||||||
| 12 | 0 | ▶ | default => sub { +{} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 13 | 1 | ); | |||||||||
| 14 | |||||||||||
| 15 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub fill { | ||||||||
|
Subroutine
fill: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 20 | 0 | my ($self, %args) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 0 | my $bucket = $self->store()->{ $args{key} }; | |||||||||
| 23 | 0 | ▶ | if (! $bucket) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | $bucket = $self->create_bucket; | |||||||||
| 25 | 0 | $self->store()->{ $args{key} } = $bucket; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | 1 while ( $bucket->try_push() ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub reset { | ||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 32 | 0 | my ($self, %args) = @_; | |||||||||
| 33 | |||||||||||
| 34 | 0 | my $bucket = $self->store->{ $args{key} }; | |||||||||
| 35 | 0 | $bucket->reset(); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub create_bucket | ||||||||||
| 39 | 0 | ▶ | { | ||||||||
|
Subroutine
create_bucket: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 40 | 0 | my $self = shift; | |||||||||
| 41 | 0 | 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 | 0 | ▶ | sub try_push { | ||||||||
|
Subroutine
try_push: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 49 | 0 | my ($self, %args) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 0 | my $bucket = $self->store()->{ $args{key} }; | |||||||||
| 52 | 0 | ▶ | if (! $bucket) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | $bucket = $self->create_bucket; | |||||||||
| 54 | 0 | $self->store()->{ $args{key} } = $bucket; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | return $bucket->try_push(); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 1 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||