| 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 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | $Cache::Moustache::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 11 | 2 | $Cache::Moustache::VERSION = '0.006'; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub isa | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isa: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 2 | my $what = $_[1]; | |||||||||||||||||||||||||||
| 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 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 3 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 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 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_clone: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 3 | require Storable; | |||||||||||||||||||||||||||
| 67 | 3 | shift; | |||||||||||||||||||||||||||
| 68 | 3 | goto \&Storable::dclone; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub set | ||||||||||||||||||||||||||||
| 72 | 18 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=10 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 18 | my ($cache, $key, $data, $expires_in) = @_; | |||||||||||||||||||||||||||
| 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 | 14 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 14 | my ($cache, $key) = @_; | |||||||||||||||||||||||||||
| 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 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=5 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 4 | my ($cache, $key) = @_; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 4 | ▶ | if (ref $key eq 'Regexp') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my @keys = grep { $_ =~ $key and not !/^~~~~/ } keys %$cache; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_ =~ /$key/ && !!/^~~~~/
MC/DC0%0/2
$_ =~ /$key/ && !!/^~~~~/
$_ =~ /$key/
!!/^~~~~/
Truth table0%0/3
A && B
A= $_ =~ /$key/B= !!/^~~~~/
| |||||||||||||||||||||||||||||
| 113 | 0 | delete @{$cache}{@keys}; | |||||||||||||||||||||||||||
| 114 | 0 | return scalar(@keys); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 4 | ▶ | return 0 if $key =~ /^~~~~/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 4 | ▶ | return( (delete $cache->{$key}) ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub clear | ||||||||||||||||||||||||||||
| 122 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 2 | my $cache = shift; | |||||||||||||||||||||||||||
| 124 | 2 | my @keys = grep !/^~~~~/, keys %$cache; | |||||||||||||||||||||||||||
| 125 | 2 | delete $cache->{$_} for @keys; | |||||||||||||||||||||||||||
| 126 | 2 | return scalar(@keys); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub purge | ||||||||||||||||||||||||||||
| 130 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
purge: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 1 | my $cache = shift; | |||||||||||||||||||||||||||
| 132 | 1 | my $now = time; | |||||||||||||||||||||||||||
| 133 | my @keys = | ||||||||||||||||||||||||||||
| 134 | 1 | ▶ | grep { my $e = $cache->{$_}[1]; $e >= 0 && $e < $now } | ||||||||||||||||||||||||||
|
Condition33%1/3
$e >= 0 && $e < $now
MC/DC0%0/2
$e >= 0 && $e < $now
$e >= 0
$e < $now
Truth table33%1/3
A && B
A= $e >= 0B= $e < $now
| |||||||||||||||||||||||||||||
| 135 | grep !/^~~~~/, keys %$cache; | ||||||||||||||||||||||||||||
| 136 | 1 | delete @{$cache}{@keys}; | |||||||||||||||||||||||||||
| 137 | 1 | return scalar(@keys); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub get_keys | ||||||||||||||||||||||||||||
| 141 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 7 | my $cache = shift; | |||||||||||||||||||||||||||
| 143 | 7 | my @keys = grep !/^~~~~/, keys %$cache; | |||||||||||||||||||||||||||
| 144 | 7 | return @keys; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub size | ||||||||||||||||||||||||||||
| 148 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 6 | scalar( my @keys = shift->get_keys ); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 153 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 154 | 8 | return; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 2 | __PACKAGE__ | |||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||