| 1 | package DBM::Deep::Iterator::File; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 23 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 23 | ▶ | use warnings FATAL => 'all'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 23 | ▶ | use base qw( DBM::Deep::Iterator ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 23 | ▶ | use DBM::Deep::Iterator::File::BucketList (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 23 | ▶ | use DBM::Deep::Iterator::File::Index (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 308 | ▶ | sub reset { $_[0]{breadcrumbs} = []; return } | ||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | sub get_sector_iterator { | ||||||||||||||
| 14 | 346 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
get_sector_iterator: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||
| 15 | 346 | my ($loc) = @_; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 346 | ▶ | my $sector = $self->{engine}->load_sector( $loc ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | or return; | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 346 | ▶ | if ( $sector->isa( 'DBM::Deep::Sector::File::Index' ) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 21 | 15 | 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 | 331 | 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 | 541 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
get_next_key: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||
| 38 | 541 | my ($obj) = @_; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 541 | my $crumbs = $self->{breadcrumbs}; | |||||||||||||
| 41 | 541 | my $e = $self->{engine}; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 541 | ▶ | 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 | 158 | ▶ | or return; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 157 | ▶ | if ( $sector->staleness != $obj->_staleness ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 0 | return; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 157 | ▶ | my $loc = $sector->get_blist_loc | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | or return; | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 151 | push @$crumbs, $self->get_sector_iterator( $loc ); | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | FIND_NEXT_KEY: { | ||||||||||||||
| 60 | # We're at the end. | ||||||||||||||
| 61 | 534 | ▶ | unless ( @$crumbs ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 150 | $self->reset; | |||||||||||||
| 63 | 150 | return; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 5837 | my $iterator = $crumbs->[-1]; | |||||||||||||
| 67 | |||||||||||||||
| 68 | # This level is done. | ||||||||||||||
| 69 | 5837 | ▶ | if ( $iterator->at_end ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 345 | pop @$crumbs; | |||||||||||||
| 71 | 345 | redo FIND_NEXT_KEY; | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 5492 | ▶ | 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 | 210 | ▶ | if ( my $next = $iterator->get_next_iterator ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 195 | push @$crumbs, $next; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | 210 | redo FIND_NEXT_KEY; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 5282 | ▶ | 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 | 5282 | my $key = $iterator->get_next_key; | |||||||||||||
| 91 | 5282 | ▶ | if ( defined $key ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | 384 | return $key; | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | #XXX else { $iterator->set_to_end() } ? | ||||||||||||||
| 95 | |||||||||||||||
| 96 | # We hit the end of the bucketlist iterator, so redo | ||||||||||||||
| 97 | 4898 | redo FIND_NEXT_KEY; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | DBM::Deep->_throw_error( "get_next_key(): How did we get here?" ); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 23 | 1; | |||||||||||||
| 104 | __END__ | ||||||||||||||