NAME
Ekorn::Pipeline::Pipes - pipe and tap methods, running an object through stages
SYNOPSIS
package My::Client;
use parent 'Ekorn::Pipeline::Pipes';
package main;
my $client = My::Client->new;
# What the stages make of the object
my @names = $client->pipe(
sub { $_->users },
sub { $_->{name} },
);
# The object itself, after the stages have run for their side effects
$client->tap(sub { $_->log('started') })->run;
DESCRIPTION
A parent class that gives its children two methods, pipe and tap. Each runs the object it's called on through a pipeline of stages, as described in Ekorn::Pipeline. The first stage is called with the object, in $_ and as its argument.
DBIx::Squirrel's database and statement handles have the same two methods, and are where they began.
METHODS
pipe
@results = $object->pipe(@stages);
$count = $object->pipe(@stages);
($first) = $object->pipe(@stages);
$first = $object->pipe(@stages, keep_first);
Runs the invocant through a pipeline of @stages, and returns what the run gives, as Ekorn::Pipeline->new(@stages)->($object) would, in either context: what comes out of the last stage; in scalar context, how many results came out, or, if a sink is last, the sink's result, a list sink's as an array reference, as "new" in Ekorn::Pipeline describes. For one value, read it in list context, or end with a sink of one, such as keep_first. With no stages, it gives the invocant, or, in scalar context, 1.
The stages are what "new" in Ekorn::Pipeline takes: code references and pipelines, not names. To use a named pipeline, pass pipeline('clean') (see "pipeline" in Ekorn::Pipeline::Factories).
Until v0.4.0, in scalar context, it gave the first result, or undef, unlike a pipeline; a list sink's first value, not its list. Code that reads one value from it in scalar context, as my $name = $object->pipe(sub { $_->name }), reads it in list context now, my($name) = ..., or ends with keep_first.
tap
$object = $object->tap(@stages);
Runs the invocant through a pipeline of @stages for their side effects, and returns the invocant, whatever the stages return. A chain of method calls can carry on after it.
SEE ALSO
Ekorn::Pipeline, Ekorn::Pipeline::Stages::Taps
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.