File: memory_tie.t

package info (click to toggle)
libcache-perl 2.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 428 kB
  • sloc: perl: 2,577; makefile: 2
file content (44 lines) | stat: -r--r--r-- 755 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use strict;
use warnings;
use Test::More;
use Carp;

$SIG{__DIE__} = sub { confess @_ };

BEGIN { plan tests => 7 }

use_ok('Cache::Memory');

{
	my %hash;
	my $cache = tie %hash, 'Cache::Memory';

	my $key = 'testkey';

	$hash{$key} = 'test data';

	ok($cache->exists($key), 'store worked');
	is($hash{$key}, 'test data', 'fetch worked');

	delete $hash{$key};

	ok(!$cache->exists($key), 'delete worked');
}

{
	sub load_func {
		return "You requested ".$_[0]->key();
	}

	my %hash;
	my $cache = tie %hash, 'Cache::Memory', {load_callback => \&load_func};

	my $key = 'testkey';

	ok(!$cache->exists($key), 'key doesnt exist');
	is($hash{$key}, "You requested $key", 'load worked');

	delete $hash{$key};

	ok(!$cache->exists($key), 'delete worked');
}