File Coverage

blib/lib/KiokuDB/Stream/Objects.pm
Criterion Covered Total %
statement 18 18 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 5 5 100.0
pod 0 1 0.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::Stream::Objects;
4 12     12   61 use Moose;
  12         18  
  12         83  
5              
6 12     12   60083 use namespace::clean -except => 'meta';
  12         26  
  12         106  
7              
8             has directory => (
9             isa => "KiokuDB",
10             is => "ro",
11             required => 1,
12             );
13              
14             has entry_stream => (
15             does => "Data::Stream::Bulk",
16             is => "ro",
17             required => 1,
18             handles => [qw(is_done loaded)],
19             );
20              
21             has linker => (
22             isa => "KiokuDB::Linker",
23             is => "ro",
24             lazy_build => 1,
25             );
26              
27             sub _build_linker {
28 436     436   576 my $self = shift;
29              
30 436         11765 $self->directory->linker;
31             }
32              
33             has live_objects => (
34             isa => "KiokuDB::LiveObjects",
35             is => "ro",
36             lazy_build => 1,
37             );
38              
39             sub _build_live_objects {
40 436     436   900 my $self = shift;
41              
42 436         11966 $self->directory->live_objects;
43             }
44              
45             has _scope => (
46             isa => "KiokuDB::LiveObjects::Scope",
47             writer => "_scope",
48             clearer => "_clear_scope",
49             );
50              
51             has _no_scope => (
52             isa => "Bool",
53             is => "rw",
54             );
55              
56             with qw(Data::Stream::Bulk) => { excludes => 'loaded' };
57              
58             sub next {
59 1050     1050 0 35341 my $self = shift;
60              
61 1050         34123 $self->_clear_scope;
62              
63 1050   100     28588 my $entries = $self->entry_stream->next || return;;
64              
65 482 100       32323 if ( @$entries ) {
66 481 100       12939 $self->_scope( $self->directory->new_scope )
67             unless $self->_no_scope;
68              
69 481         14156 $self->live_objects->register_entry( $_->id => $_, in_storage => 1 ) for @$entries;
70              
71 481         13313 return [ $self->linker->register_and_expand_entries(@$entries) ];
72             } else {
73 1         3 return [];
74             }
75             }
76              
77             before all => sub { shift->_no_scope(1) };
78              
79             __PACKAGE__->meta->make_immutable;
80              
81             __PACKAGE__
82              
83             __END__
84              
85             =pod
86              
87             =head1 NAME
88              
89             KiokuDB::Stream::Objects - L<Data::Stream::Bulk> with live object management.
90              
91             =head1 DESCRIPTION
92              
93             This class is for object streams coming out of L<KiokuDB>.
94              
95             C<new_scope> is called once for each block, and then cleared.
96              
97             =cut
98              
99