NAME
DataFlow::Proc - A data processor class
VERSION
version 1.111500
SYNOPSIS
use DataFlow::Proc;
my $uc = DataFlow::Proc->new(
p => sub {
return uc(shift);
}
);
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 {
return uc(shift);
}
);
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)
process_into
[Bool] It signals whether this processor will attempt to process data within references or not. If process_into is true, then process_item
will be applied into the values referenced by any scalar, array or hash reference and onto the result of running any code reference. (DEFAULT = true)
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 {
my $data = shift;
return ucfirst($data);
}
);
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' );
has '+p' => (
default => sub { # not the p value, but the sub that returns it
my $self = shift;
return sub {
my $data = shift;
return $data * 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.
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
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://github.com/russoz/DataFlow/issues.
AVAILABILITY
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/DataFlow/.
The development version lives at http://github.com/russoz/DataFlow and may be cloned from git://github.com/russoz/DataFlow.git. Instead of sending patches, please fork this project using the standard git and github infrastructure.
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.