| 1 | package POE::Component::Cache; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 1 | ▶ | use bytes; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 1 | ▶ | use POE; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 1 | our $VERSION = '0.1.1'; | |||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | sub new() | ||||||||||||||||||
| 12 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||
| 13 | 0 | my ($class) = shift; | |||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 0 | my $name = $class . '->new()'; | |||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | 0 | ▶ | die "$name requires an even number of arguments" unless (@_ & 1); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 18 | 0 | my %params = @_; | |||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 0 | my $life = delete $params{LifeTime}; | |||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 0 | ▶ | if($life =~ /m$/) | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 23 | { | ||||||||||||||||||
| 24 | 0 | $life =~ s/m//; | |||||||||||||||||
| 25 | 0 | $life *= 60; | |||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | } elsif ($life =~ /s$/) { | ||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | 0 | $life =~ s/s//; | |||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | } elsif ($life =~ /^\d+$/) { | ||||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | } else { | ||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 0 | die "The $name LifeTime parameter must be a". | |||||||||||||||||
| 36 | " number or a number ending in 's' or 'm'"; | ||||||||||||||||||
| 37 | } | ||||||||||||||||||
| 38 | |||||||||||||||||||
| 39 | 0 | my $alias = delete $params{Alias}; | |||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | 0 | ▶ | $alias = defined($alias) ? $alias : 'POCO::CACHE'; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 0 | POE::Session->create( | |||||||||||||||||
| 44 | inline_states => { | ||||||||||||||||||
| 45 | _start => \&start, | ||||||||||||||||||
| 46 | _stop => \&stop, | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | store => \&store, | ||||||||||||||||||
| 49 | retrieve => \&retrieve, | ||||||||||||||||||
| 50 | status => \&status, | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | adjust_life => \&adjust_life, | ||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | _cache_death => \&cache_death | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | }, | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | heap => { | ||||||||||||||||||
| 59 | CONFIG => { | ||||||||||||||||||
| 60 | life => $life, | ||||||||||||||||||
| 61 | alias => $alias | ||||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | }, | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | ); | ||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | 0 | return undef; | |||||||||||||||||
| 68 | } | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | sub start() | ||||||||||||||||||
| 71 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 72 | 0 | my ($kernel, $heap) = @_[KERNEL, HEAP]; | |||||||||||||||||
| 73 | 0 | $kernel->alias_set($heap->{'CONFIG'}->{'alias'}); | |||||||||||||||||
| 74 | 0 | $heap->{'CACHE_TABLE'} = {}; | |||||||||||||||||
| 75 | } | ||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | sub stop() | ||||||||||||||||||
| 78 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 79 | 0 | my ($kernel, $heap) = @_[KERNEL, HEAP]; | |||||||||||||||||
| 80 | 0 | $kernel->alias_remove(); | |||||||||||||||||
| 81 | 0 | delete $heap->{'CACHE_TABLE'}; | |||||||||||||||||
| 82 | 0 | $kernel->alarm_remove_all(); | |||||||||||||||||
| 83 | } | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | sub store() | ||||||||||||||||||
| 86 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
store: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 87 | 0 | my ($kernel, $heap, $key, $ref) = @_[KERNEL, HEAP, ARG0, ARG1]; | |||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | 0 | $heap->{'CACHE_TABLE'}->{$key} = $ref; | |||||||||||||||||
| 90 | 0 | $kernel->delay_set('_cache_death', $heap->{'CONFIG'}->{'life'}, $key); | |||||||||||||||||
| 91 | |||||||||||||||||||
| 92 | } | ||||||||||||||||||
| 93 | |||||||||||||||||||
| 94 | sub retrieve() | ||||||||||||||||||
| 95 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
retrieve: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 96 | 0 | my ($heap, $key) = @_[HEAP, ARG0]; | |||||||||||||||||
| 97 | |||||||||||||||||||
| 98 | 0 | return $heap->{'CACHE_TABLE'}->{$key}; | |||||||||||||||||
| 99 | } | ||||||||||||||||||
| 100 | |||||||||||||||||||
| 101 | sub status() | ||||||||||||||||||
| 102 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||
| 103 | 0 | my ($heap, $key) = @_[HEAP, ARG0]; | |||||||||||||||||
| 104 | |||||||||||||||||||
| 105 | 0 | ▶ | if(exists($heap->{'CACHE_TABLE'}->{$key})) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 106 | { | ||||||||||||||||||
| 107 | 0 | return 1; | |||||||||||||||||
| 108 | |||||||||||||||||||
| 109 | } else { | ||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | 0 | return 0; | |||||||||||||||||
| 112 | } | ||||||||||||||||||
| 113 | } | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | sub adjust_life() | ||||||||||||||||||
| 116 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
adjust_life: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 117 | 0 | my ($heap, $life) = @_[HEAP, ARG0]; | |||||||||||||||||
| 118 | |||||||||||||||||||
| 119 | 0 | $heap->{'CONFIG'}->{'life'} = $life; | |||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | 0 | return; | |||||||||||||||||
| 122 | } | ||||||||||||||||||
| 123 | |||||||||||||||||||
| 124 | sub cache_death() | ||||||||||||||||||
| 125 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
cache_death: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 126 | 0 | my ($heap, $key) = @_[HEAP, ARG0]; | |||||||||||||||||
| 127 | |||||||||||||||||||
| 128 | 0 | delete $heap->{'CACHE_TABLE'}->{$key}; | |||||||||||||||||
| 129 | |||||||||||||||||||
| 130 | 0 | return; | |||||||||||||||||
| 131 | } | ||||||||||||||||||
| 132 | |||||||||||||||||||
| 133 | 1 | 1; | |||||||||||||||||