Slick/Cache.pm

filter: Statementstmt 65.7% 23 / 35 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 58.8% 30 / 51 CC 2 SCAR 7.4
CC
2
Cov
61%
__ANON__
6.0
__ANON__
2.0
BUILD
2.0
CRAP 2.1
« Slick/Error.pm ↑ Summary Slick/CacheExecutor.pm »
1 package Slick::Cache;
2  
3 1 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::Util qw(reduce);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Types::Standard qw(Str HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Module::Runtime qw(require_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 has type => (
13 is => 'ro',
14 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 0 my $s = shift;
16 0 return grep { $_ eq $s } qw(redis memcached);
17 },
18 1 required => 1
19 );
20  
21 has _executor => (
22 is => 'ro',
23 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
24 0 my $s = shift;
25 0 ▶ return blessed($s)
Condition0%0/3
blessed($s) && blessed($s) =~ /Slick\:\:CacheExecutor.*/ux
!ll&&!rl&&r
000
MC/DC0%0/2
blessed($s) && blessed($s) =~ /Slick\:\:CacheExecutor.*/ux
blessed($s) blessed($s) =~ /Slick\:\:CacheExecutor.*/ux
Truth table0%0/3
A && B
A= blessed($s)B= blessed($s) =~ /Slick\:\:CacheExecutor.*/ux
ABresult
0X0
100
111
26 && ( blessed($s) =~ /Slick\:\:CacheExecutor.*/x );
27 },
28 1 handles => [qw(get set incr decr raw)]
29 );
30  
31 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my $self = shift;
33 0 my $args = shift;
34  
35 0 delete $args->{type};
36  
37 0 my $package = ucfirst( $self->type );
38  
39 0 require_module("Slick::CacheExecutor::$package");
40 $self->{_executor} =
41 0 "Slick::CacheExecutor::$package"->new( [ $args->%* ]->@* );
42  
43 0 return $self;
44 }
45  
46 1 1;
47  
48 =encoding utf8
49  
50 =head1 NAME
51  
52 Slick::Cache
53  
54 =head1 SYNOPSIS
55  
56 A wrapper around a L<Slick::CacheExecutor> that either implements L<Redis> or L<Cache::Memcached>.
57  
58 use 5.036;
59  
60 use Slick;
61  
62 my $s = Slick->new;
63  
64 # See Redis and Cache::Memcached on CPAN for arguments
65  
66 # Create a Redis instance
67 $s->cache(
68 my_redis => type => 'redis', # Slick Arguments
69 server => '127.0.0.1:6379' # Cache::Memcached arguments
70 );
71  
72 # Create a Memcached instance
73 $s->cache(
74 my_memcached => type => 'memcached', # Slick Arguments
75 servers => ['127.0.0.1'] => debug => 1 # Cache::Memcached arguments
76 );
77  
78 $s->cache('my_redis')->set( something => 'awesome' );
79  
80 $s->get(
81 '/foo' => sub {
82 my ( $app, $context ) = @_;
83 my $value = $app->cache('my_redis')->get('something'); # Use your cache
84 return $context->text($value);
85 }
86 );
87  
88 $s->run;
89  
90 =head1 API
91  
92 =head2 raw
93  
94 Returns the underlying L<Redis> or L<Cache::Memcached> objects.
95  
96 =head2 set
97  
98 $s->cache('my_cache')->set(something => 'awesome');
99  
100 Sets a value in the cache. Note, this is a facade for L<Redis>->set or L<Cache::Memcached>->set.
101  
102 =head2 get
103  
104 $s->cache('my_cache')->get('something');
105  
106 Gets a value from the cache, returns C<undef> if it that key does not exist.
107 Note, this is a facade for L<Redis>->get or L<Cache::Memcached>->get.
108  
109 =head2 incr
110  
111 $s->cache('my_cache')->incr('value');
112  
113 Attempts to increment a value in the cache.
114  
115 =head2 decr
116  
117 $s->cache('my_cache')->decr('value');
118  
119 Attempts to decrement a value in the cache.
120  
121 =head1 See also
122  
123 =over2
124  
125 =item * L<Slick::CacheExecutor>
126  
127 =item * L<Slick::CacheExecutor::Redis>
128  
129 =item * L<Slick::CacheExecutor::Memcached>
130  
131 =item * L<Slick::Context>
132  
133 =item * L<Slick::Database>
134  
135 =item * L<Slick::DatabaseExecutor>
136  
137 =item * L<Slick::DatabaseExecutor::MySQL>
138  
139 =item * L<Slick::DatabaseExecutor::Pg>
140  
141 =item * L<Slick::EventHandler>
142  
143 =item * L<Slick::Events>
144  
145 =item * L<Slick::Methods>
146  
147 =item * L<Slick::RouteMap>
148  
149 =item * L<Slick::Util>
150  
151 =back
152  
153 =cut
« Slick/Error.pm ↑ Summary Slick/CacheExecutor.pm »