| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package KiokuDB::LinkChecker; | ||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use KiokuDB::LinkChecker::Results; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | with 'KiokuDB::Role::Scan' => { result_class => "KiokuDB::LinkChecker::Results" }; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub process_block { | ||||||||||||||||||||
| 13 | 8 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||
|
Subroutine
process_block: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 8 | my ( $block, $res ) = @args{qw(block results)}; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 8 | my ( $seen, $root, $referenced, $unreferenced, $missing, $broken ) = map { $res->$_ } qw(seen root referenced unreferenced missing broken); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 8 | my $backend = $self->backend; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 8 | foreach my $entry ( @$block ) { | |||||||||||||||||||
| 22 | 70 | my $id = $entry->id; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 70 | $seen->insert($id); | |||||||||||||||||||
| 25 | 70 | ▶ | $root->insert($id) if $entry->root; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 70 | ▶ | unless ( $referenced->includes($id) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 19 | $unreferenced->insert($id); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 70 | my @ids = $entry->referenced_ids; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 70 | ▶ | my @new = grep { !$referenced->includes($_) && !$seen->includes($_) } @ids; | ||||||||||||||||||
|
Condition100%3/3
$referenced->includes($_) || $seen->includes($_)
MC/DC100%2/2
$referenced->includes($_) || $seen->includes($_)
$referenced->includes($_)
$seen->includes($_)
Truth table100%3/3
A || B
A= $referenced->includes($_)B= $seen->includes($_)
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 70 | my %exists; | |||||||||||||||||||
| 36 | 70 | ▶ | @exists{@new} = $backend->exists(@new) if @new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 70 | ▶ | if ( my @missing = grep { not $exists{$_} } @new ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 4 | $self->v("\rfound broken entry: " . $entry->id . " (references nonexisting IDs @missing)\n"); | |||||||||||||||||||
| 40 | 4 | $missing->insert(@missing); | |||||||||||||||||||
| 41 | 4 | $broken->insert($entry->id); | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 70 | $referenced->insert(@ids); | |||||||||||||||||||
| 45 | 70 | $unreferenced->remove(@ids); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 2 | __PACKAGE__ | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =pod | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =head1 NAME | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | KiokuDB::LinkChecker - Reference consistency checker | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 SYNOPSIS | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | use KiokuDB::LinkChecker; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | my $l = KiokuDB::LinkChecker->new( | ||||||||||||||||||||
| 66 | backend => $b, | ||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | my @idw = $l->missing->members; # referenced but not in the DB | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head1 DESCRIPTION | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | This is the low level link checker used by L<KiokuDB::Cmd::Command::FSCK>. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | |||||||||||||||||||||