NAME

Ekorn::Pipeline::Stage - a stage, as an object

SYNOPSIS

use Ekorn::Pipeline::Stage;

my $upper = Ekorn::Pipeline::Stage->new(sub { uc });

Ekorn::Pipeline->new($upper)->('a', 'b');    # A B

DESCRIPTION

A stage is a code reference, called with each value, in $_ and as its argument, returning a list: nothing to drop the value, one to pass it on, several to pass on each. "new" in Ekorn::Pipeline keeps each code reference it's given as a stage object, of this class, so that every part of a pipeline is one of Ekorn's types. You needn't make one yourself.

Called directly, as a code reference, a stage calls its code with what it's given, as its arguments, but doesn't set $_: only a run does.

The code it's made of is kept as it is, never blessed, so the same code reference can go on being used elsewhere. A stage is the same code in every run; a stage that keeps state from one value to the next is made with Ekorn::Pipeline::Gather, made afresh for each run.

The word stage {...}, in Ekorn::Pipeline::Factories, makes one of these from a block.

METHODS

new

my $stage = Ekorn::Pipeline::Stage->new($code);

Returns a stage of $code: a code reference, or an object that can be called as one, other than one of Ekorn's own types, which are already what they are. Anything else croaks.

code

my $code = $stage->code;

Returns the code the stage was made of.

EKORN_STAGE

my $step = $stage->EKORN_STAGE;

Returns the stage's step for a new run: its code, or, for an object called as a code reference, the code it gives. A run calls it as it starts; you needn't.

DIAGNOSTICS

Expected a code reference

"new" was given something that can't be called as code, such as a string.

Expected a code reference, not one of Ekorn's types

"new" was given one of Ekorn's own types, which is already what it is.

SEE ALSO

Ekorn::Pipeline, Ekorn::Pipeline::Gather

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.