Ref/Random.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 80.0% 8 / 10 Podpod 100% 6 / 6 totaltotal 85.4% 47 / 55 CC 4 SCAR 5.3
CC
4
Cov
87%
set
3.0
expire
2.0
remove
2.0
CRAP 1.7
« Ref/Util/LRU/List.pm ↑ Summary Ref/LIFO.pm »
1 package Cache::Ref::Random;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Cache::Ref::Random::AUTHORITY = 'cpan:NUFFIN';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Cache::Ref::Random::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 10 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
26 10 my $self = shift;
27 10 $self->_index_clear;
28 }
29  
30 0 ▶sub hit { }
Subroutine hit: not called CC=1 SCAR=0.0
Pod documented
31  
32 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
33 0 my ( $self, @keys ) = @_;
34  
35 0 $self->_index_delete(@keys);
36  
37 0 return;
38 }
39  
40 2800 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
41 2800 my ( $self, @keys ) = @_;
42 2800 $self->_index_get(@keys);
43 }
44  
45 2332 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
46 2332 my ( $self, $key, $value ) = @_;
47  
48 2332 ▶ unless ( defined $self->_index_get($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_index_get($key)) 2332 0 2332
49 2332 ▶ if ( $self->_index_size >= $self->size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_index_size >= $self->size) 1327 1005 2332
50 1327 $self->expire( 1 + $self->_index_size - $self->size );
51 }
52 }
53  
54 2332 $self->_index_set($key, $value);
55 }
56  
57 1337 ▶sub expire {
Subroutine expire: called CC=2 SCAR=7.0
Pod documented
58 1337 my ( $self, $how_many ) = @_;
59  
60 1337 my @s = ( 0 .. $self->_index_size - 1);
61 1337 ▶ my @slice = map { splice @s, int rand @s, 1 } 1 .. ($how_many || 1);
Condition50%1/2
$how_many || 1
l!l
13370
MC/DC0%0/1
$how_many || 1
$how_many
Truth table50%1/2
A
A= $how_many
Aresult
11
00
62  
63 1337 my @keys = ($self->_index_keys)[@slice];
64  
65 1337 $self->_index_delete(@keys);
66  
67 1337 return;
68 }
69  
70 1 __PACKAGE__->meta->make_immutable;
71  
72 1 __PACKAGE__;
73  
74  
75  
76 =pod
77  
78 =encoding utf-8
79  
80 =head1 NAME
81  
82 Cache::Ref::Random
83  
84 =head1 AUTHOR
85  
86 Yuval Kogman
87  
88 =head1 COPYRIGHT AND LICENSE
89  
90 This software is copyright (c) 2011 by Yuval Kogman.
91  
92 This is free software; you can redistribute it and/or modify it under
93 the same terms as the Perl 5 programming language system itself.
94  
95 =cut
96  
97  
98 __END__
« Ref/Util/LRU/List.pm ↑ Summary Ref/LIFO.pm »