| Revision 228 (by dpavlin, 2008/06/27 19:09:13) |
unbless blessed variables before dumping them to JSON |
#!/usr/bin/env perl
use warnings;
use strict;
=head1 DESCRIPTION
test cache
=cut
use Jifty::Test tests => 14;
use Data::Dump qw/dump/;
use_ok('A3C::Cache');
$A3C::Cache::debug = 1 if @ARGV;
my $debug = $A3C::Cache::debug;
my $instance = 'cache';
ok( my $strix = A3C::Cache->new({ instance => $instance, dir => 't' }), 'new' );
isa_ok( $strix, 'A3C::Cache' );
# cache
ok( my $path = $strix->cache_path( 'test', 42, 'bar' ), 'cache_path' );
like( $path, qr'var/t/.*test-42-bar', 'correct' );
diag "path: $path";
my $data = 'scalar';
SKIP: {
skip( 'scalars not supported', 2 );
ok( $strix->write_cache( $data, 'test-scalar' ), 'write_cache scalar' );
is_deeply( $strix->read_cache( 'test-scalar' ), $data, 'read_cache scalar' );
}
$data = { foo => 42, bar => 'baz' };
ok( $strix->write_cache( $data, 'test-hash' ), 'write_cache hash' );
is_deeply( $strix->read_cache( 'test-hash' ), $data, 'read_cache hash' );
bless $data, 'foo';
like( ref($data), qr/foo/, 'data blessed' );
diag "blessed = ",dump( $data ) if $debug;
ok( $strix->write_cache( $data, 'test-blessed' ), 'write_cache blessed' );
is_deeply( $strix->read_cache( 'test-blessed' ), $data, 'read_cache blessed' );
$data = [ 1, 2, 42 ];
ok( $strix->write_cache( $data, 'test-array' ), 'write_cache array' );
is_deeply( $strix->read_cache( 'test-array' ), $data, 'read_cache array' );