6 use Test::More 'no_plan';
9 use ok "Catalyst::Plugin::Cache";
11 use Catalyst::Plugin::Cache::Backend::Memory;
15 use base qw/Catalyst::Plugin::Cache/;
17 sub registered_plugins {}
19 ### must register a backend class as of 0.06
20 ### the previous code simply ignored a croak
21 ### this is still in line with the documentation.
25 class => 'Catalyst::Plugin::Cache::Backend::Memory',
29 sub config { \%config };
33 my $c = bless {}, "MockApp";
35 can_ok( $c, "register_cache_backend" );
36 can_ok( $c, "unregister_cache_backend" );
38 MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
39 MockApp->register_cache_backend( moose => Catalyst::Plugin::Cache::Backend::Memory->new );
41 can_ok( $c, "cache" );
43 ok( $c->cache, "->cache returns a value" );
45 can_ok( $c->cache, "get" ); #, "rv from cache" );
46 can_ok( $c->cache("default"), "get" ); #, "default backend" );
47 can_ok( $c->cache("moose"), "get" ); #, "moose backend" );
49 ok( !$c->cache("lalalala"), "no lalala backend");
51 MockApp->unregister_cache_backend( "moose" );
53 ok( !$c->cache("moose"), "moose backend unregistered");
57 MockApp->register_cache_backend( ding => undef );
58 } "can't register invalid backend";
61 MockApp->register_cache_backend( ding => bless {}, "SomeClass" );
62 } "can't register invalid backend";
66 can_ok( $c, "default_cache_backend" );
68 can_ok( $c, "choose_cache_backend_wrapper" );
69 can_ok( $c, "choose_cache_backend" );
71 can_ok( $c, "cache_set" );
72 can_ok( $c, "cache_get" );
73 can_ok( $c, "cache_remove" );
75 $c->cache_set( foo => "bar" );
76 is( $c->cache_get("foo"), "bar", "set" );
78 $c->cache_remove( "foo" );
79 is( $c->cache_get("foo"), undef, "remove" );
81 MockApp->register_cache_backend( elk => Catalyst::Plugin::Cache::Backend::Memory->new );
83 is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->default_cache_backend, "choose default" );
84 is( $c->choose_cache_backend_wrapper( key => "foo", backend => "elk" ), $c->get_cache_backend("elk"), "override choice" );
87 $c->cache_set( foo => "gorch", backend => "elk" );
88 is( $c->cache_get("foo"), undef, "set to custom backend (get from non custom)" );
89 is( $c->cache_get("foo", backend => "elk"), "gorch", "set to custom backend (get from custom)" );
91 my $cache_elk = $c->cache( backend => "elk" );
92 my $cache_norm = $c->cache();
94 is( $cache_norm->get("foo"), undef, "default curried cache has no foo");
95 is( $cache_elk->get("foo"), "gorch", "curried custom backend has foo" );