SimpleGraph/Iterator.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 56 CC 4 SCAR 23.0
CC
4
Cov
0%
next_feature
20.0
new
2.0
BEGIN
2.0
CRAP 10.0
1 =head1 NAME
2  
3 Bio::DB::GFF::Adaptor::dbi::iterator - iterator for Bio::DB::GFF::Adaptor::dbi
4  
5 =head1 SYNOPSIS
6  
7 For internal use only
8  
9 =head1 DESCRIPTION
10  
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().
16  
17 =head1 BUGS
18  
19 None known yet.
20  
21 =head1 SEE ALSO
22  
23 L<Bio::DB::GFF>,
24  
25 =head1 AUTHOR
26  
27 Lincoln Stein E<lt>lstein@cshl.orgE<gt>.
28  
29 Copyright (c) 2001 Cold Spring Harbor Laboratory.
30  
31 This library is free software; you can redistribute it and/or modify
32 it under the same terms as Perl itself.
33  
34 =cut
35  
36 package Bio::DB::GFF::Adaptor::dbi::iterator;
37 use strict;
38  
39 use constant STH => 0;
40 use constant CALLBACK => 1;
41 use constant CACHE => 2;
42  
43 *next_seq = \&next_feature;
44  
45 sub new {
46 my $class = shift;
47 my ($sth,$callback) = @_;
48 return bless [$sth,$callback,[]],$class;
49 }
50  
51 sub next_feature {
52 my $self = shift;
53 return shift @{$self->[CACHE]} if @{$self->[CACHE]};
54 my $sth = $self->[STH] or return;
55 my $callback = $self->[CALLBACK];
56  
57 my $features;
58 while (1) {
59 if (my @row = $sth->fetchrow_array) {
60 $features = $callback->(@row);
61 last if $features;
62 } else {
63 $sth->finish;
64 undef $self->[STH];
65 $features = $callback->();
66 last;
67 }
68 }
69 $self->[CACHE] = $features or return;
70 shift @{$self->[CACHE]};
71 }
72  
73 1;