YAML::Tiny::Stream - Document psuedo-streaming for YAML::Tiny
my $parser = YAML::Tiny::Stream->new('lots-of-documents.yml'); while ( my $yaml = $parser->fetch ) { # Handle the document }
To keep the design small and contained, YAML::Tiny intentionally discards support for streamed parsing of YAML documents.
In situations where a file contains a very large number of very small YAML documents, YAML::Tiny::Stream provides a limited implementation of streaming that scans for YAML's --- document separators and parses them one entire document at a time.
Please note this approach does come with caveats, as any situation in which a triple dash occurs legitimately at the beginning of a line (such as in a quote) may be accidently detected as a new document by mistake.
If you really do need a "proper" streaming parser, then you should see YAML or one of the other full blown YAML implementations.
my $stream = YAML::Tiny::Stream->new($file);
The new constructor creates a new stream handle.
new
It takes a single parameter of a file name, which it will open via IO::File.
In this quick initial implementation, the file handle will remain open until the stream object is destroyed.
The file accessor returns the original file passed to the constructor.
file
The handle accessor returns the IO handle being used to read in the YAML stream.
handle
my $yaml_tiny = $stream->fetch;
The fetch method reads from the file until it hits the end of the next document. This document is then passed to YAML::Tiny to be parsed.
fetch
Returns a YAML::Tiny object containing a single document, or undef if there are no more documents in the stream. Throws an exception if there is an IO or parsing error.
undef
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=YAML-Tiny-Stream
For other issues, contact the author.
Adam Kennedy <adamk@cpan.org>
YAML, YAML::Syck, Config::Tiny, CSS::Tiny, http://use.perl.org/~Alias/journal/29427, http://ali.as/
Copyright 2011 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install YAML::Tiny::Stream, copy and paste the appropriate command in to your terminal.
cpanm
cpanm YAML::Tiny::Stream
CPAN shell
perl -MCPAN -e shell install YAML::Tiny::Stream
For more information on module installation, please visit the detailed CPAN module installation guide.