Bio::DB::SeqFeature::* move namespace into its own distribution.
[bioperl-live.git] / lib / Bio / DB / GFF / Adaptor / dbi / iterator.pm
blob476378721ff9e8aecf93bf9135ba4a0f664e253e
1 =head1 NAME
3 Bio::DB::GFF::Adaptor::dbi::iterator - iterator for Bio::DB::GFF::Adaptor::dbi
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 DBI
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::dbi::iterator;
37 use strict;
38 use Bio::Root::Version;
40 use constant STH => 0;
41 use constant CALLBACK => 1;
42 use constant CACHE => 2;
44 *next_seq = \&next_feature;
46 sub new {
47 my $class = shift;
48 my ($sth,$callback) = @_;
49 return bless [$sth,$callback,[]],$class;
52 sub next_feature {
53 my $self = shift;
54 return shift @{$self->[CACHE]} if @{$self->[CACHE]};
55 my $sth = $self->[STH] or return;
56 my $callback = $self->[CALLBACK];
58 my $features;
59 while (1) {
60 if (my @row = $sth->fetchrow_array) {
61 $features = $callback->(@row);
62 last if $features;
63 } else {
64 $sth->finish;
65 undef $self->[STH];
66 $features = $callback->();
67 last;
70 $self->[CACHE] = $features or return;
71 shift @{$self->[CACHE]};