General fixes, docs, love (C::P::Cache)
[catagits/Catalyst-Plugin-Cache.git] / lib / Catalyst / Plugin / Cache / Curried.pm
1 #!/usr/bin/perl
2
3 package Catalyst::Plugin::Cache::Curried;
4
5 use strict;
6 use warnings;
7
8 use base qw/Class::Accessor::Fast/;
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
24     return $self;
25 }
26
27 sub backend {
28     my ( $self, $key ) = @_;
29     $self->c->choose_cache_backend( @{ $self->meta }, key => $key )
30 }
31
32 sub set {
33     my ( $self, $key, $value ) = @_;
34     $self->c->cache_set( $key, $value, @{ $self->meta } );
35 }
36
37 sub get {
38     my ( $self, $key ) = @_;
39     $self->c->cache_get( $key, @{ $self->meta } );
40 }
41
42 sub remove {
43     my ( $self, $key ) = @_;
44     $self->c->cache_remove( $key, @{ $self->meta } );
45 }
46
47 __PACKAGE__;
48
49 __END__
50
51 =pod
52
53 =head1 NAME
54
55 Catalyst::Plugin::Cache::Curried - Curried versions of C<cache_set>,
56 C<cache_get> and C<cache_remove> that look more like a backend.
57
58 =head1 SYNOPSIS
59
60
61 =head1 DESCRIPTION
62
63 =cut
64
65