3 Bio::DB::GFF::Adaptor::berkeleydb::iterator - iterator for Bio::DB::GFF::Adaptor::berkeleydb
11 This is an internal module that is used by the Bio::DB::GFF in-memory
12 adaptor to return an iterator across a sequence feature query. The
13 object has a single method, next_feature(), that returns the next
14 feature from the query. The method next_seq() is an alias for
27 Lincoln Stein E<lt>lstein@cshl.orgE<gt>.
29 Copyright (c) 2001 Cold Spring Harbor Laboratory.
31 This library is free software; you can redistribute it and/or modify
32 it under the same terms as Perl itself.
36 package Bio
::DB
::GFF
::Adaptor
::berkeleydb
::iterator
;
38 use DB_File
qw(R_FIRST R_NEXT);
40 # this module needs to be cleaned up and documented
41 use Bio
::Root
::Version
;
42 *next_seq
= \
&next_feature
;
46 my ($data,$callback,$tmpfile) = @_;
47 return bless {data
=> $data,
48 callback
=> $callback,
55 return shift @
{$self->{cache
}} if @
{$self->{cache
}};
57 my $data = $self->{data
} or return;
58 my $callback = $self->{callback
};
61 my $db = tied(%$data);
64 for (my $status = $db->seq($key,$value,$self->{iter
}++ ? R_NEXT
: R_FIRST
);
66 $status = $db->seq($key,$value,R_NEXT
)) {
67 my @feature = split ($;,$value);
68 $features = $callback->(@feature);
73 $features = $callback->();
76 unlink $self->{tmpfile
};
79 $self->{cache
} = $features or return;
80 shift @
{$self->{cache
}};