NAME
YAML::Tiny::Stream - Document psuedo-streaming for YAML::Tiny
SYNOPSIS
my $parser = YAML::Tiny::Stream->new('lots-of-documents.yml');
while ( my $yaml = $parser->fetch ) {
# Handle the document
}
DESCRIPTION
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.
METHODS
new
my $stream = YAML::Tiny::Stream->new($file);
The new
constructor creates a new stream handle.
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.
file
The file
accessor returns the original file passed to the constructor.
handle
The handle
accessor returns the IO handle being used to read in the YAML stream.
fetch
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.
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.
SUPPORT
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.
AUTHOR
Adam Kennedy <adamk@cpan.org>
SEE ALSO
YAML, YAML::Syck, Config::Tiny, CSS::Tiny, http://use.perl.org/~Alias/journal/29427, http://ali.as/
COPYRIGHT
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.