Text::ZPL::Stream - Streaming ZPL decoder
use Text::ZPL::Stream; my $stream = Text::ZPL::Stream->new; if ( $stream->push($zpl_chrs) ) { # Parsed at least one complete line: my $ref = $stream->get; # ... } # Or in a loop: while ( defined(my $zpl_chrs = magically_get_some_zpl) ) { $stream->push($zpl_chrs); } my $ref = $stream->get; # ...
A streaming decoder for ZeroMQ Property Language files using Text::ZPL.
ZeroMQ Property Language
See the Text::ZPL documentation for more on ZPL and parsing-related details.
ZPL
my $stream = Text::ZPL::Stream->new( # Optional: max_buffer_size => 512, );
Constructs an object representing a new ZPL stream.
Accepts the following options:
The maximum line length allowed in buffers before an exception is thrown.
Defaults to 0 (unlimited).
$stream->push(@chars); $stream->push($string);
Takes characters (individually or as strings) and collects until an end-of-line marker (\r, \n, or \r\n) is encountered, at which point a parse is called and the reference returned by "get" is altered appropriately.
\r
\n
\r\n
An exception is thrown if parsing fails, or if "max_buffer_size" is reached -- if you're unsure of your incoming data, you may want to wrap push calls with Try::Tiny or similar.
push
Returns the number of complete lines parsed, which can be useful as an indicator that "get" ought be called:
if ( $stream->push($zpl) ) { # Parsed at least one complete line: my $ref = $stream->get; ... }
my $ref = $stream->get;
Returns the HASH reference to the decoded structure.
HASH
This is the actual reference in use by the decoder, not a copy! Altering the structure of the HASH may have unintended consequences, in which case you may want to make use of "dclone" in Storable to create a safe copy.
Returns a string containing the current character buffer (that is, any incomplete line).
Jon Portnoy <avenj@cobaltirc.org>
To install Text::ZPL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::ZPL
CPAN shell
perl -MCPAN -e shell install Text::ZPL
For more information on module installation, please visit the detailed CPAN module installation guide.