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. Its iterators, result sets, Sugar statements, and handles' pipe and tap run their stages with it. It's a subclass of Ekorn::Pipeline, which describes it in full. It 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());
}

A pipeline can go wherever a stage goes, with more stages before or after it. Its stages run in its place, as if written out there:

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

stages returns a pipeline's stages, in order, for a function that takes only code references.

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.