TAP::Parser::YAMLish::Writer - 编写 YAMLish 数据
版本 3.44
use TAP::Parser::YAMLish::Writer;
my $data = {
one => 1,
two => 2,
three => [ 1, 2, 3 ],
};
my $yw = TAP::Parser::YAMLish::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";
} );
将标量、哈希引用或数组引用编码为 YAMLish。
new
my $writer = TAP::Parser::YAMLish::Writer->new;
构造函数 new
创建并返回一个空的 TAP::Parser::YAMLish::Writer
对象。
write
$writer->write($obj, $output );
将标量、哈希引用或数组引用编码为 YAML。
my $writer = sub {
my $line = shift;
print SOMEFILE "$line\n";
};
my $data = {
one => 1,
two => 2,
three => [ 1, 2, 3 ],
};
my $yw = TAP::Parser::YAMLish::Writer->new;
$yw->write( $data, $writer );
$output
参数可以是
追加 YAML 的标量引用
打开文件的句柄
将 YAML 推入其中的数组引用
代码引用
如果您提供代码引用,则子例程将针对每行输出调用一次,并将该行作为其唯一参数。传递的行将没有尾随换行符。
Andy Armstrong,<[email protected]>
YAML::Tiny,YAML,YAML::Syck,Config::Tiny,CSS::Tiny,http://use.perl.org/~Alias/journal/29427
版权所有 2007-2011 Andy Armstrong。
本程序是免费软件;您可以在与 Perl 本身相同的条款下重新分发和/或修改它。
许可证的全文可以在本模块附带的 LICENSE 文件中找到。