File Coverage

blib/lib/KiokuDB/GC/Naive.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1             package KiokuDB::GC::Naive;
2             BEGIN {
3 1     1   22104 $KiokuDB::GC::Naive::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::GC::Naive::VERSION = '0.57';
6 1     1   1570 use Moose;
  0            
  0            
7             # ABSTRACT: Naive mark and sweep garbage collection
8              
9             use KiokuDB::GC::Naive::Mark;
10             use KiokuDB::GC::Naive::Sweep;
11              
12             use namespace::clean -except => 'meta';
13              
14             with qw(KiokuDB::Role::Verbosity);
15              
16             has backend => (
17             does => "KiokuDB::Backend::Role::Scan",
18             is => "ro",
19             required => 1,
20             );
21              
22             has [qw(mark_scan sweep_scan)] => (
23             is => "ro",
24             lazy_build => 1,
25             );
26              
27             sub _build_mark_scan {
28             my $self = shift;
29              
30             KiokuDB::GC::Naive::Mark->new(
31             backend => $self->backend,
32             verbose => $self->verbose,
33             );
34             }
35              
36             sub _build_sweep_scan {
37             my $self = shift;
38              
39             my $mark_results = $self->mark_results;
40              
41             $self->v("sweeping...\n");
42              
43             KiokuDB::GC::Naive::Sweep->new(
44             backend => $self->backend,
45             verbose => $self->verbose,
46             mark_results => $mark_results,
47             );
48             }
49              
50             has mark_results => (
51             isa => "KiokuDB::GC::Naive::Mark::Results",
52             is => "ro",
53             handles => qr/.*/,
54             lazy_build => 1,
55             );
56              
57             sub _build_mark_results {
58             my $self = shift;
59              
60             $self->v("marking reachable objects...\n");
61              
62             return $self->mark_scan->results;
63             }
64              
65             has sweep_results => (
66             isa => "KiokuDB::GC::Naive::Sweep::Results",
67             is => "ro",
68             handles => qr/.*/,
69             lazy_build => 1,
70             );
71              
72             sub _build_sweep_results {
73             my $self = shift;
74              
75             return $self->sweep_scan->results;
76             }
77              
78             __PACKAGE__->meta->make_immutable;
79              
80             __PACKAGE__
81              
82             __END__
83              
84             =pod
85              
86             =encoding UTF-8
87              
88             =head1 NAME
89              
90             KiokuDB::GC::Naive - Naive mark and sweep garbage collection
91              
92             =head1 VERSION
93              
94             version 0.57
95              
96             =head1 SYNOPSIS
97              
98             use KiokuDB::GC::Naive;
99              
100             my $gc = KiokuDB::GC::Naive->new(
101             backend => $backend,
102             );
103              
104             $backend->delete( $gc->garbage->members );
105              
106             =head1 DESCRIPTION
107              
108             This class implements full mark and sweep garbage collection for a backend
109             supporting L<KiokuDB::Backend::Role::Scan>.
110              
111             =head1 AUTHOR
112              
113             Yuval Kogman <nothingmuch@woobling.org>
114              
115             =head1 COPYRIGHT AND LICENSE
116              
117             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
118              
119             This is free software; you can redistribute it and/or modify it under
120             the same terms as the Perl 5 programming language system itself.
121              
122             =cut