File Coverage

blib/lib/KiokuDB/Backend/Role/TXN/Memory/Scan.pm
Criterion Covered Total %
statement 39 40 97.5
branch 7 8 87.5
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 53 57 92.9


line stmt bran cond sub pod time code
1             package KiokuDB::Backend::Role::TXN::Memory::Scan;
2 21     21   10079 use Moose::Role;
  21         42  
  21         131  
3              
4 21     21   84638 use Data::Stream::Bulk::Util qw(bulk);
  21         60  
  21         233  
5              
6 21     21   3798 use namespace::clean -except => 'meta';
  21         38  
  21         208  
7              
8             with qw(
9             KiokuDB::Backend::Role::TXN::Memory
10             KiokuDB::Backend::Role::Clear
11             KiokuDB::Backend::Role::Scan
12             );
13              
14             requires qw(
15             all_storage_entries
16             clear_storage
17             );
18              
19             sub clear {
20 232     232 0 1683 my $self = shift;
21              
22 232 50       410 if ( @{ $self->_txn_stack } ) {
  232         6685  
23 232         434 %{ $self->_txn_stack->[-1] } = ( %{ $self->_new_frame }, cleared => 1 );
  232         6731  
  232         978  
24             } else {
25 0         0 $self->clear_storage;
26             }
27             }
28              
29             sub all_entries {
30 1019     1019 0 1597 my $self = shift;
31              
32 1019         29233 my $stack = $self->_txn_stack;
33              
34 1019 100       3146 if ( @$stack ) {
35 925         1552 my $frame = $stack->[-1];
36              
37 925         3724 my $flat = $self->_collapsed_txn_stack;
38              
39 925         1271 my $live = bulk(grep { not $_->deleted } values %{ $flat->{live} });
  1782         40214  
  925         4128  
40              
41 925 100       51726 if ( $flat->{cleared} ) {
42             # return all the inserted entries since the clear
43 132         592 return $live;
44             } else {
45 793         3361 my $all = $self->all_storage_entries;
46              
47             # create a filter for all the IDs that have been either deleted or superseded in the transaction frame
48 793         43494 my %mask; @mask{ keys %{ $flat->{live} } } = ();
  793         1394  
  793         3173  
49              
50 793 100   462   4910 my $shadowed = keys %mask ? $all->filter(sub {[ grep { not exists $mask{$_->id} } @$_ ]}) : $all;
  462         34554  
  1848         39060  
51              
52             # make note of all read entries in the transaction frame
53             my $noted_shadowed = $shadowed->filter(sub {
54 760     760   53651 @{ $frame->{live} }{ map { $_->id } @$_ } = @$_;
  760         2710  
  1423         29929  
55 760         21753 return $_;
56 793         6180 });
57              
58 793         5602 return $live->cat($noted_shadowed);
59             }
60             } else {
61 94         426 return $self->all_storage_entries;
62             }
63             }
64              
65              
66             # ex: set sw=4 et:
67              
68             __PACKAGE__
69              
70             __END__