File Coverage

blib/lib/KiokuDB/LinkChecker.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::LinkChecker;
2             BEGIN {
3 2     2   46669 $KiokuDB::LinkChecker::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::LinkChecker::VERSION = '0.57';
6 2     2   9639 use Moose;
  0            
  0            
7             # ABSTRACT: Reference consistency checker
8              
9             use KiokuDB::LinkChecker::Results;
10              
11             use namespace::clean -except => 'meta';
12              
13             with 'KiokuDB::Role::Scan' => { result_class => "KiokuDB::LinkChecker::Results" };
14              
15             sub process_block {
16             my ( $self, %args ) = @_;
17              
18             my ( $block, $res ) = @args{qw(block results)};
19              
20             my ( $seen, $root, $referenced, $unreferenced, $missing, $broken ) = map { $res->$_ } qw(seen root referenced unreferenced missing broken);
21              
22             my $backend = $self->backend;
23              
24             foreach my $entry ( @$block ) {
25             my $id = $entry->id;
26              
27             $seen->insert($id);
28             $root->insert($id) if $entry->root;
29              
30             unless ( $referenced->includes($id) ) {
31             $unreferenced->insert($id);
32             }
33              
34             my @ids = $entry->referenced_ids;
35              
36             my @new = grep { !$referenced->includes($_) && !$seen->includes($_) } @ids;
37              
38             my %exists;
39             @exists{@new} = $backend->exists(@new) if @new;
40              
41             if ( my @missing = grep { not $exists{$_} } @new ) {
42             $self->v("\rfound broken entry: " . $entry->id . " (references nonexisting IDs @missing)\n");
43             $missing->insert(@missing);
44             $broken->insert($entry->id);
45             }
46              
47             $referenced->insert(@ids);
48             $unreferenced->remove(@ids);
49             }
50             }
51              
52             __PACKAGE__->meta->make_immutable;
53              
54             __PACKAGE__
55              
56             __END__
57              
58             =pod
59              
60             =encoding UTF-8
61              
62             =head1 NAME
63              
64             KiokuDB::LinkChecker - Reference consistency checker
65              
66             =head1 VERSION
67              
68             version 0.57
69              
70             =head1 SYNOPSIS
71              
72             use KiokuDB::LinkChecker;
73              
74             my $l = KiokuDB::LinkChecker->new(
75             backend => $b,
76             );
77              
78             my @idw = $l->missing->members; # referenced but not in the DB
79              
80             =head1 DESCRIPTION
81              
82             This is the low level link checker used by L<KiokuDB::Cmd::Command::FSCK>.
83              
84             =head1 AUTHOR
85              
86             Yuval Kogman <nothingmuch@woobling.org>
87              
88             =head1 COPYRIGHT AND LICENSE
89              
90             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
91              
92             This is free software; you can redistribute it and/or modify it under
93             the same terms as the Perl 5 programming language system itself.
94              
95             =cut