Benjamin Trott > Data-ConveyorBelt > Data::ConveyorBelt

Download:
Data-ConveyorBelt-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Data::ConveyorBelt

SYNOPSIS ^

    my @data = ( 1 .. 15 );

    my $machine = Data::ConveyorBelt->new;
    $machine->getter( sub {
        my( $limit, $offset ) = @_;
        $offset ||= 0;
        return [ @data[ $offset .. $offset + $limit ] ];
    } );

    $machine->add_filter( sub {
        my( $data ) = @_;
        return [ grep { $_ % 2 == 1 } @$data ];
    } );
    
    my $data = $machine->fetch( limit => 5 );

DESCRIPTION ^

USAGE ^

Data::ConveyorBelt->new

Returns a new Data::ConveyorBelt instance.

$machine->getter( [ \&getter ] )

Gets/sets the getter subroutine \&getter that represents the list of items in your data source. Required before calling fetch.

A getter subroutine will be passed two arguments: the number of items to return, and the offset into the list (0-based). It must return a reference to the matching list of items.

$machine->add_filter( \&filter )

Adds a filter subroutine \&filter to your chain of filters.

A filter will be passed a reference to a list of items as returned either from your getter or from a previous filter in the chain. A filter must return a reference to a list of items.

A filter can alter the size of the list of items, either removing or expanding items in the list. It can also transform the items in the list.

$machine->fetch( %param )

Fetches a list of items from your data source, passes them through your filters, and returns a reference to a list of items.

You must install a getter before calling fetch, but you don't have to install any filters. Running fetch without any filters does what you'd expect: it returns the values directly from your data source, unmodified and unfiltered.

%param can contain:

LICENSE ^

Data::ConveyorBelt is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR & COPYRIGHT ^

Except where otherwise noted, Data::ConveyorBelt is Copyright 2007 Six Apart, cpan@sixapart.com.

syntax highlighting: