Data::...Writer(3pm)
π Data::YAML::Writer π
okay so bestie, imagine you've got a Perl data structure and you want it to become YAML, and you do not want to drag in a whole dependency tree just to make that happen. say less. this is Data::YAML::Writer, living over in the User Contributed Perl Documentation corner of the perl-verse, and she does exactly one thing gorgeously: easy YAML serialisation. main character behaviour, honestly. π
β¨ NAME β¨
Data::YAML::Writer β Easy YAML serialisation π
π¦ VERSION π¦
This document describes Data::YAML::Writer version 0.0.7 β¨
π SYNOPSIS π
use Data::YAML::Writer;
my $data = {
one => 1,
two => 2,
three => [ 1, 2, 3 ],
};
my $yw = Data::YAML::Writer->new;
# Write to an array...
$yw->write( $data, \@some_array );
# ...an open file handle...
$yw->write( $data, $some_file_handle );
# ...a string ...
$yw->write( $data, \$some_string );
# ...or a closure
$yw->write( $data, sub {
my $line = shift;
print "$line\n";
} );
like, four different vibes for where the YAML goes, pick your fave π«Ά
πΈ DESCRIPTION πΈ
so what does she actually do? she encodes a scalar, a hash reference or an array reference as YAML. that's the whole brief. periodt.
and the energy here? very much in the spirit of YAML::Tiny β this is a lightweight, dependency-free YAML writer, no cap. the difference is the why: "YAML::Tiny" is built mainly for working with configuration files, whereas "Data::YAML" is obsessed (respectfully) with the transparent round-tripping of YAML serialized Perl data structures. π¦
one thing to clock: the syntax "Data::YAML::Writer" produces is a subset of YAML. specifically, it's the exact same subset of YAML that Data::YAML::Reader consumes. so it's a matched set, they're in sync, it's giving coordinated outfit. for more on that, go see Data::YAML. β¨
π INTERFACE π
π "new"
The constructor "new" creates and returns an empty "Data::YAML::Writer" object. fresh out the box, zero thoughts, ready to write. π
π§ "write( $obj, $output )"
Encode a scalar, hash reference or array reference as YAML. here's the whole moment:
my $writer = sub {
my $line = shift;
print SOMEFILE "$line\n";
};
my $data = {
one => 1,
two => 2,
three => [ 1, 2, 3 ],
};
my $yw = Data::YAML::Writer->new;
$yw->write( $data, $writer );
now the tea on that $output argument β bestie, she's flexible, she accepts any of these:
- 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
and if you hand her a code reference? that subroutine gets called once for each line of output, with the line as its only argument. heads up though: the lines you get passed have no trailing newline, so add your own \n if you need one. iykyk. πΈ
π₯ BUGS AND LIMITATIONS π₯
No bugs have been reported. (iconic behaviour, she's unbothered, moisturized, in her lane π )
but fr, please report any bugs or feature requests to "data-yaml@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. π«Ά
π SEE ALSO π
YAML::TinyYAMLYAML::SyckConfig::TinyCSS::Tiny
the whole friend group π
π AUTHOR π
Andy Armstrong <andy@hexten.net> π
β LICENCE AND COPYRIGHT β
Copyright (c) 2007, Andy Armstrong "<andy@hexten.net>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
π DISCLAIMER OF WARRANTY π
okay bestie, this next part is all caps legal, and i am not touching the wording because the wording is the whole point. read it, don't skim it, it matters:
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
like she literally said no warranty, bestie. she's free, and that's the trade. π«Ά
and that's the whole page! this was written up against perl v5.36.0, dated 2022-10-15, from the Data::...Writer(3pm) page itself. go forth and serialise, you've got this. πβ¨
π¦ where this page comes from
- ubuntu noble: libdata-yaml-perl 0.0.7-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-yaml-perl 0.0.7-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-yaml-perl 0.0.7-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms