NAME

DBIx::Squirrel::Pipeline - run values through a list of stages

SYNOPSIS

use DBIx::Squirrel::Pipeline;

my $p = DBIx::Squirrel::Pipeline->new(
    sub { $_->{active} ? $_ : () },          # filter
    sub ($row) { @{ $row->{tags} } },        # flatMap
    sub { uc },                              # map
);

# Push: values in, a list out
my @tags = $p->(@rows);

# Pull: one value per call, from a source
my $next = $p->iterator(sub { $sth->fetchrow_hashref // () });
while (my($tag) = $next->()) { ... }

DESCRIPTION

DBIx::Squirrel's pipeline, which its iterators, result sets, Sugar statements and handles' pipe and tap run their stages with. It's a subclass of Ekorn::Pipeline, which describes it in full, and inherits its methods, new, iterator and stages; a pipeline can be called as a code reference with values, as an Ekorn::Pipeline can.

A function of your own can take stages from its caller, and run what it returns through them:

sub bands (@stages) {
    return DBIx::Squirrel::Pipeline->new(@stages)->(load_bands());
}

stages returns a pipeline's stages, in order, so a pipeline made once can be used wherever stages go, with more after them. A pipeline isn't a stage itself, so give its stages, not the pipeline:

my $hits = DBIx::Squirrel::Pipeline->new(sub { $_->[1] >= 5000 ? $_ : () }, pluck('name'));
my @top  = $dbh->iterate($sql, $hits->stages, take(10))->all;

SEE ALSO

Ekorn::Pipeline, DBIx::Squirrel, DBIx::Squirrel::Gather, DBIx::Squirrel::Stop

AUTHOR

Iain Campbell <cpanic@cpan.org>

LICENSE

Copyright (c) 2024-2026 by Iain Campbell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.