| 1 | # $Id: /mirror/coderepos/lang/perl/Data-Valve/trunk/lib/Data/Valve.pm 87019 2008-10-02T02:11:03.080140Z daisuke $ | ||||||||||||
| 2 | |||||||||||||
| 3 | package Data::Valve; | ||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use Data::Valve::Bucket; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use Scalar::Util (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 1 | ▶ | use XSLoader; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | our $VERSION = '0.00010'; | |||||||||||
| 10 | 1 | our $AUTHORITY = 'cpan:DMAKI'; | |||||||||||
| 11 | |||||||||||||
| 12 | 1 | XSLoader::load __PACKAGE__, $VERSION; | |||||||||||
| 13 | |||||||||||||
| 14 | 1 | has 'max_items' => ( | |||||||||||
| 15 | is => 'rw', | ||||||||||||
| 16 | isa => 'Int', | ||||||||||||
| 17 | required => 1 | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | |||||||||||||
| 20 | 1 | has 'interval' => ( | |||||||||||
| 21 | is => 'rw', | ||||||||||||
| 22 | isa => 'Num', | ||||||||||||
| 23 | required => 1 | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 1 | has 'strict_interval' => ( | |||||||||||
| 27 | is => 'rw', | ||||||||||||
| 28 | isa => 'Bool', | ||||||||||||
| 29 | required => 1, | ||||||||||||
| 30 | default => 0 | ||||||||||||
| 31 | ); | ||||||||||||
| 32 | |||||||||||||
| 33 | 1 | has '__bucket_store' => ( | |||||||||||
| 34 | accessor => 'bucket_store', | ||||||||||||
| 35 | is => 'rw', | ||||||||||||
| 36 | does => 'Data::Valve::BucketStore', | ||||||||||||
| 37 | required => 1, | ||||||||||||
| 38 | ); | ||||||||||||
| 39 | |||||||||||||
| 40 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 41 | |||||||||||||
| 42 | 1 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | |||||||||||||
| 44 | 0 | ▶ | sub BUILDARGS { | ||||||||||
|
Subroutine
BUILDARGS: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 45 | 0 | my ($self, %args) = @_; | |||||||||||
| 46 | |||||||||||||
| 47 | 0 | ▶ | my $store = delete $args{bucket_store} || { module => 'Memory' }; | ||||||||||
|
Condition0%0/2
delete $args{'bucket_store'} || {'module', 'Memory'}
MC/DC0%0/1
delete $args{'bucket_store'} || {'module', 'Memory'}
delete $args{'bucket_store'}
Truth table0%0/2
A
A= delete $args{'bucket_store'}
| |||||||||||||
| 48 | 0 | ▶ | if (! Scalar::Util::blessed($store) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | my $module = $store->{module}; | |||||||||||
| 50 | 0 | ▶ | if ($module !~ s/^\+//) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 0 | $module = "Data::Valve::BucketStore::$module"; | |||||||||||
| 52 | } | ||||||||||||
| 53 | 0 | Class::MOP::load_class($module); | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | $store = $module->new( %{ $store->{args} } ); | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 0 | ▶ | if ($args{strict_interval}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | # in strict_interval mode, max_items doesn't mean anything | ||||||||||||
| 60 | 0 | $args{max_items} = 0; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | return { %args, __bucket_store => $store }; | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 0 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 67 | 0 | my $self = shift; | |||||||||||
| 68 | 0 | $self->bucket_store->context($self); | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | sub try_push { | ||||||||||
|
Subroutine
try_push: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 72 | 0 | my ($self, %args) = @_; | |||||||||||
| 73 | 0 | ▶ | $args{key} ||= '__default'; | ||||||||||
|
Condition0%0/2
$args{"key"} ||= "__default"
MC/DC0%0/1
$args{"key"} ||= "__default"
$args{"key"}
Truth table0%0/2
A
A= $args{"key"}
| |||||||||||||
| 74 | 0 | $self->bucket_store->try_push(%args); | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | 0 | ▶ | sub reset { | ||||||||||
|
Subroutine
reset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 78 | 0 | my ($self, %args) = @_; | |||||||||||
| 79 | 0 | ▶ | $args{key} ||= '__default'; | ||||||||||
|
Condition0%0/2
$args{"key"} ||= "__default"
MC/DC0%0/1
$args{"key"} ||= "__default"
$args{"key"}
Truth table0%0/2
A
A= $args{"key"}
| |||||||||||||
| 80 | 0 | $self->bucket_store->reset(%args); | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 0 | ▶ | sub fill { | ||||||||||
|
Subroutine
fill: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 84 | 0 | my ($self, %args) = @_; | |||||||||||
| 85 | 0 | ▶ | $args{key} ||= '__default'; | ||||||||||
|
Condition0%0/2
$args{"key"} ||= "__default"
MC/DC0%0/1
$args{"key"} ||= "__default"
$args{"key"}
Truth table0%0/2
A
A= $args{"key"}
| |||||||||||||
| 86 | 0 | $self->bucket_store->fill(%args); | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 1 | 1; | |||||||||||
| 90 | |||||||||||||
| 91 | __END__ | ||||||||||||