Cache/Curried.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Cache.pm ↑ Summary
1 #!/usr/bin/perl
2  
3 package Catalyst::Plugin::Cache::Curried;
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use Scalar::Util ();
11  
12 __PACKAGE__->mk_accessors(qw/c meta/);
13  
14 sub new {
15 my ( $class, $c, @meta ) = @_;
16  
17 my $self = $class->SUPER::new({
18 c => $c,
19 meta => \@meta,
20 });
21  
22 Scalar::Util::weaken( $self->{c} )
23 if ref( $self->{c} );
24  
25 return $self;
26 }
27  
28 sub backend {
29 my ( $self, @meta ) = @_;
30 $self->c->choose_cache_backend( @{ $self->meta }, @meta )
31 }
32  
33 sub set {
34 my ( $self, $key, $value, @meta ) = @_;
35 @meta = ( expires => $meta[0] ) if @meta == 1;
36 $self->c->cache_set( $key, $value, @{ $self->meta }, @meta );
37 }
38  
39 sub get {
40 my ( $self, $key ) = @_;
41 $self->c->cache_get( $key, @{ $self->meta } );
42 }
43  
44 sub remove {
45 my ( $self, $key ) = @_;
46 $self->c->cache_remove( $key, @{ $self->meta } );
47 }
48  
49 sub compute {
50 my ($self, $key, $code, @meta) = @_;
51 @meta = ( expires => $meta[0] ) if @meta == 1;
52 $self->c->cache_compute( $key, $code, @{ $self->meta }, @meta );
53 }
54  
55 __PACKAGE__;
56  
57 __END__
« Cache.pm ↑ Summary