WebService::Lucene::Iterator - Iterator for lazy document inflation


WebService-Lucene documentation Contained in the WebService-Lucene distribution.

Index


Code Index:

NAME

Top

WebService::Lucene::Iterator - Iterator for lazy document inflation

SYNOPSIS

Top

    use WebService::Lucene::Iterator;

    my $iterator = WebService::Lucene::Iterator->new( $documents );

DESCRIPTION

Top

All search results are returned as XML::Atom::Entry objects which get inflated to WebService::Lucene::Document objects. This module allows us to delay that inflation as late as possible.

METHODS

Top

new( $documents )

Generates a new iterator that will iterate through $documents as requested.

iterator( [$iterator] )

Accessor for the iterator closure.

next( )

Inflates and returns the next document object.

AUTHORS

Top

* Brian Cassidy <brian.cassidy@nald.ca>
* Adam Paynter <adam.paynter@nald.ca>

COPYRIGHT AND LICENSE

Top


WebService-Lucene documentation Contained in the WebService-Lucene distribution.
package WebService::Lucene::Iterator;

use strict;
use warnings;

use base qw( Class::Accessor::Fast );

use WebService::Lucene::Document;

__PACKAGE__->mk_accessors( qw( iterator ) );

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;
}

sub next {
    return shift->iterator->();
}

1;