Ref/FIFO.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 4 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.9% 10 / 11 Podpod 100% 6 / 6 totaltotal 95.3% 61 / 64 CC 4 SCAR 4.5
CC
4
Cov
98%
set
3.0
expire
2.0
BEGIN
1.0
CRAP 1.6
« Ref/LIFO.pm ↑ Summary Ref/Null.pm »
1 package Cache::Ref::FIFO;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Cache::Ref::FIFO::AUTHORITY = 'cpan:NUFFIN';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Cache::Ref::FIFO::VERSION = '0.05'; # TRIAL
7 }
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 extends qw(Cache::Ref);
13  
14 1 with qw(
15 Cache::Ref::Role::API
16 Cache::Ref::Role::Index
17 );
18  
19 1 has size => (
20 isa => "Int",
21 is => "ro",
22 required => 1,
23 );
24  
25 has _fifo => (
26 isa => "ArrayRef",
27 is => "ro",
28 lazy => 1,
29 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 1 );
31  
32 1 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
33 1 my $self = shift;
34 1 $self->_index_clear;
35 1 @{ $self->_fifo } = ();
36 }
37  
38 0 ▶sub hit { }
Subroutine hit: not called CC=1 SCAR=0.0
Pod documented
39  
40 2 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
41 2 my ( $self, @keys ) = @_;
42  
43 2 $self->_index_delete(@keys);
44  
45 2 my %keys; @keys{@keys} = ();
46  
47 2 my $f = $self->_fifo;
48 2 @$f = grep { not exists $keys{$_} } @$f;
49  
50 2 return;
51 }
52  
53 3024 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
54 3024 my ( $self, @keys ) = @_;
55 3024 $self->_index_get(@keys);
56 }
57  
58 1757 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
59 1757 my ( $self, $key, $value ) = @_;
60  
61 1757 ▶ unless ( defined $self->_index_get($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_index_get($key)) 1756 1 1757
62 1756 ▶ if ( $self->_index_size >= $self->size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_index_size >= $self->size) 1747 9 1756
63 1747 $self->expire( 1 + $self->_index_size - $self->size );
64 }
65 1756 push @{ $self->_fifo }, $key;
66 }
67  
68 1757 $self->_index_set($key, $value);
69 }
70  
71 1748 ▶sub expire {
Subroutine expire: called CC=2 SCAR=7.0
Pod documented
72 1748 my ( $self, $how_many ) = @_;
73  
74 1748 ▶ $self->_index_delete( splice @{ $self->_fifo }, 0, $how_many || 1 );
Condition50%1/2
$how_many || 1
l!l
17480
MC/DC0%0/1
$how_many || 1
$how_many
Truth table50%1/2
A
A= $how_many
Aresult
11
00
75  
76 1748 return;
77 }
78  
79 1 __PACKAGE__->meta->make_immutable;
80  
81 # ex: set sw=4 et:
82  
83 1 __PACKAGE__;
84  
85  
86 __END__
« Ref/LIFO.pm ↑ Summary Ref/Null.pm »