Warn if you use old config key or blank config. There is a load of simplification...
[catagits/Catalyst-Plugin-Cache.git] / lib / Catalyst / Plugin / Cache / Curried.pm
CommitLineData
2e4bde89 1#!/usr/bin/perl
2
3package Catalyst::Plugin::Cache::Curried;
4
5use strict;
6use warnings;
7
8use base qw/Class::Accessor::Fast/;
9
10use Scalar::Util ();
11
12__PACKAGE__->mk_accessors(qw/c meta/);
13
14sub 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
27sub backend {
85a748b9 28 my ( $self, @meta ) = @_;
ab49d961 29 $self->c->choose_cache_backend( @{ $self->meta }, @meta )
2e4bde89 30}
31
32sub set {
85a748b9 33 my ( $self, $key, $value, @meta ) = @_;
390db05f 34 @meta = ( expires => $meta[0] ) if @meta == 1;
85a748b9 35 $self->c->cache_set( $key, $value, @{ $self->meta }, @meta );
2e4bde89 36}
37
38sub get {
85a748b9 39 my ( $self, $key, @meta ) = @_;
2e4bde89 40 $self->c->cache_get( $key, @{ $self->meta } );
41}
42
aed484da 43sub remove {
85a748b9 44 my ( $self, $key, @meta ) = @_;
aed484da 45 $self->c->cache_remove( $key, @{ $self->meta } );
2e4bde89 46}
47
48__PACKAGE__;
49
50__END__
51
52=pod
53
54=head1 NAME
55
56Catalyst::Plugin::Cache::Curried - Curried versions of C<cache_set>,
aed484da 57C<cache_get> and C<cache_remove> that look more like a backend.
2e4bde89 58
59=head1 SYNOPSIS
60
85a748b9 61 my $curried = $c->cache( %meta );
62
63 $curried->get( $key, $value ); # no need to specify %meta
2e4bde89 64
65=head1 DESCRIPTION
66
85a748b9 67See L<Catalyst::Plugin::Cache/META DATA> for details.
68
69=head1 METHODS
70
71=over 4
72
73=item new %meta
74
75Create a new curried cache, that captures C<%meta>.
76
77=item backend %additional_meta
78
79This calls C<choose_cache_backend> on the $c object with the captured meta and
80the additional meta.
81
82=item set $key, $value, %additional_meta
83
84=item get $key, %additional_meta
85
86=item remove $key, %additional_meta
87
88Dellegate to the C<c> object's C<cache_set>, C<cache_get> or C<cache_remove>
89with the arguments, then the captured meta from C<meta>, and then the
90additional meta.
91
92=item meta
93
94Returns the array ref that captured %meta from C<new>.
95
96=item c
97
98The captured $c object to delegate to.
99
100=back
101
2e4bde89 102=cut
103
104