Data::Unixish - Implementation for Unixish, a data transformation framework
version 1.41
# the a/f/l/c prefix determines whether function accepts # arrayref/file(handle)/list/callback as input. the a/f/l/c suffix determines # whether function returns an array, a list, a filehandle, or calls a callback. # If filehandle is chosen as output, a child process is forked to process input # as requested. use Data::Unixish qw( aduxa cduxa fduxa lduxa aduxc cduxc fduxc lduxc aduxf cduxf fduxf lduxf aduxl cduxl fduxl lduxl ); # or you can use :all to export all functions # apply function, without argument my @out = lduxl('sort', 7, 2, 4, 1); # => (1, 2, 4, 7) my $out = lduxa('uc', "a", "b", "c"); # => ["A", "B", "C"] my $res = fduxl('wc', "file.txt"); # => "12\n234\n2093" # like wc's output # apply function, with some arguments my $fh = fduxf([trunc => {width=>80, ansi=>1, mb=>1}], \*STDIN); say while <$fh>;
This distribution implements Unixish, a data transformation framework inspired by Unix toolbox philosophy.
The functions are not exported by default. They can be exported individually or altogether using export tag :all.
:all
The adux* functions accept an arrayref as input. $func is a string containing dux function name (if no arguments to the dux function is to be supplied), or [$func, \%args] to supply arguments to the dux function. Dux function name corresponds to module names Data::Unixish::NAME without the prefix.
adux*
$func
[$func, \%args]
Data::Unixish::NAME
The *duxc functions will call the callback repeatedly with every output item.
*duxc
The *duxf functions returns filehandle immediately. A child process is forked, and dux function is run in the child process. You read output as lines from the returned filehandle.
*duxf
The *duxl functions returns result as list. It can be evaluated in scalar to return only the first element of the list. However, the whole list will be calculated first. Use *duxf for streaming interface.
*duxl
The cdux* functions accepts a callback ($icallback) to get input elements from. Input callback function should return a list of one or more elements, or an empty list to signal end of stream.
cdux*
$icallback
An example:
cduxa($func, sub { state $a = [1,2,3,4]; if (@$a) { return shift(@$a); } else { return (); } });
The fdux* functions accepts filename or filehandle. @args is optional and will be passed to Tie::File.
fdux*
@args
The ldux* functions accepts list as input.
ldux*
None are exported by default, but they are exportable.
You can use Tie::Diamond, e.g.:
use Tie::Diamond; tie my(@in), "Tie::Diamond"; my $out = aduxa($func, \@in);
Also see the dux command-line utility in the App::dux distribution which allows you to access dux function from the command-line.
Unixish
dux script in App::dux
Steven Haryanto <stevenharyanto@gmail.com>
This software is copyright (c) 2013 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Unixish, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Unixish
CPAN shell
perl -MCPAN -e shell install Data::Unixish
For more information on module installation, please visit the detailed CPAN module installation guide.