Cache::Curried
[catagits/Catalyst-Plugin-Cache.git] / t / currying_conf.t
CommitLineData
2e4bde89 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More 'no_plan';
7
8use Scalar::Util qw/refaddr/;
9
10use ok "Catalyst::Plugin::Cache";
11
12{
13 package MockApp;
14 use base qw/Catalyst::Plugin::Cache/;
15
16 my %config = (
17 cache => {
18 profiles => {
19 foo => {
20 bah => "foo",
21 },
22 bar => MemoryCache->new,
23 },
24 },
25 );
26 sub config { \%config };
27
28 package MemoryCache;
29 use Storable qw/freeze thaw/;
30
31 sub new { bless {}, shift }
32 sub get { ${thaw($_[0]{$_[1]}) || return} };
33 sub set { $_[0]{$_[1]} = freeze(\$_[2]) };
34 sub delete { delete $_[0]{$_[1]} };
35}
36
37MockApp->setup;
38my $c = bless {}, "MockApp";
39
40MockApp->register_cache_backend( default => MemoryCache->new );
41
42can_ok( $c, "curry_cache" );
43can_ok( $c, "get_preset_curried" );
44
45isa_ok( $c->cache, "Catalyst::Plugin::Cache::Curried" );
46
47is( refaddr($c->cache), refaddr($c->cache), "default cache is memoized, so it is ==");
48
49isa_ok( $c->cache("foo"), "Catalyst::Plugin::Cache::Curried", "cache('foo')" );
50
51is_deeply( $c->cache("foo")->meta, [ bah => "foo" ], "meta is in place" );
52
53is( refaddr( $c->cache("bar") ), refaddr( $c->cache("bar") ), "since bar is hard coded as an object it's always the same" );
54