None available.
sub new
{ my $class = shift;
my ($data,$callback) = @_;
my $pos = 0;
return bless {data => $data,
pos => $pos,
callback => $callback,
cache => []},$class;
} |
sub next_feature
{ my $self = shift;
return shift @{$self->{cache}} if @{$self->{cache}};
my $data = $self->{data} or return;
my $next_feature_pos = $self->{pos};
my $callback = $self->{callback};
my $features;
while (1) {
if ($next_feature_pos < @{$self->{data}}){
my $feature = $self->{data}[$next_feature_pos];
$features = $callback->(@{$feature});
$self->{pos}++;
last if $features;
} else {
undef $self->{pos};
undef $self->{data};
$features = $callback->();
return;
}
}
$self->{cache} = $features or return;
shift @{$self->{cache}};} |