| 1 | package Cache::Sliding; | ||||||||||||||
| 2 | 2 | ▶ | use 5.010001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | our $VERSION = 'v2.0.1'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 2 | ▶ | use EV; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | |||||||||||||||
| 14 | 3 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 15 | 3 | my ($class, $expire_after) = @_; | |||||||||||||
| 16 | 3 | my $self = { | |||||||||||||
| 17 | L1 => {}, | ||||||||||||||
| 18 | L2 => {}, | ||||||||||||||
| 19 | t => undef, | ||||||||||||||
| 20 | }; | ||||||||||||||
| 21 | 3 | weaken(my $this = $self); | |||||||||||||
| 22 | 34 | ▶ | $self->{t} = EV::timer $expire_after, $expire_after, sub { if ($this) { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||
| 23 | 34 | $this->{L2} = $this->{L1}; | |||||||||||||
| 24 | 34 | $this->{L1} = {}; | |||||||||||||
| 25 | 3 | } }; | |||||||||||||
| 26 | 3 | return bless $self, $class; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 10 | ▶ | sub get { | ||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 30 | 10 | my ($self, $key) = @_; | |||||||||||||
| 31 | 10 | ▶ | if (exists $self->{L1}{$key}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | 4 | return $self->{L1}{$key}; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | elsif (exists $self->{L2}{$key}) { | ||||||||||||||
| 35 | 3 | return ($self->{L1}{$key} = delete $self->{L2}{$key}); | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | 3 | return; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 3 | ▶ | sub set { ## no critic (ProhibitAmbiguousNames) | ||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 41 | 3 | my ($self, $key, $value) = @_; | |||||||||||||
| 42 | 3 | return ($self->{L1}{$key} = $value); | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 1 | ▶ | sub del { | ||||||||||||
|
Subroutine
del: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 46 | 1 | my ($self, $key) = @_; | |||||||||||||
| 47 | 1 | delete $self->{L2}{$key}; | |||||||||||||
| 48 | 1 | delete $self->{L1}{$key}; | |||||||||||||
| 49 | 1 | return; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | |||||||||||||||
| 53 | 2 | 1; # Magic true value required at end of module | |||||||||||||
| 54 | __END__ | ||||||||||||||