NAME
DataFlow::Proc - A data processor class
VERSION
version 1.121830
SYNOPSIS
use DataFlow::Proc;
my $uc = DataFlow::Proc->new( p => sub { uc } );
my @res = $uc->process( 'something' );
# @res == qw/SOMETHING/;
my @res = $uc->process( [qw/aaa bbb ccc/] );
# @res == [qw/AAA BBB CCC/];
Or
my $uc_deref = DataFlow::Proc->new(
deref => 1,
p => sub { uc }
);
my @res = $uc_deref->process( [qw/aaa bbb ccc/] );
# @res == qw/AAA BBB CCC/;
DESCRIPTION
This is a Moose based class that provides the idea of a processing step in a data-flow. It attemps to be as generic and unassuming as possible, in order to provide flexibility for implementors to make their own specialized processors as they see fit.
Apart from atribute accessors, an object of the type DataFlow::Proc
will provide only a single method, process()
, which will process a single scalar.
ATTRIBUTES
name
[Str] A descriptive name for the dataflow. (OPTIONAL)
allows_undef_input
[Bool] It controls whether $self->p->()
will accept undef
as input or if DataFlow::Proc will filter those out. (DEFAULT = false)
deref
[Bool] Signals whether the result of the processing will be de-referenced upon output or if DataFlow::Proc will preserve the original reference. (DEFAULT = false)
dump_input
[Bool] Dumps the input parameter to STDERR before processing. See DataFlow::Role::Dumper. (DEFAULT = false)
dump_output
[Bool] Dumps the results to STDERR after processing. See DataFlow::Role::Dumper. (DEFAULT = false)
p
[CodeRef] The actual work horse for this class. It is treated as a function, not as a method, as in:
my $proc = DataFlow::Proc->new( p => sub { ucfirst } );
The sub referenced by p
is run with a localized version the special variable $_
, containing the value of the data to be processed.
It only makes sense to access $self
when one is sub-classing DataFlow::Proc and adding new attibutes or methods, in which case one can do as below:
package MyProc;
use Moose;
extends 'DataFlow::Proc';
has 'x_factor' => ( isa => 'Int' );
sub _build_p {
my $self = shift;
return sub { $_ * int( rand( $self->x_factor ) ) };
}
package main;
my $proc = MyProc->new( x_factor => 5 );
This sub will be called in array context. There is no other restriction on what this code reference can or should do. (REQUIRED)
METHODS
process
Processes one single scalar (or anything else that can be passed in on scalar, such as references or globs), and returns the application of the function $self->p->()
over the item.
SEE ALSO
Please see those modules/websites for more information related to this module.
AUTHOR
Alexei Znamensky <russoz@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Alexei Znamensky.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the web interface at http://rt.cpan.org.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.