Piper::Process - A data-processing unit for the Piper pipeline system
The constructor accepts the following patterns for @args:
@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);
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:
$_
allow
# This segment only accepts digit inputs sub { /^\d+$/ } sub { $_ =~ /^\d+$/ } sub { $_[0] =~ /^\d+$/ }
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.
batch_size
Boolean indicating that the segment is enabled and can accept items for processing. Defaults to true.
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
$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); }
A globally unique ID for the segment. This is primarily useful for debugging only.
A label for this segment. If no label is provided, the segment's id will be used.
id
Labels are necessary if any handlers wish to use the injectAt or injectAfter methods. Otherwise, labels are primarily useful for logging and/or debugging.
injectAt
injectAfter
Stringification of a Piper::Process object is overloaded to return its label:
my $process = Piper::Process->new($label => sub {...}); $process->label; # $label "$process"; # $label
A boolean indicating whether or not an allow attribute exists for this segment.
A boolean indicating whether the segment has an assigned batch_size.
Returns a Piper::Instance object for this segment.
version 0.05
Mary Ehlers <ehlers@cpan.org>
This software is Copyright (c) 2017 by Mary Ehlers.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
To install Piper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Piper
CPAN shell
perl -MCPAN -e shell install Piper
For more information on module installation, please visit the detailed CPAN module installation guide.