Data-YAML
view release on metacpan or search on metacpan
lib/Data/YAML/Writer.pm view on Meta::CPAN
for my $value ( @$obj ) {
$self->_write_obj( $pad . '-', $value, $indent + 1 );
}
}
else {
croak "Don't know how to encode $ref";
}
}
else {
$self->_put( $prefix, ' ', $self->_enc_scalar( $obj ) );
}
}
1;
__END__
=head1 NAME
Data::YAML::Writer - Easy YAML serialisation
=head1 VERSION
This document describes Data::YAML::Writer version 0.0.7
=head1 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";
} );
=head1 DESCRIPTION
Encodes a scalar, hash reference or array reference as YAML.
In the spirit of L<YAML::Tiny> this is a lightweight, dependency-free
YAML writer. While C<YAML::Tiny> is designed principally for working
with configuration files C<Data::YAML> concentrates on the transparent
round-tripping of YAML serialized Perl data structures.
The syntax produced by C<Data::YAML::Writer> is a subset of YAML.
Specifically it is the same subset of YAML that L<Data::YAML::Reader>
consumes. See L<Data::YAML> for more information.
=head1 INTERFACE
=over
=item C<< new >>
The constructor C<new> creates and returns an empty C<Data::YAML::Writer> object.
=item C<< write( $obj, $output ) >>
Encode a scalar, hash reference or array reference as YAML.
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 );
The C< $output > argument may be
=over
=item * a reference to a scalar to append YAML to
=item * the handle of an open file
=item * a reference to an array into which YAML will be pushed
=item * a code reference
=back
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.
=back
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to
C<data-yaml@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.
( run in 0.588 second using v1.01-cache-2.11-cpan-39bf76dae61 )