1 package DBM::Deep::Iterator;
6 use warnings FATAL => 'all';
14 This is an internal-use-only object for L<DBM::Deep/>. It is the iterator
15 for FIRSTKEY() and NEXTKEY().
25 The constructor takes a hashref of params. The hashref is assumed to have the
30 =item * engine (of type L<DBM::Deep::Engine/>
32 =item * base_offset (the base_offset of the invoking DBM::Deep object)
44 engine => $args->{engine},
45 base_offset => $args->{base_offset},
48 Scalar::Util::weaken( $self->{engine} );
55 This method takes no arguments.
57 It will reset the iterator so that it will start from the beginning again.
59 This method returns nothing.
63 sub reset { $_[0]{breadcrumbs} = [] }
65 =head2 get_sector_iterator( $loc )
67 This takes a location. It will load the sector for $loc, then instantiate the right
70 This returns the sector iterator.
74 sub get_sector_iterator {
78 my $sector = $self->{engine}->_load_sector( $loc )
81 if ( $sector->isa( 'DBM::Deep::Engine::Sector::Index' ) ) {
82 return DBM::Deep::Iterator::Index->new({
87 elsif ( $sector->isa( 'DBM::Deep::Engine::Sector::BucketList' ) ) {
88 return DBM::Deep::Iterator::BucketList->new({
94 DBM::Deep->_throw_error( "get_sector_iterator(): Why did $loc make a $sector?" );
97 =head2 get_next_key( $obj )
105 my $crumbs = $self->{breadcrumbs};
106 my $e = $self->{engine};
108 unless ( @$crumbs ) {
109 # This will be a Reference sector
110 my $sector = $e->_load_sector( $self->{base_offset} )
111 # If no sector is found, thist must have been deleted from under us.
114 if ( $sector->staleness != $obj->_staleness ) {
118 my $loc = $sector->get_blist_loc
121 push @$crumbs, $self->get_sector_iterator( $loc );
126 unless ( @$crumbs ) {
131 my $iterator = $crumbs->[-1];
133 # This level is done.
134 if ( $iterator->at_end ) {
139 if ( $iterator->isa( 'DBM::Deep::Iterator::Index' ) ) {
140 # If we don't have any more, it will be caught at the
142 if ( my $next = $iterator->get_next_iterator ) {
143 push @$crumbs, $next;
148 unless ( $iterator->isa( 'DBM::Deep::Iterator::BucketList' ) ) {
149 DBM::Deep->_throw_error(
150 "Should have a bucketlist iterator here - instead have $iterator"
154 # At this point, we have a BucketList iterator
155 my $key = $iterator->get_next_key;
156 if ( defined $key ) {
159 #XXX else { $iterator->set_to_end() } ?
161 # We hit the end of the bucketlist iterator, so redo
165 DBM::Deep->_throw_error( "get_next_key(): How did we get here?" );