NAME

Ekorn::Pipeline::Stages::Taps - stages run for their side effects: peek, count_into and dump_to

SYNOPSIS

use Ekorn::Pipeline;
use Ekorn::Pipeline::Stages::Taps;    # peek and count_into

my $read = 0;
my @names = Ekorn::Pipeline->new(
    count_into(\$read),                 # how many values were read
    peek { log_user($_) },              # each value, as it goes by
    sub { $_->{name} },
)->(@users);

use Ekorn::Pipeline::Stages::Taps qw(dump_to);

Ekorn::Pipeline->new(dump_to)->(@users);    # to STDERR

DESCRIPTION

Stages that look at each value as it goes by, and pass it on as it is, for logging, counting or debugging. A stage passes on what it returns, so a stage of your own run for its side effects has to return its value; these do that for you. Each function returns a stage, and checks what it's given when it's called, not on each value.

They're stages, so they work wherever stages do: in any pipeline, or on an object with pipe and tap, from Ekorn::Pipeline::Pipes, whose first value is the object:

$client->tap(peek { say "connected to $_->{host}" })->run;

FUNCTIONS

peek and count_into are exported by default; dump_to on request, or all three with :all.

peek

peek { ... }

Calls the block with each value, in $_ and as its argument, and passes the value on, whatever the block returns.

count_into

count_into(\$count)

Counts the values into $count, setting it to 0 at the start of each run, so after a run it holds how many values went by, even when that's none.

dump_to

dump_to($fh)
dump_to

Writes each value to $fh, or to STDERR, with Data::Dumper, its keys in order, and passes it on.

It's for debugging. It writes each value in full, secrets and all, and doesn't escape control characters in strings, so a value from outside can send escape sequences to a terminal.

DIAGNOSTICS

Expected a code reference

peek was given something other than a block or code reference.

Expected a reference to a scalar

count_into was given something other than a reference to a scalar.

Expected an open filehandle

dump_to was given something other than an open filehandle.

SEE ALSO

Ekorn::Pipeline, Ekorn::Pipeline::Gather, Data::Dumper

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.