File Coverage

blib/lib/Test/Deep/Cache.pm
Criterion Covered Total %
statement 35 35 100.0
branch 6 6 100.0
condition n/a
subroutine 9 9 100.0
pod 0 6 0.0
total 50 56 89.2


line stmt bran cond sub pod time code
1 41     41   130444 use strict;
  41         83  
  41         1613  
2 41     41   218 use warnings;
  41         69  
  41         2976  
3              
4             package Test::Deep::Cache 1.205;
5              
6 41     41   21019 use Test::Deep::Cache::Simple;
  41         133  
  41         17100  
7              
8             sub new
9             {
10 460     460 0 422850 my $pkg = shift;
11              
12 460         1257 my $self = bless {}, $pkg;
13              
14 460         1904 $self->{expects} = [Test::Deep::Cache::Simple->new];
15 460         1243 $self->{normal} = [Test::Deep::Cache::Simple->new];
16              
17 460         1488 $self->local;
18              
19 460         1135 return $self;
20             }
21              
22             sub add
23             {
24 1139     1139 0 1910 my $self = shift;
25              
26 1139         2310 my $type = $self->type;
27              
28 1139         3511 $self->{$type}->[-1]->add(@_);
29             }
30              
31             sub cmp
32             {
33             # go through all the caches to see if we know this one
34              
35 1178     1178 0 1895 my $self = shift;
36              
37 1178         2577 my $type = $self->type;
38              
39 1178         1946 foreach my $cache (@{$self->{$type}})
  1178         3275  
40             {
41 2512 100       6428 return 1 if $cache->cmp(@_);
42             }
43              
44 1138         3106 return 0
45             }
46              
47             sub local
48             {
49 908     908 0 1502 my $self = shift;
50              
51 908         1955 foreach my $type (qw( expects normal ))
52             {
53 1816         2755 push(@{$self->{$type}}, Test::Deep::Cache::Simple->new);
  1816         5323  
54             }
55             }
56              
57             sub finish
58             {
59 448     448 0 811 my $self = shift;
60              
61 448         685 my $keep = shift;
62              
63 448         892 foreach my $type (qw( expects normal ))
64             {
65 896         1642 my $caches = $self->{$type};
66              
67 896         1572 my $last = pop @$caches;
68              
69 896 100       3134 $caches->[-1]->absorb($last) if $keep;
70             }
71             }
72              
73             sub type
74             {
75 2317 100   2317 0 5553 return $Test::Deep::Expects ? "expects" : "normal";
76             }
77              
78             1;
79              
80             __END__