blib/lib/Cache/Moustache.pm

filter: Statementstmt 85.7% 54 / 63 Branchbran 64.2% 18 / 28 Conditioncond 34.7% 8 / 23 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 100% 13 / 13 Podpod 100% 9 / 9 totaltotal 69.5% 105 / 151 CC 24 SCAR 22.1
CC
24
Cov
70%
set
21.3
remove
10.7
get
5.0
CRAP 9.1
↑ Summary
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
BranchTrueFalseTotal
if {"Cache", 1, "Cache::Cache", 1, "Cache::FastMmap", 1, "Cache::Moustache", 1, "Cache::Ref", 1, "CHI", 1, "Mojo::Cache", 1}->{$what} 2 0 2
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
BranchTrueFalseTotal
if ref $class and $class->isa(__PACKAGE__) 2 1 3
Condition66%2/3
ref $class and $class->isa(__PACKAGE__)
!ll&&!rl&&r
102
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__)
ABresult
0X0
100
111
33 1 my %self = map { ;"~~~~$_" => $args{$_} } keys %args;
34 1 ▶ $self{'~~~~default_expires_in'} ||= 3600;
Condition50%1/2
$self{"~~~~default_expires_in"} ||= 3600
l!l
01
MC/DC0%0/1
$self{"~~~~default_expires_in"} ||= 3600
$self{"~~~~default_expires_in"}
Truth table50%1/2
A
A= $self{"~~~~default_expires_in"}
Aresult
11
00
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
BranchTrueFalseTotal
if $key =~ /^~~~~/ 0 18 18
75
76 18 ▶ $data = $cache->_clone($data) if ref $data && $cache->{'~~~~clone_references'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $data and $cache->{"~~~~clone_references"} 3 15 18
Condition66%2/3
ref $data and $cache->{"~~~~clone_references"}
!ll&&!rl&&r
1503
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"}
ABresult
0X0
100
111
77
78 18 ▶ $expires_in = $cache->{'~~~~default_expires_in'} if !defined $expires_in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expires_in 14 4 18
79
80 18 ▶ if ($expires_in =~ /^(\d*)\s*([A-Za-z]+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($expires_in =~ /^(\d*)\s*([A-Za-z]+)$/) 0 18 18
81 {
82 0 ($expires_in, my $mult) = ($1, $2);
83 0 ▶ $expires_in = 1 unless defined $expires_in && length $expires_in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expires_in and length $expires_in 0 0 0
Condition0%0/3
defined $expires_in and length $expires_in
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
84 0 ▶ $expires_in *= ($multipliers{$mult} || $multipliers{lc $mult});
Condition0%0/3
$multipliers{$mult} || $multipliers{lc $mult}
l!l&&r!l&&!r
000
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}
ABresult
1X1
011
000
85 }
86
87 18 ▶ my $expires_at = ($expires_in < 0) ? $expires_in : (time + $expires_in);
Branch: 1 branch
BranchTrueFalseTotal
$expires_in < 0 ? : 0 18 18
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
BranchTrueFalseTotal
if $key =~ /^~~~~/ 0 14 14
95 14 ▶ return unless exists $cache->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cache->{$key} 3 11 14
96
97 11 my $expires_at = $cache->{$key}[1];
98 11 ▶ if ($expires_at >= 0 and $expires_at < time)
Branch: 1 branch
BranchTrueFalseTotal
if ($expires_at >= 0 and $expires_at < time) 2 9 11
Condition66%2/3
$expires_at >= 0 and $expires_at < time
!ll&&!rl&&r
092
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (ref $key eq "Regexp") 0 4 4
112 0 ▶ my @keys = grep { $_ =~ $key and not !/^~~~~/ } keys %$cache;
Condition0%0/3
$_ =~ /$key/ && !!/^~~~~/
!ll&&!rl&&r
000
MC/DC0%0/2
$_ =~ /$key/ && !!/^~~~~/
$_ =~ /$key/ !!/^~~~~/
Truth table0%0/3
A && B
A= $_ =~ /$key/B= !!/^~~~~/
ABresult
0X0
100
111
113 0 delete @{$cache}{@keys};
114 0 return scalar(@keys);
115 }
116
117 4 ▶ return 0 if $key =~ /^~~~~/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^~~~~/ 0 4 4
118 4 ▶ return( (delete $cache->{$key}) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
delete $cache->{$key} ? : 4 0 4
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
!ll&&!rl&&r
001
MC/DC0%0/2
$e >= 0 && $e < $now
$e >= 0 $e < $now
Truth table33%1/3
A && B
A= $e >= 0B= $e < $now
ABresult
0X0
100
111
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__
↑ Summary