line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Ref::Random; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
1051
|
$Cache::Ref::Random::AUTHORITY = 'cpan:NUFFIN'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
17
|
$Cache::Ref::Random::VERSION = '0.05'; # TRIAL |
7
|
|
|
|
|
|
|
} |
8
|
1
|
|
|
1
|
|
471
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use namespace::autoclean; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
extends qw(Cache::Ref); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with qw( |
15
|
|
|
|
|
|
|
Cache::Ref::Role::API |
16
|
|
|
|
|
|
|
Cache::Ref::Role::Index |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has size => ( |
20
|
|
|
|
|
|
|
isa => "Int", |
21
|
|
|
|
|
|
|
is => "ro", |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub clear { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
$self->_index_clear; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub hit { } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub remove { |
33
|
|
|
|
|
|
|
my ( $self, @keys ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->_index_delete(@keys); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
41
|
|
|
|
|
|
|
my ( $self, @keys ) = @_; |
42
|
|
|
|
|
|
|
$self->_index_get(@keys); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub set { |
46
|
|
|
|
|
|
|
my ( $self, $key, $value ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
unless ( defined $self->_index_get($key) ) { |
49
|
|
|
|
|
|
|
if ( $self->_index_size >= $self->size ) { |
50
|
|
|
|
|
|
|
$self->expire( 1 + $self->_index_size - $self->size ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->_index_set($key, $value); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub expire { |
58
|
|
|
|
|
|
|
my ( $self, $how_many ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my @s = ( 0 .. $self->_index_size - 1); |
61
|
|
|
|
|
|
|
my @slice = map { splice @s, int rand @s, 1 } 1 .. ($how_many || 1); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my @keys = ($self->_index_keys)[@slice]; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->_index_delete(@keys); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__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__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# ex: set sw=4 et: |