File Coverage

File:local/lib/perl5/Test/Deep/Cache.pm
Coverage:78.0%

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