Leaky.pm

filter: Statementstmt 95.7% 45 / 47 Branchbran 50.0% 5 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 86.6% 65 / 75 CC 7 SCAR 9.0
CC
7
Cov
88%
clear
4.1
insert
4.0
fetch
2.0
CRAP 2.5
« Leaky/State/Memcached.pm ↑ Summary Leaky/Driver/Q4M.pm »
1 package Queue::Leaky;
2  
3 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Queue::Leaky::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.01';
7  
8 3 has 'max_items' => (
9 is => 'rw',
10 isa => 'Int',
11 required => 1,
12 default => 0,
13 );
14  
15 has 'key_generator' => (
16 is => 'rw',
17 isa => 'CodeRef',
18 required => 1,
19 3 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 12 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
21 12 my $self = shift;
22 12 $self->queue;
23 3 };
24 },
25 3 );
26  
27 {
28 3 ▶ my $default = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 6 my $class = shift;
30 6 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 6 Class::MOP::load_class($class);
32 6 $class->new;
33 6 };
34 3 };
35  
36 3 has 'queue' => (
37 is => 'rw',
38 does => 'Queue::Leaky::Driver',
39 required => 1,
40 coerce => 1,
41 default => $default->( 'Queue::Leaky::Driver::Simple' ),
42 handles => [ qw(next) ],
43 );
44  
45 has 'state' => (
46 is => 'rw',
47 does => 'Queue::Leaky::State',
48 required => 1,
49 coerce => 1,
50 default => $default->( 'Queue::Leaky::State::Memory' ),
51 handles => {
52 3 map { ("state_$_" => $_) } qw(get set remove incr decr)
53 }
54 );
55 }
56  
57 3 __PACKAGE__->meta->make_immutable;
58  
59 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 8 ▶sub insert {
Subroutine insert: called CC=4 SCAR=13.9
Pod undocumented
62 8 my $self = shift;
63  
64 8 my $key = $self->key_generator->($self, @_);
65 8 my $count = $self->state_incr($key);
66  
67 8 ▶ if ($self->max_items && $self->max_items < $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->max_items and $self->max_items < $count) 1 7 8
Condition100%3/3
$self->max_items and $self->max_items < $count
!ll&&!rl&&r
431
MC/DC100%2/2
$self->max_items and $self->max_items < $count
$self->max_items $self->max_items < $count
Truth table100%3/3
A and B
A= $self->max_itemsB= $self->max_items < $count
ABresult
0X0
100
111
68 1 $self->state_decr($key);
69 1 return ();
70 }
71  
72 7 my $rv = $self->queue->insert(@_);
73  
74 7 ▶ $self->state_decr($key) unless $rv;
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 7 7
75 7 return $rv;
76 }
77  
78 4 ▶sub fetch {
Subroutine fetch: called CC=2 SCAR=7.0
Pod undocumented
79 4 my $self = shift;
80  
81 4 my $rv = $self->queue->fetch(@_);
82  
83 4 ▶ if ($rv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv) 4 0 4
84 4 my $key = $self->key_generator->($self, @_);
85 4 $self->state_decr($key);
86 }
87 4 return $rv;
88 }
89  
90 2 ▶sub clear {
Subroutine clear: called CC=3 SCAR=14.2
Pod undocumented
91 2 my $self = shift;
92  
93 2 my $rv = $self->queue->clear(@_);
94  
95 2 ▶ if ($rv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv) 0 2 2
96 0 my $key = $self->key_generator->($self, @_);
97 0 ▶ $self->state_remove($key) if $key;
Branch: 1 branch
BranchTrueFalseTotal
if $key 0 0 0
98 }
99 2 return $rv;
100 }
101  
102 3 1;
103  
104 __END__
« Leaky/State/Memcached.pm ↑ Summary Leaky/Driver/Q4M.pm »