1package CHI::t::Subcache; 2$CHI::t::Subcache::VERSION = '0.60'; 3use CHI::Test; 4use CHI::Util qw(can_load); 5use base qw(CHI::Test::Class); 6use strict; 7use warnings; 8 9sub test_option_inheritance : Tests { 10 my $self = shift; 11 12 return 'Data::Serializer not installed' 13 unless can_load('Data::Serializer'); 14 15 my %params = ( 16 expires_variance => 0.2, 17 namespace => 'Blurg', 18 on_get_error => 'warn', 19 on_set_error => 'warn', 20 serializer => 'Data::Dumper', 21 depth => 4, 22 ); 23 my $cache = 24 CHI->new( driver => 'File', %params, l1_cache => { driver => 'File' } ); 25 foreach my $field (qw(expires_variance namespace on_get_error on_set_error)) 26 { 27 is( $cache->$field, $cache->l1_cache->$field, "$field matches" ); 28 } 29 is( $cache->l1_cache->serializer->serializer, 30 'Data::Dumper', 'l1 cache serializer' ); 31 is( $cache->depth, 4, 'cache depth' ); 32 is( $cache->l1_cache->depth, 2, 'l1 cache depth' ); 33} 34 35sub test_bad_subcache_option : Tests { 36 my $self = shift; 37 throws_ok( 38 sub { 39 CHI->new( 40 driver => 'Memory', 41 global => 1, 42 l1_cache => CHI->new( driver => 'Memory', global => 1 ) 43 ); 44 }, 45 qr/Validation failed for|isa check for .*? failed/, 46 'cannot pass cache object as subcache' 47 ); 48} 49 501; 51