NAME

DBIx::Squirrel::Context - what a stage can ask about the result it's making

SYNOPSIS

use DBIx::Squirrel::Context qw(result_number result_original);

my $it = $dbh->iterate(
    'SELECT name FROM artist ORDER BY name',
    sub ($row) { "@{[ result_number ]}. $row->[0]" },
);

DESCRIPTION

Inside a stage, these functions tell the stage about the result it's making: things it can't work out from the value it's given. "result_number" works in any run: Ekorn::Pipeline counts every run's results, and these are its numbers. "result_original" gives a statement's row in any run reading one: an iterator's own stages, and those of a chain made with |, or of a pipeline of yours, reading one; in any other run, the value its source gave, or that was pushed, as Ekorn::Pipeline::Context has it. "iterator" works only in an iterator's own stages, run by its next, all, first or single, and gives undef elsewhere; outside a run, all three do. None is exported by default.

FUNCTIONS

iterator

The iterator running the stage, in its own stages. Its sth is the statement handle, and the statement handle's Database is the database handle.

result_number

The number of the result being made, from 1. It counts results, not rows. While a stage drops rows, the number stays the same. Each value a stage returns in place of one row is a result of its own. In a flush of a stage made with DBIx::Squirrel::Gather, it's the number of the first value the flush returns. A sink's step sees the number of the value it's given. Every run counts its own results, so a pipeline run inside a stage counts from 1, and leaves the count of the run around it as it was. It's Ekorn::Pipeline::Context's, with an empty prototype, so result_number + 1 adds one.

result_original

The row the result is being made from, as it was fetched, before any stage changed it. In a flush of a stage made with DBIx::Squirrel::Gather, and the stages after it, it's undef. What a flush gives comes from every row, not one. The statement's source keeps the row in its run's context, so it's there wherever a statement is read, through chains too. In a run that reads no statement, it's Ekorn::Pipeline::Context's: the value the run's source gave, or that was pushed.

statement_context

For DBIx::Squirrel's stages, which read a statement's columns from the run they're in. It's not for use elsewhere.

within

For DBIx::Squirrel's iterators, which set the context while their stages run. It's not for use elsewhere.

SEE ALSO

DBIx::Squirrel::Iterator, Ekorn::Pipeline, Ekorn::Pipeline::Context

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.