Perinci::Examples::Stream - Examples for streaming input/output
This document describes version 0.80 of Perinci::Examples::Stream (from Perl distribution Perinci-Examples), released on 2017-07-11.
This package contains functions that demonstrate streaming input/output.
Usage:
count_ints(%args) -> [status, msg, result, meta]
This function accepts a stream of integers and return the number of integers input.
This function is not exported.
Arguments ('*' denotes required arguments):
input => array[int]
Numbers.
Returns an enveloped result (an array).
First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.
Return value: (any)
count_lines(%args) -> [status, msg, result, meta]
Count number of lines in the input.
input => array[str]
Lines.
count_words(%args) -> [status, msg, result, meta]
This function receives a stream of words and return the number of words.
Input validation will check that each record from the stream is a word.
produce_hashes(%args) -> [status, msg, result, meta]
This function produces a stream of hashes.
num => int
Limit number of entries to produce.
The default is to produce an infinite number.
Return value: (array[hash])
produce_ints(%args) -> [status, msg, result, meta]
This function produces a stream of integers, starting from 1.
Return value: (array[int])
produce_words(%args) -> [status, msg, result, meta]
This function produces a stream of random words.
Return value: (array[str])
produce_words_err(%args) -> [status, msg, result, meta]
Like `produce_words()`, but 1 in every 10 words will be a non-word (which fails the result schema).
square_nums(%args) -> [status, msg, result, meta]
This function squares its stream input.
input* => array[float]
Return value: (array[float])
square_nums_from_file(%args) -> [status, msg, result, meta]
square_nums_from_stdin(%args) -> [status, msg, result, meta]
square_nums_from_stdin_or_file(%args) -> [status, msg, result, meta]
input* => float
wc(%args) -> [status, msg, result, meta]
Count the number of lines/words/characters of input, like the "wc" command.
input* => array[str]
Return value: (hash)
wc_keys(%args) -> [status, msg, result, meta]
Count the number of keys of each hash.
This is a simple demonstration of accepting a stream of hashes. In command-line application this will translate to JSON stream.
input* => array[hash]
Please visit the project's homepage at https://metacpan.org/release/Perinci-Examples.
Source repository is at https://github.com/perlancar/perl-Perinci-Examples.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Examples
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar@cpan.org.
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 Perinci::Examples, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perinci::Examples
CPAN shell
perl -MCPAN -e shell install Perinci::Examples
For more information on module installation, please visit the detailed CPAN module installation guide.