NAME

Piper::Process - A data-processing unit for the Piper pipeline system

CONSTRUCTOR

new(@args)

The constructor accepts the following patterns for @args:

Piper::Process->new({
    label      => $label,    # recommended
    handler    => $handler,  # required
    batch_size => $num,      # optional
    allow      => $allow,    # optional
    enabled    => $enabled,  # default: 1
});

Piper::Process->new(
    $label => {
        handler    => $handler,
        batch_size => $num,
        allow      => $allow,
        enabled    => $enabled,
    }
);

Piper::Process->new($label => $handler);

ATTRIBUTES

allow

An optional coderef used to subset the items which are allowed to be processed by the segment.

The coderef runs on each item attempting to queue to the segment. If it returns true, the item is queued. Otherwise, the item skips the segment and proceeds to the next adjacent segment.

Each item is localized to $_, and is also passed in as the first argument. These example allow subroutines are equivalent:

# This segment only accepts digit inputs
sub { /^\d+$/ }
sub { $_ =~ /^\d+$/ }
sub { $_[0] =~ /^\d+$/ }

batch_size

The number of items to process at a time for the segment. Once initialized, a segment inherits the batch_size of its parent(s) if not provided.

enabled

Boolean indicating that the segment is enabled and can accept items for processing. Defaults to true.

handler

The data-processing subroutine for this segment.

The arguments provided to the handler are as follows:

$instance - the instance corresponding to the segment
$batch    - an arrayref of items to process
@args     - the init arguments (if any) provided
            at the initialization of the pipeline

Via the provided $instance object (Piper::Instance), the handler has several options for sending data to other pipes or processes in the pipeline:

$instance->eject(@data)
$instance->emit(@data)
$instance->inject(@data)
$instance->injectAfter($location, @data)
$instance->injectAt($location, @data)
$instance->recycle(@data)

See Piper or Piper::Instance for an explanation of these methods.

Example handler:

sub {
    my ($instance, $batch) = @_;
    $instance->emit(map { ... } @$batch);
}

id

A globally unique ID for the segment. This is primarily useful for debugging only.

label

A label for this segment. If no label is provided, the segment's id will be used.

Labels are necessary if any handlers wish to use the injectAt or injectAfter methods. Otherwise, labels are primarily useful for logging and/or debugging.

Stringification of a Piper::Process object is overloaded to return its label:

my $process = Piper::Process->new($label => sub {...});

$process->label; # $label
"$process";      # $label

METHODS

has_allow

A boolean indicating whether or not an allow attribute exists for this segment.

has_batch_size

A boolean indicating whether the segment has an assigned batch_size.

init

Returns a Piper::Instance object for this segment.

SEE ALSO

Piper
Piper::Instance

VERSION

version 0.03

AUTHOR

Mary Ehlers <ehlers@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Mary Ehlers.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004