File Coverage

Bio/DB/GFF/Adaptor/memory/iterator.pm
Criterion Covered Total %
statement 30 31 96.7
branch 8 10 80.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 42 47 89.3


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Bio::DB::GFF::Adaptor::memory::iterator - iterator for Bio::DB::GFF::Adaptor::memory
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 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().
16              
17             =head1 BUGS
18              
19             None known yet.
20              
21             =head1 SEE ALSO
22              
23             L,
24              
25             =head1 AUTHOR
26              
27             Lincoln Stein Elstein@cshl.orgE.
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::memory::iterator;
37 3     3   18 use strict;
  3         12  
  3         87  
38             # this module needs to be cleaned up and documented
39 3     3   18 use Bio::Root::Version;
  3         6  
  3         27  
40              
41             *next_seq = \&next_feature;
42              
43             sub new {
44 15     15 0 31 my $class = shift;
45 15         22 my ($data,$callback) = @_;
46 15         17 my $pos = 0;
47 15         216 return bless {data => $data,
48             pos => $pos,
49             callback => $callback,
50             cache => []},$class;
51             #return bless [$sth,$callback,[]],$class;
52             }
53              
54             sub next_feature {
55 285     285 0 511 my $self = shift;
56 285 50       306 return shift @{$self->{cache}} if @{$self->{cache}};
  0         0  
  285         568  
57              
58 285 100       552 my $data = $self->{data} or return;
59 280         386 my $callback = $self->{callback};
60              
61 280         318 my $features;
62 280         330 while (1) {
63 285         422 my $feature = $data->[$self->{pos}++];
64 285 100       441 if ($feature) {
65 270         312 $features = $callback->(@{$feature});
  270         545  
66 270 100       556 last if $features;
67             } else {
68 15         31 $features = $callback->();
69 15         27 undef $self->{pos};
70 15         23 undef $self->{data};
71 15         22 undef $self->{cache};
72 15         26 last;
73             }
74             }
75 280 50       524 $self->{cache} = $features or return;
76 280         299 shift @{$self->{cache}};
  280         758  
77             }
78              
79             1;