Perl 5 version 32.0 documentation

TAP::Parser::YAMLish::Writer

NAME

TAP::Parser::YAMLish::Writer - Write YAMLish data

VERSION

Version 3.42

SYNOPSIS

  1. use TAP::Parser::YAMLish::Writer;
  2. my $data = {
  3. one => 1,
  4. two => 2,
  5. three => [ 1, 2, 3 ],
  6. };
  7. my $yw = TAP::Parser::YAMLish::Writer->new;
  8. # Write to an array...
  9. $yw->write( $data, \@some_array );
  10. # ...an open file handle...
  11. $yw->write( $data, $some_file_handle );
  12. # ...a string ...
  13. $yw->write( $data, \$some_string );
  14. # ...or a closure
  15. $yw->write( $data, sub {
  16. my $line = shift;
  17. print "$line\n";
  18. } );

DESCRIPTION

Encodes a scalar, hash reference or array reference as YAMLish.

METHODS

Class Methods

new

  1. my $writer = TAP::Parser::YAMLish::Writer->new;

The constructor new creates and returns an empty TAP::Parser::YAMLish::Writer object.

Instance Methods

write

  1. $writer->write($obj, $output );

Encode a scalar, hash reference or array reference as YAML.

  1. my $writer = sub {
  2. my $line = shift;
  3. print SOMEFILE "$line\n";
  4. };
  5. my $data = {
  6. one => 1,
  7. two => 2,
  8. three => [ 1, 2, 3 ],
  9. };
  10. my $yw = TAP::Parser::YAMLish::Writer->new;
  11. $yw->write( $data, $writer );

The $output argument may be:

  • a reference to a scalar to append YAML to
  • the handle of an open file
  • a reference to an array into which YAML will be pushed
  • a code reference

If you supply a code reference the subroutine will be called once for each line of output with the line as its only argument. Passed lines will have no trailing newline.

AUTHOR

Andy Armstrong, <andy@hexten.net>

SEE ALSO

YAML::Tiny, YAML, YAML::Syck, Config::Tiny, CSS::Tiny, http://use.perl.org/~Alias/journal/29427

COPYRIGHT

Copyright 2007-2011 Andy Armstrong.

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.