root/branches/release-40/t/lib/Test/Deep/Cache.pm @ 2583

Revision 2583, 1.0 kB (checked in by mpaschal, 18 months ago)

Add Test::Deep to t/lib, since we already use it in driver-tests.pl
BugzID: 79953

Line 
1use strict;
2use warnings;
3
4package Test::Deep::Cache;
5
6use Test::Deep::Cache::Simple;
7
8sub new
9{
10        my $pkg = shift;
11
12        my $self = bless {}, $pkg;
13
14        $self->{expects} = [Test::Deep::Cache::Simple->new];
15        $self->{normal} = [Test::Deep::Cache::Simple->new];
16
17        $self->local;
18
19        return $self;
20}
21
22sub add
23{
24        my $self = shift;
25
26        my $type = $self->type;
27
28        $self->{$type}->[-1]->add(@_);
29}
30
31sub cmp
32{
33        # go through all the caches to see if we know this one
34
35        my $self = shift;
36
37        my $type = $self->type;
38
39        foreach my $cache (@{$self->{$type}})
40        {
41                return 1 if $cache->cmp(@_);
42        }
43
44        return 0
45}
46
47sub local
48{
49        my $self = shift;
50
51        foreach my $type (qw( expects normal ))
52        {
53                push(@{$self->{$type}}, Test::Deep::Cache::Simple->new);
54        }
55}
56
57sub finish
58{
59        my $self = shift;
60
61        my $keep = shift;
62
63        foreach my $type (qw( expects normal ))
64        {
65                my $caches = $self->{$type};
66
67                my $last = pop @$caches;
68
69                $caches->[-1]->absorb($last) if $keep;
70        }
71}
72
73sub type
74{
75        return $Test::Deep::Expects ? "expects" : "normal";
76}
77
781;
Note: See TracBrowser for help on using the browser.