Cache/RemovalStrategy/FIFO.pm

filter: Statementstmt 100% 24 / 24 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 92.1% 35 / 38 CC 4 SCAR 6.4
CC
4
Cov
93%
remove_size
3.0
new
2.0
BEGIN
1.0
CRAP 1.9
« Cache/Entry.pm ↑ Summary Cache/RemovalStrategy/LRU.pm »
1 =head1 NAME
2  
3 Cache::RemovalStrategy::FIFO - FIFO Removal Strategy for a Cache
4  
5 =head1 DESCRIPTION
6  
7 Implements a First In First Out removal strategy for a Cache. When removing
8 entries from the cache, the 'oldest' will be removed first.
9  
10 =head1 METHODS
11  
12 See Cache::RemovalStrategy for details.
13  
14 =cut
15 package Cache::RemovalStrategy::FIFO;
16  
17 2 require 5.006;
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use base qw(Cache::RemovalStrategy);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use fields qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
26 1 my Cache::RemovalStrategy::FIFO $self = shift;
27  
28 1 ▶ $self = fields::new($self) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
29 1 $self->SUPER::new(@_);
30  
31 1 return $self;
32 }
33  
34  
35 4 ▶sub remove_size {
Subroutine remove_size: called CC=3 SCAR=11.0
Pod documented
36 4 my Cache::RemovalStrategy::FIFO $self = shift;
37 4 my ($cache, $size) = @_;
38  
39 4 ▶ while ($size > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 0) 4 4 8
40 4 my $removed = $cache->remove_oldest();
41 4 ▶ defined $removed or last;
Branch: 1 branch
BranchTrueFalseTotal
defined $removed or last 4 0 4
42 4 $size -= $removed;
43 }
44 }
45  
46  
47 2 1;
48 __END__
« Cache/Entry.pm ↑ Summary Cache/RemovalStrategy/LRU.pm »