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);
$first   = $object->pipe(@stages);

Runs the invocant through a pipeline of @stages, and returns what comes out of the last stage. 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). In scalar context, it returns the first result, or undef if there are none. With no stages, it returns the invocant.

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.