File Coverage

blib/lib/Cassandra/Client/Policy/Queue/Default.pm
Criterion Covered Total %
statement 8 24 33.3
branch 0 2 0.0
condition 0 5 0.0
subroutine 3 6 50.0
pod 0 3 0.0
total 11 40 27.5


line stmt bran cond sub pod time code
1             package Cassandra::Client::Policy::Queue::Default;
2             our $AUTHORITY = 'cpan:TVDW';
3             $Cassandra::Client::Policy::Queue::Default::VERSION = '0.21';
4 13     13   301 use 5.010;
  13         89  
5 13     13   84 use strict;
  13         44  
  13         429  
6 13     13   71 use warnings;
  13         21  
  13         4325  
7              
8             sub new {
9 0     0 0   my ($class, %args)= @_;
10              
11 0   0       my $max_entries= $args{max_entries} || 0; # Default: never overflow
12              
13 0           return bless {
14             max_entries => 0+ $max_entries,
15             has_any => 0, # We're using this as a count.
16             queue => [],
17             }, $class;
18             }
19              
20             sub enqueue {
21 0     0 0   my ($self, $item)= @_;
22              
23 0 0 0       if ($self->{max_entries} && $self->{has_any} >= $self->{max_entries}) {
24 0           return "command queue full: $self->{has_any} entries";
25             }
26              
27 0           push @{$self->{queue}}, $item;
  0            
28 0           $self->{has_any}++;
29 0           return;
30             }
31              
32             sub dequeue {
33 0     0 0   my ($self)= @_;
34 0           my $item= shift @{$self->{queue}};
  0            
35 0           $self->{has_any}= 0+@{$self->{queue}};
  0            
36 0           return $item;
37             }
38              
39             1;
40              
41             __END__