Documentation for C::P::Cache
[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 ) = @_;
29 $self->c->choose_cache_backend( @{ $self->meta }, key => $key, @meta )
2e4bde89 30}
31
32sub set {
85a748b9 33 my ( $self, $key, $value, @meta ) = @_;
34 $self->c->cache_set( $key, $value, @{ $self->meta }, @meta );
2e4bde89 35}
36
37sub get {
85a748b9 38 my ( $self, $key, @meta ) = @_;
2e4bde89 39 $self->c->cache_get( $key, @{ $self->meta } );
40}
41
aed484da 42sub remove {
85a748b9 43 my ( $self, $key, @meta ) = @_;
aed484da 44 $self->c->cache_remove( $key, @{ $self->meta } );
2e4bde89 45}
46
47__PACKAGE__;
48
49__END__
50
51=pod
52
53=head1 NAME
54
55Catalyst::Plugin::Cache::Curried - Curried versions of C<cache_set>,
aed484da 56C<cache_get> and C<cache_remove> that look more like a backend.
2e4bde89 57
58=head1 SYNOPSIS
59
85a748b9 60 my $curried = $c->cache( %meta );
61
62 $curried->get( $key, $value ); # no need to specify %meta
2e4bde89 63
64=head1 DESCRIPTION
65
85a748b9 66See L<Catalyst::Plugin::Cache/META DATA> for details.
67
68=head1 METHODS
69
70=over 4
71
72=item new %meta
73
74Create a new curried cache, that captures C<%meta>.
75
76=item backend %additional_meta
77
78This calls C<choose_cache_backend> on the $c object with the captured meta and
79the additional meta.
80
81=item set $key, $value, %additional_meta
82
83=item get $key, %additional_meta
84
85=item remove $key, %additional_meta
86
87Dellegate to the C<c> object's C<cache_set>, C<cache_get> or C<cache_remove>
88with the arguments, then the captured meta from C<meta>, and then the
89additional meta.
90
91=item meta
92
93Returns the array ref that captured %meta from C<new>.
94
95=item c
96
97The captured $c object to delegate to.
98
99=back
100
2e4bde89 101=cut
102
103