| 1 | package DBM::Deep::Iterator::File; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 48 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 48 | ▶ | use warnings FATAL => 'all'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 48 | ▶ | use base qw( DBM::Deep::Iterator ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 48 | ▶ | use DBM::Deep::Iterator::File::BucketList (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 48 | ▶ | use DBM::Deep::Iterator::File::Index (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 299 | ▶ | sub reset { $_[0]{breadcrumbs} = []; return } | ||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | sub get_sector_iterator { | ||||||||||||||
| 14 | 355 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
get_sector_iterator: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||
| 15 | 355 | my ($loc) = @_; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 355 | ▶ | my $sector = $self->{engine}->load_sector( $loc ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | or return; | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 355 | ▶ | if ( $sector->isa( 'DBM::Deep::Sector::File::Index' ) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 21 | 16 | return DBM::Deep::Iterator::File::Index->new({ | |||||||||||||
| 22 | iterator => $self, | ||||||||||||||
| 23 | sector => $sector, | ||||||||||||||
| 24 | }); | ||||||||||||||
| 25 | } | ||||||||||||||
| 26 | elsif ( $sector->isa( 'DBM::Deep::Sector::File::BucketList' ) ) { | ||||||||||||||
| 27 | 339 | return DBM::Deep::Iterator::File::BucketList->new({ | |||||||||||||
| 28 | iterator => $self, | ||||||||||||||
| 29 | sector => $sector, | ||||||||||||||
| 30 | }); | ||||||||||||||
| 31 | } | ||||||||||||||
| 32 | |||||||||||||||
| 33 | 0 | DBM::Deep->_throw_error( "get_sector_iterator(): Why did $loc make a $sector?" ); | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | sub get_next_key { | ||||||||||||||
| 37 | 531 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
get_next_key: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||
| 38 | 531 | my ($obj) = @_; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 531 | my $crumbs = $self->{breadcrumbs}; | |||||||||||||
| 41 | 531 | my $e = $self->{engine}; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 531 | ▶ | unless ( @$crumbs ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | # This will be a Reference sector | ||||||||||||||
| 45 | my $sector = $e->load_sector( $self->{base_offset} ) | ||||||||||||||
| 46 | # If no sector is found, this must have been deleted from under us. | ||||||||||||||
| 47 | 153 | ▶ | or return; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 152 | ▶ | if ( $sector->staleness != $obj->_staleness ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 0 | return; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 152 | ▶ | my $loc = $sector->get_blist_loc | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | or return; | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 147 | push @$crumbs, $self->get_sector_iterator( $loc ); | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | FIND_NEXT_KEY: { | ||||||||||||||
| 60 | # We're at the end. | ||||||||||||||
| 61 | 525 | ▶ | unless ( @$crumbs ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 146 | $self->reset; | |||||||||||||
| 63 | 146 | return; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 5988 | my $iterator = $crumbs->[-1]; | |||||||||||||
| 67 | |||||||||||||||
| 68 | # This level is done. | ||||||||||||||
| 69 | 5988 | ▶ | if ( $iterator->at_end ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 354 | pop @$crumbs; | |||||||||||||
| 71 | 354 | redo FIND_NEXT_KEY; | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 5634 | ▶ | if ( $iterator->isa( 'DBM::Deep::Iterator::File::Index' ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | # If we don't have any more, it will be caught at the | ||||||||||||||
| 76 | # prior check. | ||||||||||||||
| 77 | 224 | ▶ | if ( my $next = $iterator->get_next_iterator ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 208 | push @$crumbs, $next; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | 224 | redo FIND_NEXT_KEY; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 5410 | ▶ | unless ( $iterator->isa( 'DBM::Deep::Iterator::File::BucketList' ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | 0 | DBM::Deep->_throw_error( | |||||||||||||
| 85 | "Should have a bucketlist iterator here - instead have $iterator" | ||||||||||||||
| 86 | ); | ||||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | # At this point, we have a BucketList iterator | ||||||||||||||
| 90 | 5410 | my $key = $iterator->get_next_key; | |||||||||||||
| 91 | 5410 | ▶ | if ( defined $key ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | 379 | return $key; | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | #XXX else { $iterator->set_to_end() } ? | ||||||||||||||
| 95 | |||||||||||||||
| 96 | # We hit the end of the bucketlist iterator, so redo | ||||||||||||||
| 97 | 5031 | redo FIND_NEXT_KEY; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | DBM::Deep->_throw_error( "get_next_key(): How did we get here?" ); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 48 | 1; | |||||||||||||
| 104 | __END__ | ||||||||||||||