package WebService::Lucene::Iterator; use strict; use warnings; use base qw( Class::Accessor::Fast ); use WebService::Lucene::Document; __PACKAGE__->mk_accessors( qw( iterator ) ); =head1 NAME WebService::Lucene::Iterator - Iterator for lazy document inflation =head1 SYNOPSIS use WebService::Lucene::Iterator; my $iterator = WebService::Lucene::Iterator->new( $documents ); =head1 DESCRIPTION All search results are returned as L objects which get inflated to L objects. This module allows us to delay that inflation as late as possible. =head1 METHODS =head2 new( $documents ) Generates a new iterator that will iterate through C<$documents> as requested. =cut sub new { my ( $class, $documents ) = @_; my $self = $class->SUPER::new; my $index = 0; $self->iterator( sub { my $document = $documents->[ $index ]; return undef unless $document; $index++; return WebService::Lucene::Document->new_from_entry( $document ); } ); return $self; } =head2 iterator( [$iterator] ) Accessor for the iterator closure. =head2 next( ) Inflates and returns the next document object. =cut sub next { return shift->iterator->(); } =head1 AUTHORS =over 4 =item * Brian Cassidy Ebrian.cassidy@nald.caE =item * Adam Paynter Eadam.paynter@nald.caE =back =head1 COPYRIGHT AND LICENSE Copyright 2008 National Adult Literacy Database This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;