t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / DB / GFF / Adaptor / memory / iterator.pm
blob2eaa8b57aa48755dff020c92f28ed51c5785013b
1 =head1 NAME
3 Bio::DB::GFF::Adaptor::memory::iterator - iterator for Bio::DB::GFF::Adaptor::memory
5 =head1 SYNOPSIS
7 For internal use only
9 =head1 DESCRIPTION
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
15 next_feature().
17 =head1 BUGS
19 None known yet.
21 =head1 SEE ALSO
23 L<Bio::DB::GFF>,
25 =head1 AUTHOR
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.
34 =cut
36 package Bio::DB::GFF::Adaptor::memory::iterator;
37 use strict;
38 # this module needs to be cleaned up and documented
39 use Bio::Root::Version;
41 *next_seq = \&next_feature;
43 sub new {
44 my $class = shift;
45 my ($data,$callback) = @_;
46 my $pos = 0;
47 return bless {data => $data,
48 pos => $pos,
49 callback => $callback,
50 cache => []},$class;
51 #return bless [$sth,$callback,[]],$class;
54 sub next_feature {
55 my $self = shift;
56 return shift @{$self->{cache}} if @{$self->{cache}};
58 my $data = $self->{data} or return;
59 my $callback = $self->{callback};
61 my $features;
62 while (1) {
63 my $feature = $data->[$self->{pos}++];
64 if ($feature) {
65 $features = $callback->(@{$feature});
66 last if $features;
67 } else {
68 $features = $callback->();
69 undef $self->{pos};
70 undef $self->{data};
71 undef $self->{cache};
72 last;
75 $self->{cache} = $features or return;
76 shift @{$self->{cache}};