| 1 | package Cache::Moustache; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | my $cpants = q/ | |||||||||||||||||||||||||||
| 5 | use strict; | ||||||||||||||||||||||||||||
| 6 | use warnings; | ||||||||||||||||||||||||||||
| 7 | /; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | BEGIN { | ||||||||||||||||||||||||||||
| 10 | 2 | ▶ | $Cache::Moustache::AUTHORITY = 'cpan:TOBYINK'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | $Cache::Moustache::VERSION = '0.005'; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub isa | ||||||||||||||||||||||||||||
| 15 | { | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | my $what = $_[1]; | ||||||||||||||||||||||||||
|
Subroutine
isa: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | return !!1 if { | ||||||||||||||||||||||||||||
| 18 | 'Cache' => 1, | ||||||||||||||||||||||||||||
| 19 | 'Cache::Cache' => 1, | ||||||||||||||||||||||||||||
| 20 | 'Cache::FastMmap' => 1, | ||||||||||||||||||||||||||||
| 21 | 'Cache::Moustache' => 1, | ||||||||||||||||||||||||||||
| 22 | 'Cache::Ref' => 1, | ||||||||||||||||||||||||||||
| 23 | 'CHI' => 1, | ||||||||||||||||||||||||||||
| 24 | 'Mojo::Cache' => 1, | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | }->{$what}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | return !!0; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub new | ||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||
| 31 | 3 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 3 | ▶ | return $class if ref $class && $class->isa(__PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $class and $class->isa(__PACKAGE__)
MC/DC50%1/2
ref $class and $class->isa(__PACKAGE__)
ref $class
$class->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= ref $classB= $class->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||
| 33 | 1 | my %self = map { ;"~~~~$_" => $args{$_} } keys %args; | |||||||||||||||||||||||||||
| 34 | 1 | ▶ | $self{'~~~~default_expires_in'} ||= 3600; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self{"~~~~default_expires_in"} ||= 3600
MC/DC0%0/1
$self{"~~~~default_expires_in"} ||= 3600
$self{"~~~~default_expires_in"}
Truth table50%1/2
A
A= $self{"~~~~default_expires_in"}
| |||||||||||||||||||||||||||||
| 35 | 1 | bless {%self}, $class; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | my %multipliers = ( | |||||||||||||||||||||||||||
| 39 | s => 1, | ||||||||||||||||||||||||||||
| 40 | second => 1, | ||||||||||||||||||||||||||||
| 41 | seconds => 1, | ||||||||||||||||||||||||||||
| 42 | sec => 1, | ||||||||||||||||||||||||||||
| 43 | m => 60, | ||||||||||||||||||||||||||||
| 44 | minute => 60, | ||||||||||||||||||||||||||||
| 45 | minutes => 60, | ||||||||||||||||||||||||||||
| 46 | min => 60, | ||||||||||||||||||||||||||||
| 47 | h => 3600, | ||||||||||||||||||||||||||||
| 48 | hour => 3600, | ||||||||||||||||||||||||||||
| 49 | hours => 3600, | ||||||||||||||||||||||||||||
| 50 | d => 86400, | ||||||||||||||||||||||||||||
| 51 | day => 86400, | ||||||||||||||||||||||||||||
| 52 | days => 86400, | ||||||||||||||||||||||||||||
| 53 | w => 604800, | ||||||||||||||||||||||||||||
| 54 | week => 604800, | ||||||||||||||||||||||||||||
| 55 | weeks => 604800, | ||||||||||||||||||||||||||||
| 56 | M => 2419200, | ||||||||||||||||||||||||||||
| 57 | month => 2419200, | ||||||||||||||||||||||||||||
| 58 | months => 2419200, | ||||||||||||||||||||||||||||
| 59 | y => 31536000, | ||||||||||||||||||||||||||||
| 60 | year => 31536000, | ||||||||||||||||||||||||||||
| 61 | years => 31536000, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub _clone | ||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 3 | ▶ | require Storable; | ||||||||||||||||||||||||||
|
Subroutine
_clone: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 3 | shift; | |||||||||||||||||||||||||||
| 68 | 3 | goto \&Storable::dclone; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub set | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 18 | ▶ | my ($cache, $key, $data, $expires_in) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=10 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 18 | ▶ | return if $key =~ /^~~~~/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 18 | ▶ | $data = $cache->_clone($data) if ref $data && $cache->{'~~~~clone_references'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $data and $cache->{"~~~~clone_references"}
MC/DC50%1/2
ref $data and $cache->{"~~~~clone_references"}
ref $data
$cache->{"~~~~clone_references"}
Truth table66%2/3
A and B
A= ref $dataB= $cache->{"~~~~clone_references"}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 18 | ▶ | $expires_in = $cache->{'~~~~default_expires_in'} if !defined $expires_in; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 18 | ▶ | if ($expires_in =~ /^(\d*)\s*([A-Za-z]+)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | ($expires_in, my $mult) = ($1, $2); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $expires_in = 1 unless defined $expires_in && length $expires_in; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $expires_in and length $expires_in
MC/DC0%0/2
defined $expires_in and length $expires_in
defined $expires_in
length $expires_in
Truth table0%0/3
A and B
A= defined $expires_inB= length $expires_in
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $expires_in *= ($multipliers{$mult} || $multipliers{lc $mult}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$multipliers{$mult} || $multipliers{lc $mult}
MC/DC0%0/2
$multipliers{$mult} || $multipliers{lc $mult}
$multipliers{$mult}
$multipliers{lc $mult}
Truth table0%0/3
A || B
A= $multipliers{$mult}B= $multipliers{lc $mult}
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 18 | ▶ | my $expires_at = ($expires_in < 0) ? $expires_in : (time + $expires_in); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 18 | $cache->{$key} = [$data, $expires_at]; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub get | ||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 14 | ▶ | my ($cache, $key) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 14 | ▶ | return if $key =~ /^~~~~/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 14 | ▶ | return unless exists $cache->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 11 | my $expires_at = $cache->{$key}[1]; | |||||||||||||||||||||||||||
| 98 | 11 | ▶ | if ($expires_at >= 0 and $expires_at < time) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$expires_at >= 0 and $expires_at < time
MC/DC50%1/2
$expires_at >= 0 and $expires_at < time
$expires_at >= 0
$expires_at < time
Truth table66%2/3
A and B
A= $expires_at >= 0B= $expires_at < time
| |||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 2 | $cache->remove($key); | |||||||||||||||||||||||||||
| 101 | 2 | return; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 9 | $cache->{$key}[0]; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub remove | ||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 4 | ▶ | my ($cache, $key) = @_; | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 4 | ▶ | return if $key =~ /^~~~~/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 4 | ▶ | return( (delete $cache->{$key}) ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub clear | ||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | 2 | ▶ | my $cache = shift; | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 2 | my @keys = grep { !/^~~~~/ } keys %$cache; | |||||||||||||||||||||||||||
| 118 | 2 | delete $cache->{$_} for @keys; | |||||||||||||||||||||||||||
| 119 | 2 | return scalar(@keys); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub purge | ||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 1 | ▶ | my $cache = shift; | ||||||||||||||||||||||||||
|
Subroutine
purge: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 1 | my $now = time; | |||||||||||||||||||||||||||
| 126 | my @keys = | ||||||||||||||||||||||||||||
| 127 | 1 | ▶ | grep { my $e = $cache->{$_}[1]; $e >= 0 && $e < $now } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 1 | grep { !/^~~~~/ } keys %$cache; | |||||||||||||||||||||||||||
| 129 | 1 | delete $cache->{$_} for @keys; | |||||||||||||||||||||||||||
| 130 | 1 | return scalar(@keys); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub get_keys | ||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | 7 | ▶ | my $cache = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 7 | my @keys = grep { !/^~~~~/ } keys %$cache; | |||||||||||||||||||||||||||
| 137 | 7 | return @keys; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub size | ||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | 6 | ▶ | scalar( my @keys = shift->get_keys ); | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | 8 | ▶ | return; | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 2 | __PACKAGE__ | |||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||