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   9 use strict;
  3         6  
  3         69  
38             # this module needs to be cleaned up and documented
39 3     3   9 use Bio::Root::Version;
  3         3  
  3         24  
40              
41             *next_seq = \&next_feature;
42              
43             sub new {
44 15     15 0 20 my $class = shift;
45 15         20 my ($data,$callback) = @_;
46 15         13 my $pos = 0;
47 15         134 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 400 my $self = shift;
56 285 50       202 return shift @{$self->{cache}} if @{$self->{cache}};
  0         0  
  285         527  
57              
58 285 100       505 my $data = $self->{data} or return;
59 280         206 my $callback = $self->{callback};
60              
61 280         166 my $features;
62 280         202 while (1) {
63 285         305 my $feature = $data->[$self->{pos}++];
64 285 100       315 if ($feature) {
65 270         199 $features = $callback->(@{$feature});
  270         433  
66 270 100       470 last if $features;
67             } else {
68 15         27 $features = $callback->();
69 15         20 undef $self->{pos};
70 15         18 undef $self->{data};
71 15         20 undef $self->{cache};
72 15         15 last;
73             }
74             }
75 280 50       440 $self->{cache} = $features or return;
76 280         221 shift @{$self->{cache}};
  280         576  
77             }
78              
79             1;