summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl0/lib/Test/Deep/Cache.pm
blob: e9ffd952740a9861d6cbbff3a1e96610a106b8b9 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use strict;
use warnings;

package Test::Deep::Cache;

use Test::Deep::Cache::Simple;

sub new
{
	my $pkg = shift;

	my $self = bless {}, $pkg;

	$self->{expects} = [Test::Deep::Cache::Simple->new];
	$self->{normal} = [Test::Deep::Cache::Simple->new];

	$self->local;

	return $self;
}

sub add
{
	my $self = shift;

	my $type = $self->type;

	$self->{$type}->[-1]->add(@_);
}

sub cmp
{
	# go through all the caches to see if we know this one

	my $self = shift;

	my $type = $self->type;

	foreach my $cache (@{$self->{$type}})
	{
		return 1 if $cache->cmp(@_);
	}

	return 0
}

sub local
{
	my $self = shift;

	foreach my $type (qw( expects normal ))
	{
		push(@{$self->{$type}}, Test::Deep::Cache::Simple->new);
	}
}

sub finish
{
	my $self = shift;

	my $keep = shift;

	foreach my $type (qw( expects normal ))
	{
		my $caches = $self->{$type};

		my $last = pop @$caches;

		$caches->[-1]->absorb($last) if $keep;
	}
}

sub type
{
	return $Test::Deep::Expects ? "expects" : "normal";
}

1;