Cache::Curried
[catagits/Catalyst-Plugin-Cache.git] / t / currying_conf.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan';
7
8 use Scalar::Util qw/refaddr/;
9
10 use 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
37 MockApp->setup;
38 my $c = bless {}, "MockApp";
39
40 MockApp->register_cache_backend( default => MemoryCache->new );
41
42 can_ok( $c, "curry_cache" );
43 can_ok( $c, "get_preset_curried" );
44
45 isa_ok( $c->cache, "Catalyst::Plugin::Cache::Curried" );
46
47 is( refaddr($c->cache), refaddr($c->cache), "default cache is memoized, so it is ==");
48
49 isa_ok( $c->cache("foo"), "Catalyst::Plugin::Cache::Curried", "cache('foo')" );
50
51 is_deeply( $c->cache("foo")->meta, [ bah => "foo" ], "meta is in place" ); 
52
53 is( refaddr( $c->cache("bar") ), refaddr( $c->cache("bar") ), "since bar is hard coded as an object it's always the same" );
54